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

  1. You send the conversation plus a list of tools: each with a name, a description and a JSON Schema for its arguments.
  2. The model either answers in text or returns a tool call: the tool's name and arguments as JSON.
  3. Your code runs the function with those arguments.
  4. You send the result back to the model.
  5. 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

OpenAIAnthropic (Claude)Google (Gemini)
Tools are passed astools (type function)tools with input_schematools → function_declarations
The model asks for a call witha tool call (name + JSON arguments)a tool_use content blocka functionCall part
You return the result asa tool message with the call's ida tool_result block with the tool_use_ida functionResponse part
Parallel callsSupportedSupportedSupported

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

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.

Related