01.04 · Concept
Stopping, and the loop that will not
Bound a loop so it terminates on success, on budget and on repetition.
Agent loops need explicit exit conditions because the model will not reliably decide to stop by itself. A robust loop checks for a defined successful result, enforces resource limits, and detects repeated states or unproductive actions before continuing. Without those controls, useful autonomy becomes an unbounded retry loop.
What this lesson answers
- how do I stop an agent loop
- why do AI agents get stuck repeating
- what exit conditions should agents have
Notes
An agent is software wrapped around a model that repeatedly chooses what to do next: think, call a tool, inspect the result, and continue. That loop is useful because one model call often is not enough to solve a task. It is also dangerous because nothing about “agent” automatically means “will stop.” Termination has to be designed as deliberately as the tool calls themselves.
A good mental model is a production retry loop with exit conditions. The loop should stop when it reaches success, when it spends its budget, or when it detects repetition.
Common questions
- Why can an AI agent run forever?
- An agent keeps asking a model what to do next, then runs tools and feeds the results back into the next decision. If the surrounding program does not define success, limits, or repetition detection, each step can look locally reasonable while the overall loop never reaches a terminal state.
- What should make an agent stop?
- An agent should stop when it has met a concrete success condition, when it has exhausted its allowed budget, or when it is repeating itself without new progress. Good terminal states are explicit, such as success, budget exceeded, human input needed, or stuck on repetition.
- Is a better model enough to prevent infinite loops?
- No. A stronger model may choose better next actions, but stopping is a property of the control code around it. The program still needs to track progress, enforce limits, compare states, and decide when another iteration is no longer safe or useful.
Short definition: what is Stopping, and the loop that will not?