Lesson 3 of 7
Function / tool calling
7 min read
A model is frozen in the past and can't touch your systems. So how does an AI assistant book a meeting, refund an order, or read today's weather?
The model asks; your code acts
On its own the model only produces text. Tool calling (a.k.a. function calling) changes that: you describe some functions your app exposes — name, purpose, and a schema for the arguments — and when the model needs one, it doesn't run it. It emits a structured request: call `book_meeting` with these arguments. Your code runs it and hands the result back.
Tool calling is a loop: the model requests a function, your code runs it, the result goes back in, and the model answers with real, live information.
This is how an agent is born
Give a model a few tools and a goal and it becomes an agent: it plans, calls a tool, reads the result, and decides the next step. The same schema idea from structured outputs powers the arguments — which is exactly what a protocol like MCP standardises, so one tool works across many apps. You stay in control: your code decides what each tool is allowed to do.
Tools turn a text generator into something that acts. The model chooses; your code executes and sets the limits.
The model can pick the wrong tool or invent arguments. Validate every tool call against its schema before you run it, and never wire a destructive action to fire without a check.
The shape of it
- —Tools let the model act — call functions, read live data, touch your systems.
- —The model emits a structured call; your code runs it and returns the result.
- —Tools + a goal + a loop = an agent.
- —You set the limits: validate arguments, gate anything destructive.
A model with tools decides to call `delete_account` with an argument you didn't expect. What's the right safeguard?
Continue in the app
Take the whole Building AI Apps with the API course — tracked
Get your personalized path, progress and streaks in the app — this lesson and every next one, in order.