Anatomy of one turn

Lesson 1 of 5 in The Agent Loop: One Turn at a Time.

The previous module gave you the definition — an LLM given tools, run in a loop, with a stopping condition — and showed you the loop from orbit. This module lands and walks the ground, because every capability an agent has, and every way it fails, lives inside the loop’s unit of work: the turn.

A turn is one model call plus everything it triggers. The model reads the entire context — system prompt, tool contracts, the user’s request, every earlier message and tool result — and produces one response. That response either contains tool calls or it doesn’t. If it does, the runtime executes them, appends the results to the context, and calls the model again: next turn. If it doesn’t, the loop exits, and whatever the model wrote is the answer. Think → act → observe → repeat.

One full turn — and the one place the loop exits by choice

  1. Turn begins: the context so far

    Goal, system prompt, tool contracts, and everything that has happened — messages and tool results — in one window.

  2. Model call: the LLM reads it all

    One inference pass over the whole context. The model has no other source of information — no memory outside this window.

  3. Tool calls in the response?

    The model-directed branch. Nothing in your code decides which way this goes.

  4. Runtime executes each call

    The model only requested. The harness validates arguments, applies permissions, and runs the actual code.

  5. Results appended to context

    Observation. The tool output becomes ordinary context text — the model will read it on the next pass.

  6. Loop exits: final answer returned

    The natural stop: the model chose to answer instead of act. Lesson 3 covers the exits that don’t wait for its choice.

Two properties of this diagram do most of the explaining for the rest of the module.

The model is stateless between turns. It doesn’t remember turn one when turn three starts — it re-reads it. The context window is the loop’s entire memory, which is why context is a budget measured in tokens, why long-running agents eventually hit its ceiling, and why what you append after each tool call matters so much.

The happy path has exactly one exit. Trace the arrows: the only way out is the model responding without tool calls — the natural stop. Every other way a real loop ends is a backstop bolted on from outside, and lesson 3 is about why you must bolt them on.

Key terms: agent loop, turn, context window, tool call, natural stop

Interactive checkpoint quiz (2 questions) — open this page in a browser to take it.