Continuous Agent Loop
Patterns for autonomous agent loops with quality gates and recovery.
Loop Selection
Choose your loop type based on requirements:
Need strict CI/PR control?
→ continuous-pr
Need RFC decomposition?
→ rfc-dag
Need exploratory parallel generation?
→ infinite
Default → sequential
Production Stack (Recommended)
- RFC decomposition — break large requests into a DAG of sub-tasks before looping
- Quality gates — define explicit pass/fail criteria before starting each loop iteration
- Eval loop — run automated checks after each iteration to verify progress
- Session persistence — checkpoint state between iterations so you can resume on failure
Key Patterns
Sequential Loop:
- Single task → execute → verify → repeat
- Best for: stable, incremental work
- Recovery: freeze, audit, reduce scope
RFC-DAG Loop:
- Decompose request → parallel branches → merge results
- Best for: complex multi-part features
- Recovery: replay failing unit
CI/PR Loop:
- Generate → test → push PR → merge on pass
- Best for: code-heavy deliverables
- Recovery: fail fast, surface root cause
Infinite/Exploratory:
- Generate variants in parallel, filter winners
- Best for: creative or search-heavy work
- Recovery: cap iterations, tighten criteria
Failure Modes & Recovery
| Problem | Root Cause | Fix |
|---|---|---|
| Loop churn | Vague acceptance criteria | Freeze & redefine criteria |
| Repeated retries | Same root cause ignored | Run harness audit (see scripts/harness-audit.js), fix root |
| Merge queue stalls | Test flakes or deps | Isolate failing unit |
| Cost drift | Unbounded escalation | Cap token budget per loop |
Recovery checklist:
- Freeze loop
- Run
node scripts/harness-audit.js— scores 7 categories (tool coverage, quality gates, evals, security, cost efficiency, memory, context) - Reduce scope to failing unit
- Replay with explicit criteria
References
scripts/harness-audit.js— deterministic audit script, scores repo 0-70 across 7 categoriesreferences/harness-audit.md— full command usage and output contract
