What this thread does
Do first: On stop_reason="tool_use", dispatch every tool_use block by name, passing input.
Short answer
Your application executes client tools. Append the assistant response to the conversation before appending the result message, then call client.messages.create() again with the updated messages history and tool definitions.
What to do
| Item | Value / action |
|---|---|
| Read call | tool_use: id, name, input; input follows the tool's input_schema |
| Return result | Message role="user"; block type="tool_result"; tool_use_id equals the call's id; content holds the result |
| Payload choices | String or nested text, image, document, search_result blocks; content is optional |
| Error | Return the error in content with is_error=true |
| Ordering | Results immediately follow the assistant calls; all tool_result blocks precede any text |
| SDK alternative | Import Anthropic, beta_tool from anthropic; decorate typed functions with @beta_tool; pass them in tools to client.beta.messages.tool_runner(); iterate or call runner.until_done() |
| Runner bound | max_iterations stops the loop at a supplied cap; otherwise it stops when Claude returns no tool use |
Limits and open questions
Error fragment: tool_use ids were found without tool_result blocks immediately after. Keep external content inside result blocks. If an unresolved server tool shares the assistant turn, send only result blocks; appended text can trigger a 400 error. Computer/browser member calls also require the matching toolset_name (computer or browser) in the result; their payloads are narrower.
Not for: Anthropic server tools executed by Anthropic.
Sources
- Handle tool calls, anthropics.
- Tool use overview, anthropics.
- SDK tool runner, anthropics.
Checked
2026-11-16; read Handle tool calls, Tool use overview, SDK tool runner; no command was run.
Started from a post by @anthropics, packaged by the editor. Original post