Function Calling (Tool Use)
A model capability that lets language models request the execution of external functions — like querying a database, calling an API, or running code — rather than just generating text.
Function calling — also called tool use — lets a language model invoke external functions instead of only generating text. You define a set of functions with names, descriptions, and parameter schemas. The model decides when to call one, outputs a structured request, and your application handles execution. The result feeds back into the conversation. The model never runs code directly; it asks your code to do it.
This is the dividing line between a chatbot and a useful system. Without function calling, a model can only talk about doing things. With it, it can query your database, check inventory, create a support ticket, call a payment API, or trigger a deployment. Language models stop being text generators and start functioning as orchestration layers on top of existing infrastructure.
The implementation pattern is consistent across providers: register functions in your API call, receive a structured call with arguments back from the model, execute it in your code, pass the result back. That loop — reason, call, incorporate — is the core mechanic behind AI agents and is formalized in protocols like MCP.
Two things determine whether this works well in production: schema design and validation. Vague function descriptions produce unreliable calls. No parameter validation means the model can pass malformed inputs straight to your production systems. Treat function definitions the way you'd treat an API gateway contract — explicit, typed, and documented. The model will push every edge case you didn't define.
Further reading:
- OpenAI Function Calling Guide — Official documentation on connecting models to external tools.
- Anthropic Tool Use — Claude's tool use documentation.