Chapter 14 — Tool Calling & Function Execution
TL;DR: Tool calling allows the LLM to decide which tool to call, when, and with which arguments — turning the agent into an action orchestrator, not just a text generator.
Tool calling loop
Section titled “Tool calling loop”graph TD
A[Agent receives question] --> B[LLM decides: need tool?]
B --> C{Yes?}
C -->|Yes| D[LLM chooses tool + args]
C -->|No| E[Answer directly]
D --> F[Execute tool]
F --> G[Return result to LLM]
G --> H[LLM interprets, decides next step]
H --> I[Loop or final answer]
Código do diagrama
graph TD
A[Agent receives question] --> B[LLM decides: need tool?]
B --> C{Yes?}
C -->|Yes| D[LLM chooses tool + args]
C -->|No| E[Answer directly]
D --> F[Execute tool]
F --> G[Return result to LLM]
G --> H[LLM interprets, decides next step]
H --> I[Loop or final answer]
Typed tools
Section titled “Typed tools”const tools = [ { name: "get_order", description: "Fetch an order by ID", inputSchema: { type: "object", properties: { order_id: { type: "string" } }, required: ["order_id"] }, handler: async (args) => { return await db.orders.findOne({id: args.order_id}); } }];