-
Notifications
You must be signed in to change notification settings - Fork 618
agenttool: Run() leaks thinking parts into tool result #697
Copy link
Copy link
Labels
bugSomething isn't workingSomething isn't working
Description
Description
agenttool.Run() collects all Part.Text from the sub-agent's final response without checking Part.Thought. When thinking models (Gemini 2.5/3 with IncludeThoughts: true) are used as sub-agents, their internal reasoning tokens leak into the tool result that the calling agent sees.
Root cause
tool/agenttool/agent_tool.go lines 223-228:
for _, part := range lastContent.Parts {
if part != nil && part.Text != "" {
textParts = append(textParts, part.Text)
}
}No check on part.Thought. Compare with genai.GenerateContentResponse.Text() (types.go:3148-3151) which correctly skips thought parts:
if part.Thought {
continue
}Impact
- Thinking tokens leak into tool results — the root agent sees the sub-agent's internal reasoning mixed into the response text
- OutputSchema validation can fail — when thought text is concatenated before JSON output, unmarshalling breaks
- Token waste — the root agent processes thinking tokens it shouldn't see, inflating context
Related
- fix: interleaved thought&text aggregation in remoteagent #655 — same class of bug, fixed for
remoteagent(merged) - session.Events() and separating thinking & final response #313 — request for separating thinking & final response in session events
- Missing ThoughtSignature on adk_request_confirmation parts breaks execution #656 / Add thought signature propagation to avoid hard crashes #686 —
ThoughtSignaturepropagation issues (related thinking-model support gaps)
Fix
Submitted in #696 — adds && !part.Thought to the text extraction loop, matching genai.Text() behavior.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working