Module 5 · AI that takes action: agents · Lesson 22 of 32
Tools: giving AI a phone and a calculator
10 minFree GenAI course · BeginnerLesson 5.1By Saket Bhatnagar
Researched and drafted with AI, reviewed and edited by Saket Bhatnagar.
In short
- A model alone can only write text. It cannot check today’s weather, do exact sums or send a message.
- With tool calling, the model writes a small, structured request, your app runs the real tool, and the result goes back to the model.
- The model only asks. Your app decides what actually runs, which is where safety lives.
Video lesson · coming soon
AI tool calling explained in 3 minutes
Lala, your AI mentor, will walk you through this lesson in a short animated video. Until then, everything is here to read and try.
- 01 Will it rain in Pune tomorrow?
- 02 Words are not weather
- 03 Dadi writes a chit
- 04 Model asks, app runs, model answers
- 05 Step through one tool call
- 06 The model asks. The app decides.
- 07 Try it, then meet agents
Kabir has a cricket match in Pune tomorrow morning. He asks a chat app, “Will it rain in Pune tomorrow?” A plain language model has a problem here. It learned from text that stopped at a cut-off date, so tomorrow’s weather was never in it.
Yet many chat apps answer this question well. They say “light rain likely after 4 pm” with real numbers. The model did not become a weather station. It picked up a phone and asked one. This lesson is about that phone.
Why does a smart model need tools?
Remember the one trick from module 2: a language model predicts the next token, again and again. That is wonderful for writing and explaining. But predicting words is not the same as knowing fresh facts, counting exactly or doing things in the world.
- Fresh facts: today’s weather, a train’s live status, a stock of shoes in a shop. These change every hour and were never in the training data.
- Exact work: 18% GST on ₹7,349, or the number of days until Diwali. A model can guess a number that looks right. A calculator gets it right.
- Actions: sending an email, booking a cab, adding a meeting to your calendar. Text alone cannot press any button.
How tool calling works, one step at a time
Before any question arrives, the app gives the model a short menu of tools. Each tool has a name, a one-line description and the details it needs, such as a city and a date. This menu sits in the prompt, so it costs tokens like everything else.
When Kabir’s question comes in, the model reads the menu and decides a tool would help. So its reply is not a sentence for Kabir. It is a small, fixed-shape request, much like the JSON you met in the structured output lesson. Then the app takes over.
Who talks to whom in a tool call
Drag to exploreThe model never touches the weather service. It asks the app, the app calls the tool, and the app hands the result back to the model for the final answer.
Diagram connections:
- Kabir to Your app (question)
- Your app to Language model (question + tools)
- Language model to Your app (tool request)
- Your app to Weather service (runs it)
- Weather service to Your app (result)
- Kabir: Asks a question in plain words.
- Your app: Holds the tool menu and runs every tool call.
- Language model: Decides whether a tool is needed and writes the request.
- Weather service: Ordinary software that returns real data.
// The tool description the app sends (part of the menu)
{
"name": "get_weather",
"description": "Get the weather forecast for a city on a given date.",
"parameters": {
"type": "object",
"properties": {
"city": { "type": "string", "description": "City name, e.g. Pune" },
"date": { "type": "string", "description": "today, tomorrow, or YYYY-MM-DD" }
},
"required": ["city"]
}
}
// The model's reply: a request, not an answer
{ "tool": "get_weather", "arguments": { "city": "Pune", "date": "tomorrow" } }How does the model know how to write these requests? During fine-tuning, which you met in the training lesson, models practise thousands of examples of “here is a tool menu, here is a good request”. So spotting when a tool helps is a learned habit, not magic.
The model asks, the app decides
This is the most important idea in the lesson. The model only writes text that looks like a request. Your app chooses whether to run it. That gap is where you put every safety rule.
A weather lookup is harmless. Sending ₹5,000 through a payments tool is not. So good apps sort tools by risk, and they ask the person before anything that changes the world.
| Kind of tool | Examples | What can go wrong | Sensible rule |
|---|---|---|---|
| Look up | Weather, train status, search your documents | Wrong or stale data | Run freely, show where the data came from |
| Calculate | Calculator, unit converter, run a small piece of code | Bad input gives a wrong number | Run freely, check the inputs |
| Act | Send an email, book a cab, pay a bill, delete a file | Real money, real messages, hard to undo | Show the details and ask the person first |
What makes a good tool for a model?
The model chooses tools only from their names and descriptions. So writing a tool is a bit like writing a prompt: a clear brief gets good behaviour, a vague one gets confusion.
A clear name
get_train_status says what it does. tool_2 or helper does not.
A description that says when to use it
“Use this for live running status of Indian Railways trains, by train number.” The “when” stops the model from calling it for a hotel booking.
Few, well-typed details
Ask for a train number as a 5-digit text, not a long free-form paragraph. Small, exact inputs mean fewer mistakes.
Helpful errors
If the train number is wrong, return “No train 12345 found. Check the number.” The model can read that and fix its next try.
A short menu
Five sharp tools beat fifty overlapping ones. Every description costs tokens, and look-alike tools make the model pick the wrong one.
Modern models can also ask for several tools at once. Ask “Weather in Pune and Delhi?” and the model may request two weather lookups together, so the app can run them side by side and answer faster.
Check yourself
Check yourself
Kabir asks about tomorrow’s rain, and the model returns a get_weather request. Who actually contacts the weather service?
Pick an answer to see why it is right or wrong.
Check yourself
You give an AI assistant a send_payment tool. What is the safest design?
Pick an answer to see why it is right or wrong.
Check yourself
Your assistant keeps calling search_hotels when people ask about trains. What is the most likely fix?
Pick an answer to see why it is right or wrong.
Remember these three
- A model alone only writes text; tools give it fresh facts, exact answers and the power to act.
- In tool calling, the model writes a structured request, the app runs the tool, and the result returns to the model.
- The model only asks and the app decides, so put approvals and limits in the app, especially for actions.
Questions people ask
- What is function calling in an LLM?
- Function calling, also called tool calling, lets a language model reply with a structured request to run a named function, such as get_weather with a city. Your app runs the function and sends the result back, and the model uses it in its answer.
- Does the AI model run the tool itself?
- No. The model only writes the request as text. Your app reads it, decides whether it is allowed, runs the tool and passes back the result. This is why safety checks belong in the app.
- Is tool calling the same as an AI agent?
- Not quite. Tool calling is one building block: one request, one result. An agent repeats this in a loop, choosing the next tool after each result, until a bigger goal is done. The next lesson covers agents.
- Do tools make AI answers always correct?
- They help a lot for fresh facts and exact sums, but they are not a guarantee. A tool can return stale data, and the model can still misread a result. Show sources and test with real questions.