PATH COMPLETION0 / 45 STEPS (0%)
BACK TO LEARNING PATHTRACK 01: Agent Foundations
Step 4 of 6 in this track · 7 min

The agent loop

Every agent, whatever the branding, runs the same basic cycle. Once you can see it, most confusing agent behaviour becomes explainable.

The cycle

  1. The harness sends the model everything it knows: your instructions, the conversation so far, and the list of tools available.
  2. The model replies with either text for you, or a request to call a tool.
  3. If it called a tool, the harness runs that tool and puts the result back into the conversation.
  4. Return to step 1.

That loop repeats until the model stops asking for tools and answers you instead, or until it hits a limit.

What this explains

Why the agent forgets things. Each pass resends the conversation. When it grows past the context window, something has to be dropped or summarised. What got dropped is what it forgot.

Why it repeats a failed command. The model sees the error in the conversation. If nothing in its instructions tells it to change approach after a failure, running the same command again is a perfectly reasonable next prediction.

Why costs grow faster than you expect. Turn ten resends everything from turns one through nine. Cost per turn rises through a long session even if your messages stay short.

Why it does not know what it just did. The model has no memory outside the conversation. If a tool result was trimmed to save space, that action is now invisible to it.

The part people get wrong

The model does not execute anything. It produces text saying it would like to call a tool with certain arguments. The harness decides whether to run it.

This matters because it is the only place safety lives. When you approve a command, you are approving something the harness is about to run, and the model has no way to run it without you. Everything in permissions and approvals builds on that gap.

Where it stops

Harnesses cap the loop, usually on total turns or total tokens. When an agent stops mid task saying it has run out of steps, it hit that cap rather than deciding it was finished.

Long tasks need either a higher cap or a smaller task. Smaller is almost always the better answer, because a long loop accumulates context, and accumulated context degrades quality.

Try it

Ask an agent to read one file and report what it contains. Watch the sequence: it calls a read tool, gets the contents, then answers. That is two passes through the loop. Every complex task is that same shape, repeated.