An agent loop has no natural end. The model reads the context and outputs either a final answer or another tool call, and nothing stops it from choosing the tool call again and again. Stop conditions are the rules, written in the harness, that end the run.
The happy ending is a final answer: the model outputs text the harness recognises as “done”. The others are there for when that does not happen.
- A step limit. The run ends after a set number of turns, whatever state it is in.
- A token budget. Every turn re-reads the whole growing context, so cost climbs faster than the step count. A budget caps the total.
- A full context. When the context will not fit in the model’s window, the harness has to stop or cut something out.
- An error or a refusal. A tool fails in a way that cannot be retried, or a person says no.
Anthropic’s guide to building agents notes that it is common to include stopping conditions, such as a maximum number of iterations, to keep control of a run.
A stop condition limits cost and damage; it does not make an agent safe or correct. A loop that stops after a set number of steps can still have done the wrong thing in each of them. That is why stop conditions sit beside permissions and approvals, not in place of them.
The explainer lets you change the step limit and the context window and watch where the run ends.