Function Calling (Tool Usage)
Function calling is the mechanism that lets an LLM actually use tools. The model outputs a structured call — a function name and arguments — and your code runs it, feeding the result back. It's the bridge between the model's language and real code, and the foundation of how agents take action.
💡 In one line: Function calling lets a model request a function by name with arguments; your code executes it and returns the result.
What is Function Calling?
It's the mechanism where an LLM invokes external functions by outputting a structured call (function name + JSON arguments). The crucial split: the model decides and formats the call, but your code executes it.
How It Works (the Round-Trip)
Step by step: define functions → send the query with them → the model returns a call (it does not run it) → you execute → return the result → the model answers.
The Function Schema
Each function is described by a name, a description, and a parameters definition (JSON schema). The model chooses which to call and fills the arguments based mainly on the descriptions — so clear descriptions are the difference between good and bad tool use.
Key Point: Model Decides, Code Executes
The model never runs code. It only outputs which function to call and with what arguments; your application executes it and returns the result. This separation is what keeps function calling controllable and safe.
Parallel Function Calling
Modern models can request multiple calls at once — for example, the weather in three cities — which your code can execute together for speed.
Function Calling vs. Tool Calling
They're essentially the same idea. "Tool calling" is the newer, broader term that covers custom functions plus built-in tools (code execution, web search, etc.).
In Agents
Function calling is how an agent calls a tool at each step — the concrete mechanism behind the Tools pillar and the "Action" in a ReAct loop. Every agent action ultimately flows through it.
Use Cases
- Fetch data — weather, stock prices, database rows.
- Compute — math, conversions.
- Call APIs and take actions — book, send, update.
Best Practices
- Write clear descriptions and use typed parameters.
- Validate arguments and handle errors from the function.
- Keep functions focused, and offer a small, well-described set.
Summary
- Function calling lets a model request a named function with arguments.
- The model decides and formats; your code executes and returns the result.
- The round-trip: define → call → execute → return → answer.
- Clear schemas and descriptions drive good tool selection.
- It's the mechanism behind agent actions — and pairs with APIs and code execution, coming next. EOF echo created