Big Picture 6: Tool Execution and the Agent Loop
The model only writes tool_use. Someone else runs the tool, and the cycle repeats until stop_reason is end_turn. That cycle is the agent loop.
- 1.Model writes tool_use (stop_reason: tool_use)
- 2.Permission / hook check
- 3.Tool runs (in parallel if needed)
- 4.tool_result is added to the messages
- 5.Request rebuilt (Big Picture 2), model thinks again (Big Picture 4)
- 6.Repeat until end_turn
Where a tool can run
- Your code (client): custom functions (DB, APIs), Bash and text editor, Computer use (screenshot then click) and the Memory tool (/memories).
- Anthropic servers: web search, web fetch, the code execution sandbox, tool search and advisor. Anthropic runs these itself.
- MCP servers: Tools (the model runs them), Resources (data) and Prompts (templates). Talk over stdio or HTTP, with OAuth over HTTP.
- Claude Code / Agent SDK: a permission check and hooks run before every tool, Skills (SKILL.md, scripts), Subagents (separate context), and Read / Edit / Grep / Bash.
The loop itself
- tool_use, check, run: when tool_use arrives, the permission and hook checks run first, then the tool runs (several in parallel if needed), and the outcome comes back as a tool_result.
- Back into the loop: the tool_result is added to the messages, the request is rebuilt at Big Picture 2, and the model thinks again at Big Picture 4, until end_turn.
- Who runs the loop: a manual loop you write yourself, the SDK Tool Runner, Claude Code / the Agent SDK, or Managed Agents (hosted by Anthropic).