How does a safe agent loop work, step by step?
Answer out loud or in your head first, then compare.
Answer
The application sends the model the task and a description of the allowed tools. The model returns an answer or a request to use a tool. The application checks that request, performs the allowed operation and sends the result back. Then the model can decide what to do next.
This repetition must have limits: the number of steps, time and budget. An unknown tool or invalid arguments must not run arbitrary code. Results have to be attached to the right calls. For writes, add access control, protection against repeats and sometimes human approval. A final “done” doesn't prove success — I check what was actually saved or changed.
Why it matters: After the definition of an agent, the logical step towards implementation.
Possible follow-ups: What about several tools in one response? When do you stop the loop?
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
Practise in code
- A minimal agent loop — runs tests in your browser
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.