Day 20 — A Bounded Agent Loop
Today Forge becomes an agent loop. The hard part is not repetition; it is knowing whether an iteration made verified progress and when the system must stop.
Run the loop lab
Section titled “Run the loop lab”cd rust/rust-ai-engineeringcargo test -p mosaic-harness agent_loopcargo run -q -p mosaic-harness --example bounded_agent_loop_labType the terminal states
Section titled “Type the terminal states”pub enum TerminalState { Completed, BudgetExhausted(BudgetKind), NoProgress, RepeatedAction, PolicyDenied, NeedsReconciliation, Failed,}Completion is not the string “done.” It requires the behavior contract’s completion evidence. Progress requires a successful state change plus new independently identified evidence.
Reserve before dispatch
Section titled “Reserve before dispatch”Before a model or tool call, reserve from the relevant budget. On known failure, release or commit according to policy. On an indeterminate external effect, stop for reconciliation—blind retry may duplicate a write.
Track maximum steps, model calls, tool calls, repairs, wall time, output bytes, and cost. One loop owner decides termination precedence.
Repair narrowly
Section titled “Repair narrowly”A malformed structured output may get bounded repair feedback. A provider timeout follows retry policy. A policy denial is not repaired by asking more persuasively. Keep these loops distinct.
Attack completion
Section titled “Attack completion”Add mutations where the model:
- repeats a successful action;
- claims completion without a receipt;
- changes text but not state;
- consumes a budget without accounting;
- proposes a step after a terminal event;
- receives an indeterminate write result.
The replayed receipt must reach the same terminal state without calling a model.
Completion proof
Section titled “Completion proof”Draw the state machine, name every terminal, and prove one run for successful completion, repeated action, no progress, exhausted budget, and uncertain effect.
Deep reference: Agent loops, progress, stopping, and repair.
Next: Day 21 — Authorization →.