Agent Loops & Checkpointing
An agent is a loop with a budget
An agent repeatedly asks a model what to do next, executes a tool or deterministic step, appends the result to state, and asks again. The model provides decisions inside the loop; the runtime owns the loop itself.
Every production loop needs explicit terminal states: success, user input required, policy refusal, permanent failure, and budget exhausted. Bound model calls, tool calls, elapsed time, tokens, and spend. “Continue until done” is not a stopping condition the infrastructure can enforce.
The transcript grows after every step. Later model calls resend earlier messages and tool results, so token work can grow faster than the step count. Compact old state into typed facts, store large artifacts outside the prompt, and give the model references instead of repeatedly copying entire outputs.
load state → model decision → validate → execute step
▲ │
│ ▼
└──────── checkpoint ◀──── append typed result
stop when: success | input required | refused | failed | budget exhausted