Function calling
How an AI model asks your code to run a tool and then uses the result.
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
- The model outputs a structured request; your code runs the tool.
- Each tool is described by a name, a description and an argument schema.
- Call, run, return, repeat: that loop is the core of an AI agent.
- Ask for confirmation before a model triggers actions that are hard to undo.