Practice: How tool use turns a model into an agent
Self-check
Section titled “Self-check”Seven short questions. Answer each before opening the collapsible.
1. A language model cannot run code. So what does it mean when an agent “calls” a tool?
Show answer
The model does not run anything. It emits a small piece of structured text, a request, that names a tool and its arguments. The loop (plain code around the model) reads that request, runs the real function, and feeds the result back to the model. The model proposes; the loop disposes.
2. List the four steps of one tool-call exchange, and say who does each.
Show answer
(1) Describe: the loop tells the model which tools exist (the schema). (2) Request: the model emits a tool call instead of an answer. (3) Execute: the loop runs the real tool and returns the result as new input. (4) Decide: the model reads the result and either answers or calls again.
3. In a given step, can the model emit both a tool call and a final answer?
Show answer
No. In one step it does one or the other: it either requests a tool or replies to the user. The final answer comes on a later trip around the loop, after the tool results are back.
4. What actually is a “tool call”? Why is it less magical than it sounds?
Show answer
It is just text in a specific shape the loop has agreed to recognize. The model is still only predicting tokens. The loop scans the output, notices it matches the tool-call shape, and acts on it instead of showing it to the user. Nothing inside the model changed; the scaffolding around it did.
5. A tool fails (times out, bad input). How does the mechanism handle it?
Show answer
A failure is just another result. The loop feeds the error back to the model as the step-3 input, and the model decides what to do: retry with a fix, try a different tool, or tell the user. No new machinery is needed; the error is input like any other.
6. Why is “feed the result back” not an optional step?
Show answer
It is how the model learns what happened. A tool that runs but whose output never returns to the model leaves the model blind, unable to use the result or to notice a failure. The return step is what closes the loop.
7. How can the same model be a plain chatbot one moment and an agent the next?
Show answer
Because agency is in the scaffolding, not the model. Give the model a menu of tools, ask it to format requests a certain way, and wrap it in code that watches for those requests, and it is an agent. Remove that and it is a chatbot. The model is unchanged either way.
Try it yourself: put the exchange in order
Section titled “Try it yourself: put the exchange in order”These four moments are shuffled. Put them in the order they happen, and label each as MODEL or LOOP.
A. runs get_weather("Seattle", "tomorrow") and returns { rain, 58°F }B. emits: call get_weather { city: "Seattle", day: "tomorrow" }C. sends the model the tool menu: get_weather(city, day) "forecast..."D. reads { rain, 58°F } and replies "Tomorrow in Seattle: rain, 58°F."Show answer
Order: C, B, A, D.
- C = LOOP (describe: hand the model the menu)
- B = MODEL (request: emit a tool call, not an answer)
- A = LOOP (execute: run the tool, return the result)
- D = MODEL (decide: read the result, answer)
That is the four-step exchange: describe, request, execute, decide.
Try it yourself: trace a tool call (with a failure)
Section titled “Try it yourself: trace a tool call (with a failure)”The agent has one tool: convert_currency(amount, from, to). Write the trace for this request, and include a recovery when the first attempt uses a bad currency code.
User: “How much is 50 euros in US dollars?” Twist: the model’s first call uses
to: "USA"(not a valid currency code), which the tool rejects.
Show a sample trace
LOOP -> menu: convert_currency(amount, from, to)MODEL -> call: convert_currency { amount: 50, from: "EUR", to: "USA" }LOOP -> ERROR: "unknown currency 'USA'; expected an ISO code like USD"MODEL -> call: convert_currency { amount: 50, from: "EUR", to: "USD" }LOOP -> { result: 54.20 }MODEL -> reply: "50 euros is about 54.20 US dollars."The point: the error came back as a step-3 result, the model read it, corrected the code, and called again. Steps 2 and 3 ran twice; the menu (step 1) and the final answer (step 4) each ran once. If the loop had not fed the error back, the model would have been stuck or guessed.
Flashcards
Section titled “Flashcards”Ten cards. Click any card to reveal the answer. Use the Print flashcards button for one card per page.
Q. What does a model actually do when it 'calls' a tool?
It emits a structured request (tool name + arguments) as text. It never runs the tool; the loop reads the request and runs the real function. The model proposes; the loop disposes.
Q. What are the four steps of one tool-call exchange?
Describe (loop sends the tool menu), request (model emits a tool call), execute (loop runs the tool, returns the result), decide (model reads the result and answers or calls again).
Q. In one step, does the model emit a tool call OR a final answer?
One or the other, never both. The final answer arrives on a later loop iteration, once the tool results are back.
Q. What is a 'tool call', really?
Just text in a shape the loop agreed to recognize. The model is only predicting tokens; the loop spots the shape and acts on it instead of showing it to the user.
Q. How does the four-step exchange handle a tool that fails?
A failure is just another result. The loop feeds the error back as the step-3 input; the model reacts (retry, try another tool, or tell the user).
Q. Why must the tool result be fed back to the model?
It is how the model learns what happened. Without the return step the model is blind to the result and to any failure. The return closes the loop.
Q. What is a tool schema?
The description of a tool the loop gives the model: name, what it does, and the inputs it expects. The ‘menu’ the model orders from.
Q. How can one model be a chatbot or an agent?
Agency is in the scaffolding, not the model. Add a tool menu, a request format, and a watch-and-execute loop and it is an agent; remove them and it is a chatbot. The model is unchanged.
Q. How do the four steps relate to Lesson 1's loop?
Steps 2 to 4 (request, execute, decide) trace Lesson 1’s perceive-decide-act loop entered at the decide point. Tool use is the mechanism that lets the loop act.
Q. What do model-provider 'function calling' / 'tool use' features do?
They formalize emitting and parsing tool calls. Agent frameworks go further and automate the menu-building and the watch-and-execute loop so you do not write that plumbing by hand.