A step budget, repeated-call detection, and no-progress detection genuinely stop runaway loops; bigger context windows and faster models do not.
Imagine a robot vacuum stuck in a corner, bumping the same wall over and over. How do you stop it from doing that forever? You could give it a timer that switches it off after a set number of bumps. You could notice it keeps hitting the exact same spot and force it to turn somewhere new. Or you could check whether the room is actually getting cleaner, and stop it if nothing is changing. Those three tricks each catch a stuck robot. What does not help is buying a robot with a bigger memory, or a faster motor. A bigger memory just lets it remember more bumps. A faster motor just lets it bump the wall quicker. Neither one notices that it is stuck. Agent loops are the same: you need a real stopping rule, not just more room or more speed.
Detailed answer & concept explanation~7 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
Separate the options into safeguards that detect non-termination versus ones that only change cost or capacity, justify the three correct picks, then explain crisply why a bigger context window and a faster model add no exit condition and so cannot stop a loop.
Real products, models, and research that use this idea.
- LangGraph exposes a recursion_limit on its graph runtime that raises an error after a fixed number of node executions, the framework-level version of a step budget.
- Claude Code and Cursor cap agent turns per task and surface a stop prompt, preventing a misfiring edit-test loop from running unbounded.
- OpenAI's Agents SDK enforces a max_turns parameter so a tool-calling loop terminates rather than spinning on a repeated failed call.
- LangSmith and Langfuse traces let engineers spot a stuck agent visually as a run with dozens of identical tool spans and no new observations.
What an interviewer would ask next. Try answering before peeking at the approach.
QExact-match call deduplication misses an agent that varies its arguments slightly each turn. How would you catch that case?
QIf you could keep only one of the three real safeguards, which would you pick and what do you give up?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Picking the bigger context window or the faster model. Both change how much or how fast the loop runs, but neither detects that the agent has stopped making progress, so neither prevents the loop.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.