The Agent Loop
Every AI agent you've ever used is this loop:
Here is the agent, is the model, and is tool or environment execution. The state is the model-visible transcript, modeled as a sequence of messages and tool events. The outputs , , and are transcript entries, and appends them to the transcript.
The loop is simple: the model either answers, or asks for an action. If it asks for an action, the agent executes it, concatenates the action and result onto the transcript, and runs the loop again.
This version quietly assumes infinite context. Real agents have finite context windows, so the state may need to be normalized before each model call. Context management is a preprocessing step, not a third model outcome. Let be the length of the state, be the context limit, and be the compression function. For a given state , define the model-visible state as:
With finite context, the loop becomes:
is the transcript the model actually sees: compressed if needed, otherwise unchanged.