Skip to main content
Section 2

Giving a model tools

How tool use (function calling) lets a model act beyond text.

4 lessons25-question quiz
2.1

What tools are and why they matter

6 min read

AI Foundations covered a plain model's limits: it answers from patterns learned during training, frozen at a knowledge cutoff, with no live lookup unless something else steps in. That "something else" is a tool.

A tool is a function the model can call. Not a metaphor: an actual piece of code you write and connect to the model, like a web search function, a calculator, or a function that reads a file. The model does not run this code itself. It asks for the tool to run, and your program does the running.

What changes when a model has tools

  • It can pull in information past its knowledge cutoff, like today's date or a live price.
  • It can get an exact answer instead of an estimated one, like a calculation.
  • It can read or write real data, like a file on your machine or a row in a database.
  • It can trigger a real action outside the conversation, like sending an email or creating a ticket.
Plain modelModel with tools
KnowledgeFrozen at training cutoffCan fetch live information
MathEstimates from patternsCan call a calculator for exact answers
Your filesCannot see themCan read or write them, if given a tool
OutputText onlyText, plus real actions in the world
Plain model vs. model with tools
Key idea
A tool is a function the model can call when text alone is not enough. It is what turns a model from something that only talks into something that can also act.
This builds directly on Building with AI in AI Foundations, which introduced tools as what gives a model "hands and eyes." This section goes one level deeper: how a tool actually gets defined and called.
Key terms
Tool
A function the model can call to do something text generation alone cannot.
More

Search, a calculator, and file or database access are common examples. The model requests the tool; your code runs it.

Function calling
Another name for tool use: the model requesting that a specific function run, with specific inputs.
2.2

Defining a tool the model can call

7 min read

The model does not automatically know which functions exist in your program. You describe each tool to it: a name, a plain description of what it does, and the inputs it needs. The model reads that description and decides, on its own, when calling the tool would help.

The three parts of a tool definition

  • Name: a short, machine-friendly identifier, like get_weather.
  • Description: a plain sentence explaining what the tool does and when to use it.
  • Input schema: the exact inputs the tool needs, with their names and types.
A tool definition (schema-style)
{
  "name": "get_weather",
  "description": "Get the current weather for a city. Use this when the user asks about today's weather or current conditions.",
  "input_schema": {
    "type": "object",
    "properties": {
      "city": { "type": "string", "description": "City name, e.g. 'Austin' or 'Tokyo'" },
      "unit": { "type": "string", "enum": ["celsius", "fahrenheit"] }
    },
    "required": ["city"]
  }
}

The description is what the model reads

The model never sees your function's actual code. All it has is the name, the description, and the schema. A vague description, like "weather tool", leaves the model unable to tell when to use it or what to pass in. A specific one, like the example above, gets called at the right moment with the right input.

  • Say what the tool does, and say when to use it, not just its name.
  • Name every input and say what format it expects.
  • Keep the description in plain language, the same way you would explain the tool to a new teammate.
Key idea
You do not write "if the user asks about weather, call this function." You write a clear description, and the model decides when to call the tool based on that description alone.
Providers format this schema slightly differently, but the three parts, name, description, and inputs, show up everywhere tool use is supported.
Key terms
Tool definition
The name, description, and input schema you give the model so it knows a tool exists and how to use it.
Input schema
The structured list of inputs a tool expects, with each input's name and type.
2.3

The tool-use loop

6 min read

Defining a tool is only half the picture. Once the model can see a tool, using it follows a loop, with your code sitting in the middle, not the model acting alone.

  1. 1Model asksInstead of answering directly, it responds with a tool call: this tool, with these inputs.
  2. 2Your code runs the toolThe model never executes anything itself. Your program receives the request and runs the real function.
  3. 3Result returnedYou send the tool's output back to the model as part of the conversation.
  4. 4Model continuesIt reads the result and either answers, or asks for another tool call.
The tool-use loop

A worked example

  1. You ask: "What is 4,821 times 37?"
  2. Instead of guessing, the model responds with a tool call: { "a": 4821, "b": 37, "op": "multiply" }.
  3. Your code runs the real multiplication and returns 178377.
  4. The model reads 178377 and replies with the answer, exact instead of estimated.

The loop can repeat. A model can call one tool, look at the result, then call a second tool before it ever writes a reply to you. Each round trip, model asks, code runs, result returns, is one turn of the loop.

Key idea
The model never runs code itself. It asks; your program runs the tool and hands the result back; the model reads that result and continues. That handoff is the entire mechanism behind tool use.
Because your code is the one actually running the tool, it is also the one deciding what the tool is allowed to touch, covered next.
Key terms
Tool call
The model's request to run a specific tool with specific inputs, instead of a plain text reply.
2.4

Common tools and when to add one

6 min read

Most tool use in practice comes down to a short list of categories. You do not need to invent something exotic. You need to recognize which gap in the model's plain-text ability you are trying to close.

ToolWhat it lets the model do
Web searchReach past the knowledge cutoff for current information, prices, or news
Code execution / calculatorGet an exact result instead of an estimate, for math or logic
File accessRead or write files on disk, instead of only working with pasted text
Database accessLook up or update real records instead of guessing at them
Common tools and what they add

When to add a tool

  • Add a tool when the model would otherwise have to guess at something you can look up or compute exactly.
  • Add a tool when the task needs information from after the knowledge cutoff.
  • Add a tool when the task needs to touch something outside the conversation: a file, a database, an external service.
  • Do not add a tool just because you can. Every tool is another thing the model might call wrong, and another thing you have to secure.

The safety angle

A plain model can only produce text; the worst it can do is say something wrong. A model with tools can touch real things: delete a file, send a message, spend money, change a database row. That is the entire point, and it is also the risk. Give a tool only the access it needs, read-only where possible, and put a human or a permission check in front of anything that cannot be undone.

Key idea
Reach for a tool when text alone cannot get an exact, current, or real-world answer. The more a tool can actually do, the more carefully you should gate when it runs.
Many coding agents already do this: they ask before running anything risky and let you review the change first. That review step exists because the agent can act, not just talk.
Key terms
Read-only access
Letting a tool see data without being able to change or delete it, the safer default when a tool does not need to write.

Section 2 quiz

25 questions. Pass at 75% to master this section. Retakes are unlimited, and the quiz is where the learning sticks.

Section 2 quiz · Giving a model toolsQuestion 1 of 25

What is a tool, in the sense used in this section?