tool use and function calling
/ TOOL yooss and FUNK-shun KAWL-ing /
A language model on its own can only produce text. It cannot actually check today's weather, do reliable arithmetic on big numbers, or look up a fact it never memorized. Tool use is the trick that lets it reach outside itself: instead of trying to answer from memory, the model writes out a request — "call get_weather with city = Tokyo" — and a surrounding program runs that real function and hands the answer back. Think of giving a brilliant but housebound expert a telephone and a set of instruments: now they can ask the world instead of guessing.
Function calling is the specific, structured way this is wired up. The developer describes each available tool — its name, what it does, and what inputs it needs — and the model, when it decides a tool would help, emits a tidy structured request (typically JSON) naming the function and filling in the arguments. Crucially, the model does not run anything itself; it only proposes the call in a fixed format. The application validates and executes it, then feeds the result back into the conversation so the model can use it. This is the plumbing underneath nearly every modern AI agent.
The big win is honesty about what a model can't do: arithmetic goes to a calculator, current events go to a search tool, private data goes to your database. But the model is still the one deciding when and how to call a tool, and it can decide badly — invent arguments, pick the wrong tool, or skip a needed call. So the surrounding code must treat every model-proposed call as untrusted input: validate it, restrict what tools can do, and never let a single misjudged JSON blob, say, wipe a database.
You ask "What's 4,891 × 2,733?" The model, instead of guessing, emits: {"tool": "calculator", "args": {"expression": "4891*2733"}}. The app runs the real calculator, gets 13,367,103, and feeds it back. The model then replies in plain English: "That's 13,367,103." The answer is exact because a real calculator — not the model's fuzzy memory — did the math.
The model proposes a structured call; the app runs the real tool and returns the result.
A common misconception: the model "runs" the tool. It doesn't — it only writes the request. Everything between the request and the result is ordinary software you control, which is exactly where you must put the safety checks. A model can be tricked (by a poisoned web page, say) into requesting a dangerous call, so the tool layer, not the model, is the real security boundary.