Overview
Many “agents” are just controlled loops:- Run an iteration body
- Decide whether to stop
- Enforce budgets/timeouts
- Optionally checkpoint or interrupt
agent_loop(...), which returns a Step you can compose like any other step.
LoopPolicy and LoopState
LoopPolicy controls loop execution:
max_iterationstimeout_seconds- Optional
checkpoint_store+checkpoint_policy - Optional
execution_policy(budgets)
LoopState tracks iteration index, elapsed time, and the last checkpoint id.
Checkpointing and budgets in loops
The loop can checkpoint before/after each iteration and on errors/interrupts. If a usage policy is configured, the loop checks budget before each iteration.Stop conditions
The stop condition is a function:(state) -> bool.
Keep it:
- Explicit (no hidden globals)
- Cheap (evaluated every iteration)
- Testable (unit tests should cover stop behavior)