← All AI Agents & Tool Use modules

Module 2 — Calling Tools

The core loop · hands-on · about 25 minutes.

A language model is astonishing at language and surprisingly bad at things that should be easy — like multiplying two numbers. It does not calculate; it predicts the next token, so it produces digits that look right. Ask it for 18.5% of $84.50 and it may confidently hand you a number that is simply wrong. The fix is the second pillar of every agent: give the model a tool it can call, and let it use the tool instead of guessing.

A tool is just a function the agent can call

A tool has a name, a description of what it does, and it takes an input and returns a result. A calculator tool takes "84.50 * 0.185" and returns "15.63". The agent's job is not to do the arithmetic — it is to recognize that this is a calculation, hand it to the calculator, and read the result back. That returned result is fed into the loop as the next observation, exactly like the "too high / too low" feedback from Module 1.

Watch the agent reach for the calculator

Pick a question. On the left is what a model tends to do when it just guesses the answer token by token. On the right, the agent instead calls the calculator tool — you will see the Action it takes, the Observation it gets back, and the final Answer it builds from that observation. Notice the tool's answer is exact; the guess often is not.

This activity needs JavaScript. The lesson below still covers everything.

Try your own calculation

Type any arithmetic and hand it to the calculator tool yourself. This is the same tool the agent calls — it understands + - * / % and parentheses. (It is a safe parser, not a code-runner: it can only do arithmetic.)

This activity needs JavaScript.

Declaring a tool — read only, nothing to install
# the agent is handed a list of tools it may call
calculator = {
    "name": "calculator",
    "description": "Evaluate an arithmetic expression, e.g. '84.5 * 0.185'.",
    "run": lambda expr: str(safe_eval(expr)),
}

# the model decides: call the tool instead of guessing the digits
action = {"tool": "calculator", "arg": "84.5 * 0.185"}
observation = tools[action["tool"]]["run"](action["arg"])  # "15.6325"

This is exactly the shape of OpenAI "function calling" and Claude "tool use": you describe the tools, the model emits a structured call, your code runs it, and the result goes back into the conversation as an observation.

AI anchor — tools are how AI touches the real world Every useful thing a modern assistant does beyond chatting is a tool call. Browsing the web, running Python, checking the weather, searching your files, sending a message — each is a function the model chose to call, with the result fed back so it can keep going. The model supplies the judgment about which tool and what input; the tool supplies the capability and the ground truth. That division — model decides, tool acts — is the heart of agentic AI.

Check your understanding

A few questions about tools and tool calls. You will get a score.

This activity needs JavaScript.

Why this matters next One tool call answered a one-part question. But "how many more people live in Tokyo than Paris?" needs two lookups and then a calculation. Module 3 introduces the ReAct pattern: chaining thought, action, and observation across several steps.
One-sentence summary: a tool is a named function the agent can call with an input and read a result from; instead of guessing answers a language model is unreliable at (like exact arithmetic), the agent calls the right tool and feeds its result back into the loop as an observation.

Next: The ReAct Pattern →