Function calling — the mechanic
**What it does:** You define one or more 'tools' (functions) the model can invoke. Each tool has a name, description, and parameter schema. The model decides whether to call a tool, which tool to call, and what parameters to pass. The actual function execution happens in your code; the model gets the result back in the next turn.
**Mechanism:** Model receives the tool definitions in the system prompt context. When the model wants to invoke a tool, it returns a structured tool-call object instead of plain text. Your code parses the tool call, executes the function, and feeds the result back to the model as a tool-result message.
**Best for:** Tasks where the model needs to interact with external systems (API calls, database queries, calculations) AND the model should decide whether/when to interact. The decision-making is part of the value.
**Documentation:** Anthropic tool use, OpenAI function calling.