Pattern · beginner
Tool Use Pattern
How agents call tools reliably: schemas, selection, error handling, permissions, and verification of side effects.
Tool use (function calling) lets models invoke external capabilities with structured arguments and observe results.
Design good tools
- Small and sharp — one clear job
- Strict schemas — types, enums, required fields
- Actionable errors — “order_id not found” beats “error”
- Idempotent writes when possible
- Document side effects in the description
Selection quality
Overlapping tools confuse models. Prefer:
- Distinct names
- Non-overlapping responsibilities
- Examples in descriptions (short)
Execution loop
model proposes tool call → validate schema → policy check → execute →
return observation → model continues
Never skip validation/policy because the model “sounded sure.”
Verification
For side-effecting tools, verify postconditions in code before reporting success to users.
MCP and portability
Standard interfaces like MCP help expose tools across hosts, but security remains your job.
FAQ
Frequently asked questions
What is tool use in AI agents?
Tool use is the ability for a model to invoke external functions—APIs, databases, browsers, code runners—to observe or change the world beyond text generation.