Lv.1 0 XP

Agentic Loop Control Flow — Handling Multiple Tools

Core 9 min +35 XP
💡
THE ANALOGY

An air traffic controller managing multiple planes simultaneously. Each plane (tool call) needs clearance, executes its flight path, reports back, and the controller coordinates the next move — never letting planes figure out their own sequence.

⚠️ EXAM TRAP — The Wrong Answer People Choose

Only handling the first tool_use block in a response. Claude can request multiple tools in a single response — you must handle ALL of them before looping.

KEY POINTS
1 A single Claude response can contain multiple tool_use blocks — you must execute ALL of them before appending results and continuing.
2 Each tool_use block has a unique tool_use_id — your tool_result must reference the correct id or the conversation history becomes invalid.
3 Tool results are appended as a single user turn containing multiple tool_result content blocks — not as separate API calls.
4 The order of tool_result blocks does not need to match the order of tool_use blocks, but every tool_use_id must have a corresponding tool_result.
5 If a tool fails, you still must return a tool_result for that tool_use_id — mark it as an error, don't skip it.