Module 2 — Calling Tools
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.
# 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.
Check your understanding
A few questions about tools and tool calls. You will get a score.
This activity needs JavaScript.