CHAPTER 02 · The Agent Loop · 2 / 5
How it works: a closer walk
Let us trace one real turn, the kind Bolin describes in the Codex write-up.
- You type: "Add an architecture diagram to the README."
- The harness builds a prompt (Chapter 3 covers exactly what goes in it) and calls the model.
- The model thinks, then asks for a tool call:
shellwith commandcat README.md. It does not run anything; it asks. - The harness runs
cat README.md, captures the output, and appends two things to the history: the tool call and its result, linked by a sharedcall_idso the model knows which result belongs to which call. - The harness calls the model again, now with the README contents included.
- The model asks for another tool call: an edit that inserts the diagram.
- The harness applies the edit, appends the result, calls again.
- This time the model returns plain text: "I added a diagram explaining the client/server architecture." Turn over.
Notice that step 4's appended history is what makes step 5 smarter than step 2. Each tool result feeds back in. That feedback is the whole point; it is why the loop can course-correct instead of blindly executing a fixed plan.