-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Agent loops indefinitely when tool call output exceeds max_tokens #7527
Copy link
Copy link
Labels
p1Priority 1 - High (supports roadmap)Priority 1 - High (supports roadmap)
Description
When a tool call's JSON output exceeds max_tokens, the response is truncated mid-JSON and fails to parse ("EOF while parsing an object"). The agent retries the same call indefinitely because:
no_tools_calledis set tofalseeven when the tool call failed to parse (agent.rs ~L1476), so the exit/retry logic is never reached- The system hint (
"Try breaking the task into smaller steps") is injected but the model ignores it and attempts the same large write DEFAULT_MAX_TURNSis 1000, so the loop can burn tokens for a very long time before stopping
Observed in a session where the model tried to write a full HTML dashboard via developer__text_editor. Every attempt hit 8,192 output tokens, failed to parse, and retried — 24 consecutive failures with zero user intervention possible.
Contributing factors:
- Default
max_output_tokens()is 4,096 — too low for models supporting 16K-32K+ output - Tool-pair summarization (Tool-pair summarization is too aggressive for large context models #7415) fires during the loop, replacing error context with stale summaries, making recovery even less likely
Fix options (not mutually exclusive):
- Break after N consecutive tool parse failures (e.g., 3) instead of setting
no_tools_called = false - Raise default
max_output_tokensper model capability - Detect repeated identical truncation and suggest a different strategy
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
p1Priority 1 - High (supports roadmap)Priority 1 - High (supports roadmap)