Lets the model invoke external functions/APIs by outputting structured calls.
Function calling enables the model to interact with the outside world. You define available functions (with names, descriptions, and parameter schemas), and the model can choose to call them. It outputs a structured function call, your code executes it, and you feed the result back.
You send tool definitions (JSON Schema format) with your prompt. The model evaluates relevance and returns a tool_call object instead of plain text. Your application executes the function, sends the result back, and the model incorporates it into its final response. This creates an agent loop.
Building AI agents that take actions (search databases, call APIs, modify files). Creating chatbots that need real-time data (weather, stock prices). Any time the model needs information it was not trained on or needs to trigger side effects.
Not providing clear function descriptions, leading to wrong function calls. Defining too many functions at once. Not validating function call parameters before executing them (security risk). Forgetting to handle the case where the model decides not to call any function.
Supported by OpenAI GPT-4o+, Anthropic Claude 3+, Google Gemini, Mistral Large, and most modern models.