How AI Can Use Tools and Call Functions
See exactly how a model “uses” a tool: by writing a request that the app runs on its behalf.
Here’s a surprise: a language model can’t actually do anything. It can’t open a website, read a database or send an email. All it can ever do is write text. So how do agents use tools?
The trick is called tool calling (or function calling), and it’s a polite round trip:
- The app describes its tools in the request: each one’s name, what it does, and what information it needs, written as a schema like the ones from Track 5’s structured outputs.
- The model replies with a tool call instead of an answer: “please run
get_weatherwith city = Lisbon”, as structured data. - The app runs the real function, then sends the result back to the model.
- The model writes the final answer using that result, or asks for another tool.
The model decides whether a tool is needed. Ask it for a haiku and it simply writes one. Ask about tomorrow’s weather and it knows it can’t, so it asks for the weather tool.
This split is what makes tools safe enough to use. The model only ever produces a request; your code decides whether to run it, checks the arguments, applies permissions, and can ask a human first. A tool is any function you choose to expose: a search, a calculator, a database query, a booking system. Give a model good tools and it can reach far beyond what it learned in training.
Key takeaways
- Models can only write text; “using a tool” means writing a structured request for one.
- The app describes the tools, runs the requested function, and sends the result back.
- The model decides whether a tool is needed and which one.
- Because the app runs the tools, it controls permissions, checks and approvals.
Check your understanding
Go deeper (more technical)
Tool definitions are usually written in JSON Schema. Models are fine-tuned on many examples of deciding when to call a tool and filling in its arguments, and many APIs support parallel tool calls: several independent requests in one turn, such as checking three calendars at once.
Tool calls and their results take up context like everything else, so very large results are often trimmed or summarised before being handed back (more on that in “Managing an agent’s context”).