Stopping: budgets, limits and done-ness
By the end: Choose stop conditions for an agent and explain what each one protects against.
The loop as written earlier has one natural exit: the model stops asking for tools. That is necessary and nowhere near sufficient. Three more stops belong in every production agent, and each protects against a different failure.
A step limit protects against loops. Models do get stuck, calling the same search with slightly different words, convinced the next phrasing will work. A cap — often somewhere between five and twenty depending on the task — turns an unbounded spend into a bounded one. When you hit it, say so plainly rather than pretending the answer is complete.
A cost or token budget protects against the expensive-but-not-looping case: a genuinely hard task grinding through a large context. Checking spend before each call, rather than after the run, is the difference between a limit and a postmortem.
A wall-clock timeout protects the thing waiting for the agent. A user watching a spinner, a queue with a lease, an HTTP request with its own deadline — all of them have limits shorter than "eventually".
One subtlety about done-ness. The model saying it is finished is a claim, not a verification. Where you can check — the test passes, the record now matches, the file parses — check, and feed the check back as another tool result. An agent that can verify its own work is dramatically more reliable than one that cannot, and that single property does more for quality than any prompt wording.

