/ the-loop
01 The Agent Loop
Day 1. The beating heart of every harness: a loop that calls the model, runs the tools it asks for, and repeats until the work is done. We build a bare harness from first principles.
→
The agent loop from first principlesLOOP
Call the model, see if it wants a tool, run it, feed the result back, repeat. The whole of agency is this while-loop. We derive it from nothing.
→
Messages, turns & roles
The conversation as an array of typed messages (system, user, assistant, tool). How a turn is structured and why the message array IS the agent's state.
→
Stop conditions: when does the loop end?
The model stops asking for tools, hits a limit, or is interrupted. Getting the stop condition right is the difference between an agent and an infinite loop.
→
Streaming responses into a terminal
Why you stream tokens and tool calls as they arrive instead of waiting for the full response, and how that changes the loop and the UI.
→
The model client & provider abstraction
One thin interface over the model API (and why models.json / a provider abstraction keeps the harness model-agnostic, a core pi idea).
→
Build: your first bare harnessBUILD
Model client + message array + a hand-rolled loop that runs until the model stops asking for work. The smallest thing that is genuinely an agent.
