AI & ML — INTRODUCTION
Tool Calling (Function Calling): How It Actually Works
Every model can produce text describing what it would do. Tool calling is what lets it produce something an application can actually run — the difference between describing an action and requesting one.
The Quick Answer
Tool calling — also called function calling — is a mechanism that lets a model generate a structured request instead of plain text: a specific function name, plus the arguments to call it with, in a fixed format like JSON. The model itself never runs this function. The application reads the request, executes the real function, and can send the result back so the model can use it. This is the exact mechanism behind AI agents taking real actions instead of only describing them.
Same Request, Two Very Different Outputs
Compare what a model produces for the same request, with and without tool calling:
The plain-text version reads perfectly reasonably — that’s exactly what makes it risky to build software around. There’s no reliable way for application code to tell “this really happened” from “this is just how the sentence came out.” The structured version removes that ambiguity entirely: either the exact function and arguments are there, or they aren’t.
Why This Matters More Than It Sounds
Before tool calling existed as a first-class feature, getting a model to reliably trigger real actions meant asking it to produce specially formatted text and then writing fragile parsing code to try to extract an action from it — code that broke whenever the model phrased something slightly differently. Tool calling moves that structure into the model’s own output format directly, so the application doesn’t have to guess at what a sentence “really means.”
Fun Fact
Tool calling and structured output solve a similar-sounding problem — getting a predictable format out of a model — but for different reasons: structured output shapes the model’s final answer, while tool calling requests an action the application still has to actually perform.
Test Yourself
What is the core difference between a plain text response and a tool call?
In the booking example on this page, why is plain text (“Sure, I’ll book a table”) risky for an application to rely on?
Who actually executes the function when a model makes a tool call?
Ready to see how a model chooses between several available tools, and what happens when it needs to call more than one at once? Continue to the Intermediate level →