Tool Use and Agentic Workflows
What to know
Tool use turns Claude into an actor: you declare tools with a name, description, and JSON-schema input; the model may respond with a tool_use block containing a tool name and arguments; your code executes it and returns a tool_result block in a subsequent user turn; the loop repeats until the model returns a final text answer. This is a client-executed loop - the model never runs code itself.
Understand tool descriptions as prompts: precise names, clear purpose, and input schemas with required fields and enums dramatically improve reliability. Know how to handle errors: return an error message in the tool result so the model can adapt, rather than silently failing. Understand tool_choice to force or forbid tool use, and parallel tool calls where multiple independent calls arrive together.
Traps
- Forgetting to send the
tool_resultback, leaving the loop hanging. - Mismatched
tool_use_idbetween the call and its result. - Assuming the model validates arguments against your schema; your code must validate and sanitize.
- Overly terse tool descriptions causing wrong tool selection.
- Letting an agent loop run unbounded without a max-iterations guard.
- Trusting tool output as instructions (injection via tool results).
Rule of thumb
The agent loop is: model proposes → your code authorizes and executes → you return results → model continues. Every step must be bounded, validated, and logged.