PRODUCTION SCENARIO
An autonomous refactoring agent runs shell commands and edits files in a loop. On a repository with circular test failures it re-runs the same two commands for hours without converging.
Which control stops the runaway loop?
Answering here is anonymous. Nothing is saved unless you sign in.
Show answer and explanation
Answer: Cap the loop at 40 iterations plus a token budget, and halt on a repeated tool call
Stopping conditions such as a maximum number of iterations are what hold an agent loop, and a token budget plus a check for a repeated tool signature catches this circular case specifically. A per-request max_tokens bounds one response, not the number of responses, and more container memory lets the loop run longer. A prompt rule asks the model that cannot tell it is looping to notice that it is. tool_choice auto is already the default and leaves termination to that same judgement.
Official Source: https://www.anthropic.com/engineering/building-effective-agents ↗