The agent that never stops
Without a hard stop, an agent handed an ambiguous or impossible task keeps calling tools and burning tokens long after a person would have given up, because nothing in the loop tells it to quit.
A support agent loops forty times re-reading the same ticket, then times out with a $9 bill and no answer.
where_are_you
The maturity ladder, worst to best
These are the rungs the Agent Reliability Scorecard scores for this dimension, straight from the tool. Find where your agent sits, then aim for the top rung.
Nothing explicit: we trust the model to decide when it's done
A generous max-iteration cap as a last-resort backstop
A tuned iteration cap that fails closed when it's hit
An iteration cap plus loop detection for repeated/identical tool callstarget
why_it_matters
An agent loop is a while-loop with a language model deciding the exit condition. That works right up until the model can't tell it's stuck: the task is underspecified, a tool keeps returning the same unhelpful result, or two steps contradict each other. Left to its own judgment the model will keep trying, because from inside the loop each turn looks like progress. The cost is real tokens and real latency for output nobody can use.
The fix is a ceiling the model doesn't control. A max-iteration cap that fails closed is the floor. Better is that cap plus loop detection: if the last few tool calls are identical, or the same error repeats, break out early rather than waiting to hit the cap. The point is that termination is your decision encoded in code, not a behavior you hope the model exhibits.
more_failure_modes
Related ways agents break
The confident wrong answer
Read itCost & rate controlThe runaway invoice
Read itSee all 7 failure modes, or score your loop with the scorecard.
faq
Questions & answers
- Why does my AI agent get stuck in a loop?
- Because nothing outside the model forces it to stop. When a task is ambiguous or a tool keeps returning the same result, the model reads each retry as progress and keeps going. Add a max-iteration cap that fails closed and loop detection for repeated identical tool calls, so the loop ends on your terms rather than the model's judgment.
- What is a good max-iteration cap for an agent?
- Low enough that a stuck run stops before it costs real money, high enough that legitimate multi-step tasks finish. Start from the longest real task you've seen, add a small margin, and treat the cap as a backstop rather than the primary control. Pair it with loop detection so most runs never approach it.
Fixing one failure mode is a day. Hardening the whole loop is the work.
I review where your agent loop terminates, how it escalates, how it fences tool output, idempotency on the side effects, and the evals that catch a regression before users do. Book a call, or leave your email.
Prefer proof first? See how this plays out in real case studies →