Skip to slide
023 / 170

CH 02 · The Agent Loop · 11/11

Read as one page

Key takeaways

  • The agent loop is tiny: call the model, run any tool it asks for, append the result, repeat until the model returns plain text.
  • Anthropic's version is "gather context, take action, verify results." It is the same loop.
  • Each model call ends one of two ways: a tool request (keep looping) or an assistant message (stop).
  • Production loops add stop rules on top of that. mini-swe-agent treats plain text as a format error and stops only on an explicit submit, pi keeps going while you have messages queued, and Codex can take another lap when a hook or the API says the turn is unfinished.
  • For a software agent, the real output is the changes on your machine, not the final text. The text is just the "I'm done" signal.
  • A turn can contain dozens of inference-and-tool laps, and each turn re-sends the whole growing history, which sets up the cost problem in Chapter 4.

Original sources for this chapter: Anthropic's How Claude Code works and OpenAI's Unrolling the Codex agent loop by Michael Bolin.


Finished this idea?

Your learning progress stays in this browser.