Skip to content
BytePatterns

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.

  1. Append the result to the transcript as an observation
  2. The model emits a tool name and its arguments
  3. Stop when the model answers or the step budget is spent
  4. Your code validates the arguments and runs the tool

Mini quiz

1 / 3

In a tool-use loop, the tool is actually executed by:

New lessons land every few weeks

Leave an address and we will tell you when the next one is up. That is the only reason we will use it.

One address, stored so we can email you. Nothing else, ever.