Resources / AI agents
Function calling explained: how OpenAI, Claude and Gemini call your tools
How LLM function calling (tool use) works across OpenAI, Anthropic Claude and Google Gemini — the request/response loop, schemas, and how to host the functions.
Function calling (also called tool use) lets a language model ask your application to run a function — look up weather, query a database, create a ticket — and then use the result in its answer. The model never runs code itself; it returns a structured request, and your code runs it.
The loop
- You send the conversation plus a list of tools: each with a name, a description and a JSON Schema for its arguments.
- The model either answers in text or returns a tool call: the tool's name and arguments as JSON.
- Your code runs the function with those arguments.
- You send the result back to the model.
- The model continues — another tool call, or the final answer.
Defining a tool
The shape is nearly identical across providers — a name, a description, and a JSON Schema:
{
"name": "get_weather",
"description": "Current weather for a city. Use when the user asks about weather.",
"parameters": {
"type": "object",
"properties": { "city": { "type": "string", "description": "City name, e.g. Berlin" } },
"required": ["city"]
}
}
Provider differences
| OpenAI | Anthropic (Claude) | Google (Gemini) | |
|---|---|---|---|
| Tools are passed as | tools (type function) | tools with input_schema | tools → function_declarations |
| The model asks for a call with | a tool call (name + JSON arguments) | a tool_use content block | a functionCall part |
| You return the result as | a tool message with the call's id | a tool_result block with the tool_use_id | a functionResponse part |
| Parallel calls | Supported | Supported | Supported |
The details change between API versions, so check each provider's current docs — but the loop and the JSON Schema are the same everywhere. That's also why the Model Context Protocol exists: define tools once and let any MCP client use them.
Tips that matter more than the provider
- Descriptions are prompts. Say when to use the tool and what the fields mean.
- Validate arguments. Models occasionally send wrong types or invented values — check against the schema before running anything.
- Return small, structured results. Every token of the result goes back into the context.
- Return errors the model can act on: "date must be YYYY-MM-DD" beats a stack trace.
- Guard side effects. Confirm before payments, deletes or messages to customers.
Where the functions run
In a prototype, tools are functions in the same script as the model call. In production they're usually APIs: the model call happens in one place, the tool runs behind an authenticated endpoint with logging and rate limits — and the same endpoint can serve several agents.
On Wisp
Describe a tool and Wisp writes and hosts it as an endpoint with an input schema — ready for function calling from your own agent (call its URL) or as an MCP tool for Claude, ChatGPT and Cursor, with API keys, per-client limits and a log of every call.
Build it with Wisp — describe an API, get it live.