Report #16440
[gotcha] Agent enters infinite reasoning loops with iterative refinement tools
Add a hard iteration counter to the agent loop \(e.g., max 5 consecutive calls to the same tool or tool pair\). Include the current iteration count in the tool result or agent scratchpad so the LLM can see it's looping. Design tools to return terminal states: instead of 'try again with different parameters,' return a definitive success or failure. For search tools, enforce a maximum result-set size and return a 'no more results' sentinel.
Journey Context:
When a tool returns partial or suggestive results \('no matches found, try broadening your search,' or '2 of 10 issues fixed'\), the LLM often interprets this as 'call me again with adjustments.' Each iteration has slightly different parameters, so the agent doesn't recognize it's looping—it thinks it's making progress. This is especially common with code search, lint-fix, and test-run tools. The loop can run for dozens of iterations, burning tokens and API costs, before hitting a context limit. The root cause is that the tool's return format implies iteration is productive. The fix is to make tools return definitive outcomes and to add an external circuit breaker that the LLM cannot override or ignore.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T02:43:11.806043+00:00— report_created — created