Loops, levels, and building a platform that drives itself
Agent operations · Bounded loops
What you will leave with
Build a loop that verifies each transition, stops deterministically, and escalates without losing context.
What you will build
One persisted state machine around a narrow action and an independent verifier.
- 01Load stateResume the same attempt safely after interruption.
- 02ActPerform one bounded, idempotent operation.
- 03ObserveCapture artifact state rather than worker confidence.
- 04DecideSucceed, retry, stop, or escalate.
- 05PersistRecord transition, budget, evidence, and next action.
Build it in sequence
Define the state machine first
Name success, retryable failure, terminal failure, waiting, budget exhaustion, and human review. If two states look the same to the code, the loop will eventually choose the unsafe one.
type LoopState =
| 'ready'
| 'waiting-for-evidence'
| 'retryable-failure'
| 'terminal-failure'
| 'human-review'
| 'succeeded'Make one iteration idempotent
Give every attempt an idempotency key and check current external state before acting. A process restart must not duplicate a ticket, deployment, payment, notification, or merge.
Verify before the next action
Bind the observation to the artifact produced by this iteration. Do not let a green check for an earlier commit or cached deployment advance the current loop.
if (evidence.commit !== attempt.commit) return 'terminal-failure'
if (evidence.deployment !== attempt.deployment) return 'terminal-failure'
if (evidence.required.some((check) => check.status !== 'success')) return 'wait'
return 'succeeded'Spend from explicit budgets
Track attempts, wall time, tokens, tool calls, and external mutations separately. Exhaustion produces an escalation; it never silently buys more budget.
Return a decision packet
On stop or escalation, report the state, attempts, last verified artifact, contradiction, reversible options, and recommended next action, not a transcript.
Definition of done
- Success and terminal failure are observable and distinct.
- One iteration is safe to retry.
- Evidence is bound to this attempt's artifact.
- Every resource has a hard ceiling.
- Restart resumes state without duplicating side effects.
- Escalation contains a recommendation and rollback context.
What breaks and what it means
The loop keeps making plausible changes without converging.
The verifier is too weak or the stopping condition measures activity rather than outcome.
Retries duplicate external actions.
Add an idempotency key and observe current state before mutation.
Questions, corrections, and useful disagreement
Sign in with GitHub to join the conversation. Comments are public. Article views are anonymous and counted once per browser, per article, each day.