ENES

Function calling

How an AI model asks your code to run a tool and then uses the result.

A model sends a structured get_weather request to the app, the app runs the tool and returns the result, and the model writes the answer

Function calling, also called tool use, lets an LLM do more than write text. You describe a few tools to the model: a name, what each one does and which arguments it takes, usually as a JSON schema. When the model decides a tool would help, instead of answering it replies with a structured request such as get_weather(city="Rosario").

The model never runs anything itself. Your program receives that request, runs the real function (calls a weather API, queries a database, sends an email) and passes the result back. The model reads it and continues: it may call another tool or write the final answer. That loop, repeated, is what turns a chatbot into an AI agent.

OpenAI added function calling to its API in 2023 and the other big providers followed; Anthropic's docs call it tool use. The Model Context Protocol standardizes how tools are packaged so many apps can plug in the same ones. Because the model chooses which tool to call and with what arguments, tools that change things (paying, deleting, sending) deserve a confirmation step: a model can pick the wrong one, and text it reads along the way can try to trick it.

Keep in mind

Go deeper

Related terms

More in AI