Learn · narrated lesson · about 4 minutes
When does it stop?
An AI agent works on its own, step after step. Watch one fix a bug, and find out what really ends the loop.
Transcript
This invoice should say nine hundred rupees.
It says eight hundred and ten: the billing software applies the discount twice.
Two of its sixteen automatic checks fail.
You ask an AI agent to fix it, and it works on its own, step after step.
So when does it stop?
Take a guess, and tap how sure you are. We'll come back to it.
That agent is really two parts.
In the glass room sits Claude. It reads what it's given, and writes back.
It has no hands: it can't open a file, or run anything.
Everything passes through this slot, like the tray under a bank counter's glass.
Outside sits the harness, the program around Claude. Here, that's Claude Code.
It has the hands, and the tools.
So: Claude asks. The harness does.
Your request goes into a ledger: the conversation so far.
Each round, the harness slides the whole ledger through the slot.
Claude keeps no memory between rounds.
So every time, it reads the ledger from the top.
Claude wants to read the checks, but can't. So it writes a request.
Amber means asking.
Its name is tool use: which tool, on what, and a ticket number.
The whole reply comes out with one stamp, the stop reason: why Claude stopped writing.
This one says tool use. Meaning: I need something done.
The harness reads the stamp, and opens the file. Not Claude.
It writes back what it found. Teal means coming back.
Its name is tool result, with the same ticket number.
It's filed as a user message, even though the harness wrote it.
Then the whole ledger goes back in.
That's one lap: ask, stamp, do, report.
Lap two. Claude writes: Found it. The discount is applied twice. I'll fix line twelve.
It has words. It sounds finished.
Your call: stop, or loop?
The stamp says tool use.
Claude wrote words and asked for a tool, in the same reply.
A harness that stops on words would quit right here, with the invoice still wrong.
So that rule, stop when you see words, gets wiped.
Words never decide. The stamp does.
Tool use: go round again. End turn: finished.
Edit line twelve.
Run the checks.
Sixteen of sixteen pass.
Claude writes: Fixed it. The discount was applied twice, and all sixteen checks pass.
End turn.
Claude is finished, and asks for nothing more.
So the harness stops, and hands you the answer.
One more control on the desk: a turn limit, a cap on how many laps.
It's a circuit breaker for a loop that runs away.
If it trips, the run is cut off before Claude says it's done.
A backstop. Never the finish line.
So, back to your guess: when does it stop?
Not when Claude writes words.
Not when a limit trips: that only cuts it off.
It stops when the stamp, the stop reason, says end turn.
Claude asks. The harness does. The stamp decides.
Now, three quick cards from memory. Then you play the harness.
Check yourself
- Who runs the tools? The harness (here, Claude Code). Claude only asks, with a tool_use request.
- What ends the loop? The stamp (stop_reason). tool_use means go round again; end_turn is the normal finish. Text in the reply never decides it.
- What is the turn limit for? A backstop for a loop that runs away. If it trips, the run is cut off and reported as hitting the limit, not as finished.
Where the picture is simplified
- The ledger leaves out the system prompt and tool definitions, which are also sent each round.
- In long sessions Claude Code compacts the ledger, replacing older history with a summary, so "the whole ledger" means the whole current ledger.
- Real ids look like toolu_01...; the film shows #1, #2, #3.
- Server tools (such as web search) are run by Anthropic's platform, not by your harness, and you never write their tool_result. Claude still only asks; "the harness does" describes client tools.
- Other stop reasons exist: max_tokens (reply cut off at the length limit), refusal (Claude declined), stop_sequence, model_context_window_exceeded, and pause_turn (a server-tool loop paused; re-send to continue). A careful harness checks which stamp it got before treating a reply as the finished answer.
- is_error marks a tool result as an error, for when the tool itself fails (for example, a network error). Harnesses differ on failing tests: Claude Code treats a command that exits non-zero, such as a failing test run, as a failed tool call. In this film the checks pass, so no error is shown.