The Tool Calling Loop, Explained Step by Step
See exactly what happens, message by message, when a model calls a tool and gets the result back
A taste of a lesson
If the model asks for a tool and my code never sends the result back, what happens?
The loop stalls or the model guesses. The model asked a question it cannot answer itself, like 'what is the forecast for Lisbon?', and it is waiting for your code to reply with the result. If nothing comes back, many systems will error. If a result is skipped or lost, the model may continue as if it knew the answer, which is how invented facts slip in. The fix is simple: every tool request gets exactly one result message, even if that result is an error. Try this: write the error message you would send if the city was not found.
Written by the teacher as an example. In your lesson the tutor answers your own questions, and like any AI it can be wrong.
What you will be able to do
- Trace a tool call from request to final answer, naming every message
- Explain why the model requests tools but never runs them
- Describe what a tool definition contains and why descriptions matter
- Identify where loops go wrong and what stops them
Lesson plan
- 1 The cast: user, application, model, tools Name the four parties in a tool calling exchange and what each one does. Start
- 2 Tool definitions: what the model sees Understand how a name, a description and an input schema tell the model what a tool does. Start
- 3 One full cycle, message by message Trace a single tool call from user question to final answer. Start
- 4 Many steps and parallel calls Follow a loop that needs several tools, sometimes requested at once. Start
- 5 Errors, limits and stopping See how good loops recover from failures and end cleanly. Start
Try asking
About this tutor
For curious beginners and new developers who want to understand what is really going on inside an agent. We slow the loop right down: the model receives a request and a list of tools, decides to call one, your code runs it, the result goes back to the model, and the cycle repeats until the model answers. You will trace a full example on paper, learn where errors come from, and understand why the model never runs anything itself. No coding is required, though developers will find the message structure useful when they move on to building.
Reviews
4.5
4 ratingsSample
- Ana P.Sample
Free and genuinely good. I am a designer, not a developer, and I can now follow conversations with our engineers about tool calls.
- Yuki T.Sample
The prediction questions kept me honest. I got the parallel calls one wrong and the explanation stuck because of it.
- Daniel O.Sample
I finally get that the model does not 'go online'. Tracing the umbrella example message by message made everything else click.
- Liam W.Sample
Very clear. I would have liked one extra lesson with a slightly messier example, but as an introduction it is excellent.
About the teacher
I teach how AI agents are built: the loop, the tools, the memory, and when a plain workflow is the better choice
9 tutors 310 lessons taught Sample
I build and teach the inner workings of AI agents. Most of my working life has been spent on backend systems, so I approach agents the way I approach any distributed system: what runs, in what order, what can fail, and what it costs. I like to start every topic with a drawing of the loop on a whiteboard and...
See Hiroshi's profile and tutorsMore like this
Other tutors on the same or nearby topics.