Tool & Function Calling
2 minute read
This is the primitive that turns a text generator into something that can act. Agents, skills, plugins, and MCP are all built on it.
The idea
You give the model a list of tools (functions) it’s allowed to call. When answering would need one, the model doesn’t run it — it returns a structured request to call it, with arguments. Your code runs the function and hands the result back. The model then continues with that result in hand.
The loop
- You send the prompt plus tool definitions.
- The model replies either with an answer, or with a tool call (name + arguments).
- Your code executes the tool and returns the result.
- The model uses the result to answer — or calls another tool. Repeat until done.
sequenceDiagram
participant App as Your app
participant Model
participant Tool
App->>Model: prompt + tool definitions
Model-->>App: tool call (name + args)
App->>Tool: execute
Tool-->>App: result
App->>Model: tool result
Model-->>App: final answerThis request → call → result → continue cycle is exactly what an agent automates.
Defining a tool
A tool is declared with a name, a description (the model uses this to decide when to call it), and an input schema (typed parameters). Clear names and descriptions matter more than anything — they’re how the model picks the right tool.
Key points
- The model never executes anything — it only requests calls; your side runs them and is the security boundary.
- Parallel calls — a model may request several tools at once; return all results together.
- Validate inputs and gate risky actions (see Guardrails); the model’s requested arguments are untrusted.
- Structured output is the sibling idea: constrain the answer to a schema, the same way tool arguments are constrained.
Skills, plugins, and MCP are all ways to supply tools (and context) to a model — the calling mechanism underneath is this.
Strengths & limitations
- Strengths — lets the model act, not just talk; typed, validated inputs; the primitive underneath agents, skills, and MCP.
- Limitations — the model can pick the wrong tool or hallucinate arguments; you own execution and its security; each call is a round-trip, adding latency and cost.