The Tool-Use Loop
AI & ML: lesson 21 of 32
The model proposes a call; your code decides whether it runs.
Lesson 21 of 32 · 5 min
The Tool-Use Loop
Step 1 of 9
An agent is a loop, not a model. The goal goes in once; the loop is what does the work.
The Idea
An agent is a loop, not a model. The model reads the goal and emits a tool name with arguments. Your code validates them, runs the tool, and appends the result as an observation. Round it goes until the model answers or the budget runs out.
Real-World Example
A duty officer on a radio. They can request a tow truck, a road closure or an ambulance, but every request goes through a dispatcher who checks it is permitted, sends it, and reads the outcome back.
The Tradeoff
Tools turn a guessing machine into one that can check. They also widen the blast radius: every call is code running with your credentials. Validate arguments against a schema, keep destructive tools behind explicit confirmation, cap the number of steps, and log every call — the transcript is your only debugger.
Your turn
Put the steps in the right order.
- Append the result to the transcript as an observation
- The model emits a tool name and its arguments
- Stop when the model answers or the step budget is spent
- Your code validates the arguments and runs the tool
Mini quiz
1 / 3