GPTCrunch
Back to AI Glossary
Fundamentals

Function Calling

A capability that allows AI models to generate structured outputs that invoke predefined functions or APIs, enabling models to take actions like searching databases, calling web services, or executing code.

Function calling (also known as tool use) enables language models to interact with external systems by generating structured requests to predefined functions. Instead of just producing text responses, the model can decide when it needs to use a tool — like searching a database, checking the weather, performing a calculation, or calling an API — and output a structured JSON object specifying the function name and its arguments.

The function calling flow works in several steps. First, the developer defines available functions with their names, descriptions, and parameter schemas (typically in JSON Schema format). These definitions are included in the API request alongside the user's prompt. Second, the model evaluates whether any function would help answer the user's question. If so, it generates a function call with the appropriate arguments instead of (or alongside) a text response. Third, the application executes the function and returns the result to the model. Finally, the model incorporates the result into its text response.

Function calling is the foundation of AI agents — systems where language models can autonomously complete multi-step tasks by chaining together tool calls. A travel planning agent might search for flights, check hotel availability, look up weather forecasts, and convert currencies, all through function calls. Coding assistants use function calling to read files, run code, search documentation, and execute terminal commands. The model decides when and how to use each tool based on the conversation context.

Most major AI providers support function calling: OpenAI, Anthropic, Google, Mistral, and others all offer this capability through their APIs. Some models are specifically trained to be reliable tool users, producing well-formed function calls with correct argument types. Key considerations when implementing function calling include validation of model-generated arguments (the model might produce invalid inputs), error handling for failed function calls, and security (ensuring the model cannot call functions it should not have access to). Parallel function calling, where the model requests multiple tools simultaneously, can significantly speed up complex workflows.

Explore more AI concepts in the glossary

Browse Full Glossary