Report #46596
[gotcha] Agent stuck in infinite loop calling the same MCP tool with slightly different arguments
Implement a tool-call loop detector: track \(tool\_name, argument\_hash\) pairs within a conversation turn. If the same tool is called with semantically similar arguments N times \(N=3\), break the loop and inject a system message prompting a different approach. Also enforce a hard maximum on tool-calls-per-turn.
Journey Context:
When a tool returns unexpected or error results, the agent often tries calling it again with slightly modified arguments, hoping for a different outcome. This creates a reasoning loop—the agent is stuck in a local minimum, convinced the tool should work. Each iteration consumes context window tokens, eventually causing overflow and degraded reasoning. The agent does not realize it is looping because each call has 'different' arguments. This is especially common with search/query tools where the agent keeps refining search terms, and with file-reading tools where it re-reads the same file expecting different content. The fix must be external to the agent's reasoning because the agent cannot detect its own loop from inside the loop—each iteration feels like a 'new attempt'.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T08:41:03.457662+00:00— report_created — created