Function Calling

2 min read

Function calling is a capability of modern large language models (LLMs) that allows them to interact with external tools, APIs, and systems by generating structured function invocations as part of their output. Rather than simply producing text responses, an LLM with function calling can determine when a user's request requires external data or actions, select the appropriate function from a predefined set, generate the correct parameters, and incorporate the function's result into its response. This capability turns LLMs from passive text generators into active agents that can take real-world actions.

Function calling works through a structured protocol. Developers define a set of available functions with descriptions and parameter schemas (typically in JSON Schema format). When the model receives a user query, it analyzes whether any available function would help answer the request. If so, it returns a structured function call with the appropriate arguments instead of (or alongside) a text response. The application executes the function, returns the result to the model, and the model incorporates the result into its final response to the user.

Common use cases for function calling include:

  • Data retrieval: Querying databases, searching knowledge bases, or fetching real-time information from APIs.
  • Workflow automation: Creating calendar events, sending emails, updating CRM records, or triggering CI/CD pipelines.
  • Multi-step reasoning: Breaking complex tasks into sequential function calls, for example looking up a customer, checking their order status, and initiating a refund.
  • Code execution: Running calculations, generating charts, or executing scripts in sandboxed environments.

Function calling is a core building block for AI agents and copilot-style applications. Platforms like OpenAI, Anthropic, and Google have made function calling a standard feature of their APIs. It's what allows AI applications to go beyond conversation and actually interact with existing systems, workflows, and data sources in a structured, reliable way.