Giving models tools

How a model can ask your code to look things up or take actions, and why your code stays in charge.

A model on its own can only write text. It can't check today's weather, look up an order, or do exact math with certainty. Tools change that. Tool use, sometimes called function calling, lets a model ask your code to do something and then use the result.

How it works

Tool use is a short back-and-forth between your code and the model:

  1. You describe the tools. Along with your messages, you send a short description of each tool: its name, what it does, and what details it needs. For example, a tool called get_weather that needs a city name.
  2. The model asks to use one. If a tool would help answer the user, the model replies with a request instead of a normal answer. It is like a note saying "please run get_weather with city = Leeds."
  3. Your code runs it. Your program reads that note, calls a real weather service, and gets the answer.
  4. You send back the result. You add the result to the message list and call the model again. Now it can write a proper reply: "It's 12 degrees and raining in Leeds."

Here is roughly what the model's request might look like. As before, this is a generic sketch, not any provider's exact format.

{"tool": "get_weather", "input": {"city": "Leeds"}}

The model never runs your tools

This is the part people most often get wrong. The model does not reach out and run your tools. It can only ask. Your code reads the request and decides what happens next. (Some providers also offer built-in tools, like web search, that run on their side. This lesson is about tools you write yourself.)

That gives you real control. Your code can check that the details make sense, refuse requests it doesn't like, or ask a person to approve before going ahead. If you never wrote a tool to delete files, the model has no way to delete files.

Think hard about what tools can do

Tools fall roughly into two kinds:

  • Tools that look things up, like checking the weather or searching a help page. These rarely cause harm.
  • Tools that take action, like sending an email, making a payment, or changing a record. These can cause real trouble if used at the wrong time.

Models make mistakes, and they can be fooled by tricky text. So give each tool only the power it needs. A tool that reads a calendar shouldn't also be able to delete events. For anything that acts in the world, have your code show the planned action to a person and wait for a "yes."

Try it

Imagine a chatbot for a small café. List three tools it might use. Next to each, write whether it only looks things up or takes an action, and whether you'd want a person to approve it first.

Check your understanding

4 questions. Get 4 right to master this skill. Quiz results count toward your skill progress; they are not a credential.

  1. 1. When a model "uses" a tool you wrote, who actually runs it?
  2. 2. What does the model need from you before it can ask for a tool?
  3. 3. Which tool deserves the most caution?
  4. 4. Why is it useful to give a model a calculator tool?

0 of 4 answered.

What this opens up

Back to the AI Foundations tree