← Build an AI Agent Lesson 2 of 8

Tools

Tell it what it can use

I'd love to use a calculator. But how would I know there is one?

Turn the tool list off and on. Then let the LLM write.

The program puts a tool list at the top of the text, every time, before your question. The LLM reads it, so it knows which tools exist and how to ask for them.
the LLM can only use tools on the list
No list → a guess: 1,264,871. With the list → ACT: calculator(4817 * 263).

The list has several tools. How does the LLM pick one?

Which tool?

You are the LLM. Pick the tool for each question.

That's what the LLM does too: it matches the question to each tool's description, then writes the ACT: line.
“What's 9 × 6?” → calculator “works out math exactly” → ACT: calculator(9 * 6)

Try it on new numbers.

✏️ Practice 2.1

New numbers, same ideas.
Remember: the tool list goes at the top of the text, every time.
The LLM matches the question to each tool's description.
One ACT: line asks for one tool, once.

Work each one out. Type the answer, press Check.
A tool list has 4 tools, each described in 20 words. The agent gets 10 questions. How many words of tool list does the LLM read in total?
Tools: calculator, search, weather, add_reminder. “Will it rain in Goa tomorrow, and what's 15% of ₹600?” How many different tools does the LLM need?
“Is it raining in Pune, Goa and Delhi?” The agent has a weather tool, one city at a time. How many ACT: lines does it write?

Those descriptions were clear. What if they aren't?

Good descriptions

Same question, two tool lists. Switch between them.

The LLM can only go by the words in the list. A good description says three things:
name + what it does + what to give it
weather + “the weather right now in a city” + “the city name”.

Even a good tool can fail. Then what?

When a tool fails

Step through. Something goes wrong in round 1.

The program doesn't stop when a tool fails. It writes the error on the LOOK: line, like any result. The LLM reads it, fixes its mistake and tries again.
errors go back on a LOOK: line too
The retry costs a round: 2 rounds here, so 2 + 1 = 3 LLM writes.

Try it on new numbers.

✏️ Practice 2.2

New numbers, same ideas.
Remember: a failed tool use still takes a round. The error comes back on a LOOK: line.
times the LLM writes = rounds + 1
The step limit is the most rounds the program allows. It stops there, even without an answer.

Work each one out. Type the answer, press Check.
A task needs a search, then the calculator. The first search fails, the second works. How many rounds?
Same task. How many times does the LLM write?
A task needs 2 tools. Each fails once, then works. How many rounds does it need? (The step limit is 3: think about whether it finishes.)

So far the tools only looked things up. Some do more.

Tools that change things

Sort each tool. Then press Check.

A tool that only looks changes nothing, so trying again is safe. A tool that changes something, like sending an email, can't always be undone. An agent needs more care with those: coming in Lesson 7.

Quick check: did it all make sense?

Lesson 2 test

5 questions, one for each idea in this lesson. Answer them all right to pass. A wrong answer tells you why, and which page to look at again.

1. PredictAn agent has a weather tool, but it's missing from the tool list. You ask: “Is it raining in Goa?” What happens?
2. ApplyTools: calculator, search, weather, add_reminder. Which one for “What's 12% of 3,500?”
3. Spot the mistakeA tool list says: tool_x: helps. What's wrong with it?
4. PredictThe weather tool answers “Error: no city called Kochii”. What does the program do?
5. ThinkWhich tool needs the most care?

You've seen every piece now.

Your turn to build

An LLM, a tool list, a program running the loop. You've watched an agent work, step by step.

I know what I can do now. Will you build me for real?

This leaves a question
You've watched an agent work. Can you build one yourself?
Lesson 3 answers it.