Agents

Function Calling

Function calling is a language model API feature, first formalized by OpenAI in June 2023, that enables a model to output structured JSON specifying which predefined function to invoke and with what arguments, enabling reliable programmatic integration with external code and APIs.

Function calling is a feature of language model APIs that allows developers to define a set of functions—described by name, description, and parameter schema—that the model can choose to invoke during a conversation. Instead of generating free-form text, the model outputs a structured JSON object specifying the function name and argument values. The calling application executes the function and passes the return value back to the model, which then incorporates it into its response.

The mechanism works by embedding function schemas into the model's system context or a dedicated API parameter. During generation, the model decides whether a user request is best served by calling a function or by generating text directly. If it chooses to call a function, generation stops and the structured call is returned to the application. This determinism—structured output rather than parsed natural language—makes function calling substantially more reliable for integration than prompting a model to suggest a call in free text.

Function calling is foundational to agentic applications because it provides a precise, low-ambiguity interface between language models and the rest of a software system. It enables models to interact with databases, trigger business logic, query APIs, and control application state without requiring developers to parse free-form output. It also reduces hallucination risk on parameter values by constraining the output format and allowing downstream validation before execution.

OpenAI introduced function calling in the GPT-3.5 and GPT-4 APIs in June 2023. Anthropic released an equivalent feature—called tool use—for Claude models shortly after, and Google followed with Gemini. By 2026, the concept is universal across major providers and standardized enough that frameworks such as LangChain and LlamaIndex treat function calling as a first-class abstraction. The capability is central to building reliable agents, copilots, and automated pipelines in production.

Example

A customer support bot uses function calling to retrieve a user's order status: the model outputs a structured call to get_order_status with the order identifier as an argument, the application queries the database and returns the result, and the model generates a natural language response explaining the delivery timeline.

Related terms

← Glossary