API glossary

Function calling

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Function calling is a capability that lets a large language model (LLM) request the use of an external tool, API, or piece of code by producing a structured, machine-readable call instead of a plain-text reply. The model does not run the code itself; it decides which function to invoke and with what arguments, while the application then executes that function, and the result is handed back to the model to incorporate into its final answer. Function calling is often used interchangeably with “tool use” or tool calling, though strictly speaking it refers to developer-defined functions, a subset of the broader tool-calling pattern.

In short: function calling lets a model say “call this function with these inputs,” so it can fetch live data or take actions instead of relying only on what it already knows.

How function calling works

The application and the model exchange messages in a loop, with the application always in control of what actually runs:

  1. Tool definitions: The application gives the model a list of available functions, each with a name, a description, and a JSON schema describing its inputs.
  2. Decision: Given the user’s request and those descriptions, the model decides whether a function would help and, if so, which one.
  3. Structured call: Instead of answering in prose, the model returns a structured call naming the function and the argument values, formatted to match the schema.
  4. Execution: The application, not the model, runs the function (such as querying a database, calling an API, or performing a calculation) and captures the result.
  5. Return: The result is sent back to the model as a new message.
  6. Final response: The model uses that result to produce its answer, or it calls another function and the loop repeats.

Different providers use different names for the same idea: OpenAI popularized function calling (noting that “a function is a specific kind of tool”), while Anthropic refers to it as tool use. The defining point is that the model never executes anything on its own; it only proposes the call, and the application decides what to run.

Function calling vs. text generation, RAG, agents, and skills

  • Plain text generation produces prose for a person to read; function calling produces a structured request the application can execute, letting the model act rather than just describe. For example, a structured call like get_weather(location=“London”) can help generate a plain-text response like “The weather today in London is overcast”.
  • Retrieval-augmented generation (RAG) adds relevant content to the model’s context before it answers; function calling lets the model trigger data fetches or actions on demand, and the two often combine when “search” is itself one of the available functions.
  • An agent strings many tool calls together in a loop to complete a multi-step task; function calling is the building block that external actions in those loops rely on. Internal planning and reasoning steps might not emit a tool call at all.
  • Structured output uses the same schema-based format as function calling but without triggering any external action; it is a way of constraining the model’s response shape rather than extending what the model can do.
  • An agent skill packages reusable instructions, scripts, and resources that an agent can load on demand for a specialized task; function calling is the lower-level mechanism it builds on, since a skill mainly describes how to combine multiple tool calls rather than being a single call itself.

Where function calling is used

  • Live data and actions: Fetching current information such as weather, prices, or inventory, or taking actions such as booking, sending, or updating records that the model cannot do on its own.
  • Retrieval and search: Exposing a search or database lookup as a function so the model can pull in facts partway through an answer—including calls to a web search API.
  • Agents and agentic search: Multi-step agentic workflows rely on function calls to execute external actions such as searching, fetching, and updating records.
  • Standardized tool access: Open standards such as the Model Context Protocol (MCP) build on function calling so that one tool definition can work across many models and applications without custom integration for each.
  • Reusable capability packages (aka “Skills”): Emerging standards such as Agent Skills bundle instructions, scripts, and resources into portable folders that an agent loads on demand. A skill may include scripts that the hosting runtime exposes and executes via tools—the model proposes the call, and the runtime runs the code.

Function calling is what turns a language model from a text generator into a system that can reach outside itself: it is the foundation for agents, live retrieval, and AI that is capable of taking action on a user’s behalf.

Tool use, agentic search, retrieval-augmented generation (RAG), Model Context Protocol (MCP), Agent Skills, JSON schema, structured output, large language model (LLM), API, AI agent.