Function Calling Fundamentals
Function calling (also called tool use) is the mechanism that lets a language model invoke code in your application. Every modern agent uses it. Every major model provider has its own flavour and they are all more similar than different.
The Same Idea, Slightly Different APIs
Anthropic (Claude): The response includes tool_use blocks with the tool name, input JSON and a unique tool_use_id. You run the tool, then send back a tool_result referencing that ID.
OpenAI (GPT): The response includes tool_calls. You run each one and reply with a role: tool message containing the result and a tool_call_id.
Google (Gemini): Function calls are returned as functionCall parts. You reply with functionResponse parts.
The concept is identical: model sees available tools, model decides which to call, your code runs the tool, model sees the result. The API shape is different enough that portable code needs a small adapter layer, similar enough that once you know one you can pick up the others in an hour.
What Function Calling Is Not
Function calling is not code execution by the model. Claude does not run your Python. Your code runs your Python. The model produces a structured request; your infrastructure executes it and returns the result. The model never touches your database, file system or credentials directly.
This distinction matters for security. When you give Claude a delete_customer tool, you are trusting Claude to decide when to call it, not trusting Claude to have delete permissions on your database. Your tool implementation is the actual thing with the permissions.
Anatomy of a Function Call Round Trip
- Your app sends a message + a list of tool definitions to the model
- Model returns a response with one or more tool call requests
- Your app runs each tool with the arguments the model provided
- Your app sends the results back to the model
- Model returns either a final text response, or more tool calls, or both
Steps 2 through 5 can repeat. That is the agent loop.
Providing Tool Definitions
The tool definition uses JSON Schema for its inputs. Claude reads:
- The tool name
- The tool description
- The input schema, including per-parameter descriptions and required fields
None of this is optional. A tool with a bad description or a loose schema will be called wrong.
Give the model only the tools it needs. More tools means more tokens per request, more distraction and more chances to pick the wrong one. Ten tools is a reasonable ceiling for a single agent. Fifty is too many; you need a router.
Parallel Function Calls
Modern models can decide to call multiple tools at once. Claude might return three tool_use blocks in one response. Your code should run all three (in parallel if they are safe to parallelise) and return all three results in one message.
This is significantly faster than running tools serially and is worth handling in your loop from the start.
When Function Calling is the Wrong Choice
If the "tool" is really just a text transformation, do not use function calling. Ask the model to do it in plain text. Function calling has overhead. Reserve it for actual side effects (querying data, sending messages, changing state) or actual retrieval (looking things up in databases the model does not know).
Function Calling vs Structured Output
There is a related but distinct feature called structured output or JSON mode. This is not function calling. Structured output forces the model's response to conform to a JSON schema. It is useful when you need the model to return data in a specific shape (say, an extracted list of entities). Function calling is for invoking side effects. Use each for what it is designed for.
Key Takeaway
Function calling is a structured way for the model to ask your code to do something. Anthropic, OpenAI and Google all implement it slightly differently but the concept is identical. Your code runs the actual code; the model only ever produces requests. Give the model only the tools it needs, describe them well, run them in parallel when safe.