AI Agents & Tool Calling
The shift from a model that only answers questions to one that can act on them.
6.5.1Definition
Tool calling lets a model invoke external functions — a web search, a database query, a calculator, an API call — as part of producing a response, rather than answering purely from its own knowledge. An AI agent is a system built around this capability: a model that plans, calls tools, observes results, and iterates toward completing a multi-step task.
6.5.2Why It Exists
Language models have no inherent access to live data, cannot perform precise calculations reliably, and cannot take actions in the world on their own. Tool calling exists to extend a model's capability beyond generating text — giving it a defined, structured way to fetch real information or trigger real effects, with the model deciding when and how to use each available tool.
6.5.3Anatomy of a Tool-Calling Loop
- Tool definition — each available tool is described to the model with a name, purpose, and expected parameters (a schema, per REST conventions in 5.4).
- Model decision — given a task, the model decides whether a tool is needed and which one, then produces a structured call.
- Execution & observation — the application executes the actual tool call and returns the result to the model as new context.
- Iteration — the model may call additional tools based on what it observed, repeating until the task is complete or a limit is reached.
6.5.4Common Mistakes
- Vague or ambiguous tool descriptions, causing the model to call the wrong tool or misuse the right one's parameters.
- No limit on iteration count, allowing an agent stuck in a reasoning loop to call tools indefinitely, burning cost with no progress.
- Granting tools with real-world side effects (sending emails, spending money) with no confirmation step, risking an unintended or premature action.
- Trusting tool output uncritically, when a tool call can fail or return unexpected data the model should be prompted to handle gracefully.
6.5.5Best Practices
- Write precise, unambiguous tool descriptions with clear parameter schemas — this is prompt engineering (6.1) applied to tools.
- Cap iteration count and cost per task, with a clear failure/timeout path.
- Require explicit confirmation before any tool call with an irreversible real-world effect.