Loop Engineering Handbook
Automate the run. Verify the result.
You learned to prompt. Then you learned to direct agents. Now learn to build the system that runs the runs. Loop engineering is the discipline of writing automation that prompts an AI, checks the result, and re-runs until done - with real stop conditions, cost controls, and a verifier that is not the agent itself. This handbook is the third book in the trilogy: the altitude above both.
Inside this book
- Loop anatomy: trigger, skill, durable state, verifier, isolation, and stop condition
- The three loop types: goal loops (work to a condition), timer loops (present), and scheduled cloud routines (absent)
- Verification-first design: cross-model judges, idempotent oracles, and reward-hacking defenses
- Durable state mechanics: stateless iteration, disk/git-backed progress, and append-only journals
- Cost controls: max-iteration caps, no-progress detection, token budgets, and cost-per-accepted-change tracking
- Eight loop shapes: build-test-fix, quality-streak, generate-and-rank, refine-to-threshold, adversarial review, completion contracts, fresh-context goal loops, and human-gated loops
- Self-improving loops: hill-climbing via traces, Champion/Challenger prompt promotion, and outer-loop skill rewriting
- Build discipline: prove by hand, skillify, add a verification gate, then schedule
- Long-horizon goal loops: fresh context each pass, a checklist the loop must clear, and IVO as the exit condition
- Human gates: consultative intake, approval before irreversible actions, and escalation instead of guessing
- Eval-driven iteration: capability and regression evals as the loop's scoreboard and promotion gate
By Valentin Nagacevschi