How do you stop an agent that's looping or too expensive?
Answer out loud or in your head first, then compare.
Answer
The application enforces limits: the maximum number of steps, tool calls, time and budget. Writing “don't work too long” in the instructions isn't enough. You can also detect repeated actions without progress and end the task with an explanation.
If an agent fetches the same document several times and still can't settle the matter, another attempt may only add cost. I record the result so far, the reason for stopping and a safe next step. Repeating a read isn't always an error — the data may have changed — so I tailor such a rule to the task. The model shouldn't be able to raise its own limits at will.
Why it matters: The loop needs termination control on failed cases too.
Possible follow-ups: Is a step limit enough to cap the cost of all the tools?
How did it go? Be honest — “Not yet” puts the question on your review list.
Start with
- H-P01 · How does an AI agent differ from a plain model call? — Agents and workflows
- H-P02 · What is a workflow, i.e. a fixed sequence of work? — Agents and workflows
Further reading
- Claude Platform: Tool use overview(opens in a new tab)Docs; accessed 22.10.2026. Client and server tools, the call, and a result matched by call ID.