CH 02 · The Agent Loop Pattern · 01/15
Read as one pageThe Agent Loop Pattern
The agent loop appends each request and result until the model stops or hits a safety cap. Covers common failure modes to design against.
15 slides · 14 min read
In this chapter
- 01The essential loop
- 02Why both the request and the result must be appended
- 03Real code: Codex never sends a call without its output
- 04Termination and the safety cap
- 05Real code: the OpenAI Agents SDK caps turns
- 06Where the loop lives
- 07Variants of the loop
- 08The event timeline
- 09Real code: pi's typed event timeline
- 10Statelessness within, state at the edges
- 11Common failure modes to design against
- 12Real code: Gemini CLI spots a stuck loop
- 13Real code: pi turns every tool failure into a result
- 14Read the source yourself
The agent loop is the heart of every agent. This chapter examines it as a pattern: its essential shape, its variants, how it terminates, and the safety properties you must build in. Get the loop right and the rest of the system has a solid spine to hang off.
Finished this idea?
Your learning progress stays in this browser.