agenttool: child state updates do not reach the parent session
Describe the Bug
An agent called through agenttool can read the parent's state, but its state updates do not reach the parent. I reproduced this with both OutputKey and a callback calling ctx.State().Set(...).
Steps to Reproduce
- Give the child agent an
OutputKeyofchild_result. - Call it through
agenttooland let it return"done". - Read
child_resultfrom the parent tool context.
Expected Behavior
The child's state delta reaches the parent, as in Python's AgentTool.
Observed Behavior
The tool returns {"result": "done"}, but child_result is missing from the parent's state and event StateDelta.
The Go event loop reads child events without forwarding their state deltas. Is this isolation intentional in Go, or should these updates be forwarded?
Environment Details
- ADK:
mainat0a1ae8b - OS: macOS, arm64
- Go: 1.26.6
Model Information
testutil.MockModel; no live model or credentials needed.
Minimal Reproduction Code
Append this test to tool/agenttool/agent_tool_test.go. It uses the existing imports and createToolContext helper.
func TestAgentToolPropagatesOutputKey(t *testing.T) {
child, err := llmagent.New(llmagent.Config{
Name: "child",
OutputKey: "child_result",
Model: &testutil.MockModel{Responses: []*genai.Content{
genai.NewContentFromText("done", "model"),
}},
})
if err != nil {
t.Fatal(err)
}
ctx := createToolContext(t, child)
wrapped := agenttool.New(child, nil).(toolinternal.FunctionTool)
result, err := wrapped.Run(ctx, map[string]any{"request": "run"})
if err != nil {
t.Fatal(err)
}
if result["result"] != "done" {
t.Fatal("child did not return its result")
}
value, err := ctx.State().Get("child_result")
if err != nil || value != "done" {
t.Fatal("child completed, but child_result is missing from parent state")
}
}Run:
go test -race ./tool/agenttool -run '^TestAgentToolPropagatesOutputKey$' -count=1The test fails with child completed, but child_result is missing from parent state.
Source: google/adk-go