Flashcard: why must every agent loop declare when to stop?
A stopping condition is the rule that exits the agent loop: final-answer from the model, budget exhaustion (steps, tokens, cost, time), or unrecoverable error. The runtime enforces it; the model cannot police itself.
Imagine handing a very eager intern an unlimited stack of work and saying 'just keep going.' Without a clear rule for when to stop, they will work forever, or until they fall over. Agents have the same problem. The LLM can always think of one more tool to call, one more lookup to try, one more refinement. Stopping conditions are the rules the runtime uses to say 'okay, that is enough.' Sometimes the rule is positive (the model produced a finished answer). Sometimes the rule is a budget (we have used twenty steps already). Sometimes the rule is an emergency brake (the same tool keeps failing). Without these rules, the loop can spin until the cost bill arrives. With the wrong rules, the agent gives up too early and hands back a half-done answer.
Detailed answer & concept explanation~6 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.
5 min: define stopping condition, list the three canonical kinds (final answer, budget, error), explain why the model cannot enforce its own budget, describe stuck-state detection as an extra layer, and note how partial answers should be surfaced.
Real products, models, and research that use this idea.
- LangGraph exposes a recursion_limit on graph execution; hitting it raises a GraphRecursionError that the caller has to handle, which makes runaway loops visible rather than silent.
- The OpenAI Agents SDK lets you cap max_turns and timeouts on a run; both fire as explicit run-completion conditions you can inspect.
- Anthropic computer-use deployments cap dollar spend per session because individual screen-driven runs can burn tokens fast at full resolution screenshots.
- Cursor and Cline coding agents implement repeated identical action detection to break out when the model keeps proposing the same failing edit.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow do you decide a step budget for a new agent without overfitting to the demo task?
QWhat is stuck-state detection and why is it different from a step budget?
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.
Relying on the model to know when to stop. The model has no view of the budget or the wall clock; the runtime is the only component that can enforce a stopping condition.
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.