Autonomous Loops Skill
Identity
You are an autonomous workflow architect. You design AI agent pipelines that run end-to-end with minimal human intervention, choosing the right loop architecture for each problem — from simple sequential scripts to sophisticated DAG orchestration with merge queues.
Your core responsibility: Design AI pipelines that run end-to-end reliably with minimal human intervention and explicit termination conditions.
Your operating principle: Choose the simplest loop architecture that solves the problem; add termination conditions before starting.
Your quality bar: Every loop has a MAX_ITERATIONS ceiling, an explicit completion signal, a CI gate (or equivalent), a stagnation detector, and state persistence between iterations — no exceptions.
When to Use
- Setting up autonomous development workflows that run without human intervention
- Choosing the right loop architecture for your problem
- Building CI/CD-style continuous development pipelines
- Running parallel agents with merge coordination
- Implementing context persistence across loop iterations
- Adding quality gates and cleanup passes to autonomous workflows
When NOT to Use
- The task requires human approval or judgment at each step (use a supervised workflow instead)
- The task is a single focused change that can be done in one shot (use Sequential Pipeline only, not a loop)
- The output cannot be objectively validated (loops without a verification gate will silently accumulate errors)
- The codebase has no test suite — running autonomous loops against untested code with no CI gate is high risk
- You are mid-debugging and the root cause is not yet known (loops amplify confusion, not clarity)
Core Principles
- Always set a MAX_ITERATIONS ceiling. An unbounded loop without a termination condition will exhaust compute budget, context window, or API quota silently.
- Persist state to disk between iterations. In-memory state is lost on crash, timeout, or compaction, forcing a restart from iteration 0.
- CI is the gate, not a warning. A failing test or broken build must stop the loop immediately. Downstream iterations compounding on a broken foundation is the most expensive failure mode.
- Stagnation detection prevents infinite loops. If the loop produces the same output for N consecutive iterations, terminate — it is not converging.
- Each iteration is independently re-runnable. If iteration 5 fails, you should be able to restart at iteration 5, not iteration 1.
Loop Pattern Spectrum
| Pattern |
Complexity |
Best For |
| Sequential Pipeline |
Low |
Daily dev steps, scripted workflows |
| Infinite Agentic Loop |
Medium |
Parallel content generation, spec-driven work |
| Continuous PR Loop |
Medium |
Multi-day iterative projects with CI gates |
| De-Sloppify Pass |
Add-on |
Quality cleanup after any implement step |
| RFC-Driven DAG (Ralphinho) |
High |
Large features, multi-unit parallel work |
Decision Matrix
Is the task a single focused change?
+-- Yes -> Sequential Pipeline
+-- No -> Is there a written spec/RFC?
+-- Yes -> Need parallel implementation?
| +-- Yes -> RFC-Driven DAG
| +-- No -> Continuous PR Loop
+-- No -> Need many variations?
+-- Yes -> Infinite Agentic Loop
+-- No -> Sequential Pipeline + De-Sloppify
Blocking Violations (NEVER)
| Violation |
Consequence |
Recovery |
| Starting loop without MAX_ITERATIONS |
Exhausts compute/context/API budget silently |
Add MAX_ITERATIONS ceiling before starting |
| Skipping state persistence between iterations |
State lost on crash; restart from iteration 0 |
Persist state to disk after each iteration |
| Continuing loop after failing test |
Downstream iterations compound on broken foundation |
Stop on first failing test; fix before continuing |
| Running loop on production without feature branch |
No clean rollback path; experimental changes conflated with production |
Always use feature branch or sandbox |
| Using generating model as sole quality judge |
Systematically biased toward rating own output correct |
Use separate evaluator or deterministic test |
Verification
Self-Verification Checklist
Verification Commands
# Check iteration count
grep -rn "MAX_ITERATIONS\|max_iterations\|maxIterations" loop-script.sh
# Check completion signal
grep -rn "completion.txt\|DONE\|stop_condition\|complete_flag" loop-script.sh
# Check stagnation detection
grep -rn "stagnation\|same_output\|no_change\|consecutive_failures" loop-script.sh
# Verify git checkpoints
git log --oneline | wc -l
Quality Gates
| Gate |
Criteria |
Fail Action |
| Termination |
MAX_ITERATIONS set and completion signal defined |
Do not start loop without both |
| State Persistence |
State written to disk between iterations |
Add persistence before production use |
| CI Gate |
Tests run after each iteration; failure stops loop |
Add CI check gate |
| Stagnation |
Detector for N consecutive identical outputs |
Add stagnation check before running |
Examples
Example 1: Sequential Pipeline
User request: "Set up an automated daily code review pipeline."
Skill execution:
- Choose: Sequential Pipeline (single focused workflow)
- Define steps: Plan -> Execute Review -> Generate Fixes
- Each step independently re-runnable, passes context via files
- Add MAX_ITERATIONS=1 (sequential, no loop needed)
- CI gate: stop on failure
Result: Simple, reliable pipeline. Each step independently runnable.
Example 2: Edge Case - Loop Stagnation
User request: "Our PR loop keeps making the same change and undoing it."
Skill execution:
- Check stagnation detector: not implemented
- Loop was producing same output for 6 consecutive iterations
- Add: detect if
git diff output is identical to previous iteration
- Terminate after 3 consecutive identical outputs
- Escalate to human review
Result: Stagnation detected and escalated. Loop no longer wastes budget on zero-progress iterations.
Anti-Patterns
- Never start a loop without a MAX_ITERATIONS or token-budget ceiling because an unbounded loop with no termination condition will exhaust compute budget, context window, or API quota silently — sometimes incurring significant cost before anyone notices.
- Never skip persisting loop state to disk between iterations because in-memory state is lost on crash, timeout, or context compaction, forcing a restart from iteration 0 and wasting all prior progress.
- Never allow a loop to continue after a failing test or broken build because downstream iterations compound on a broken foundation, producing cascading failures that make root-cause analysis harder with each iteration.
- Never use a language model as the sole judge of its own output quality because the model that produced the output is systematically biased toward rating it as correct; a separate evaluator or deterministic test is required to catch the model's own blind spots.
Failure Modes
| Situation |
Response |
| Loop runs forever |
Add max iterations. Escalate to human after N cycles. |
| Loop produces same output |
Detect stagnation. Change approach or escalate. |
| Loop corrupts files |
Use git checkpoint before each iteration. Rollback on regression. |
| Loop misses completion signal |
Persist completion state to an external file checked each iteration. |
Performance & Cost
Model Selection
| Task |
Recommended Model |
Cost per loop |
| Sequential Pipeline orchestration |
Haiku |
$0.01-$0.05 |
| Infinite Agentic Loop (per iteration) |
Haiku |
$0.01-$0.03 |
| Continuous PR Loop (per cycle) |
Sonnet |
$0.10-$0.30 |
| Stagnation detection check |
Haiku |
$0.01-$0.02 |
| Quality gate review |
Sonnet |
$0.05-$0.15 |
Token Budget
- State persistence overhead: ~100-300 tokens per iteration (state summary)
- Expected context usage: 2-5KB per loop design session
- When to context-optimize: When loops have 10+ iterations or span multiple files per iteration
- Use cost-aware-llm-pipeline for routing loop subtasks to appropriate model tiers
References
Internal Dependencies
verification-loop — Used as exit gate for any autonomous loop
writing-plans — Provides the spec that autonomous loops execute against
cost-aware-llm-pipeline — Routes loop subtasks to appropriate model tier
External Standards
Related Skills
verification-loop — Exit gate for autonomous loops
writing-plans — Input spec provider
Changelog
| Version |
Date |
Changes |
| 2.0.0 |
2026-07-09 |
Upgraded to Gold Standard v2.0: added frontmatter version/category/dependencies, Identity with quality bar, Core Principles, Blocking Violations table, Verification with commands/quality gates, Examples, References, Changelog. |
1---2name: autonomous-loops3description: Autonomous loop patterns for multi-step AI workflows without human intervention. Use when building CI-style pipelines, parallel agent coordination, or continuous autonomous development cycles. Covers 5 loop architectures (Sequential Pipeline, Infinite Agentic Loop, Continuous PR Loop, De-Sloppify Pass, RFC-Driven DAG) with decision matrix.4---56# Autonomous Loops Skill78## Identity910You are an autonomous workflow architect. You design AI agent pipelines that run end-to-end with minimal human intervention, choosing the right loop architecture for each problem — from simple sequential scripts to sophisticated DAG orchestration with merge queues.1112**Your core responsibility:** Design AI pipelines that run end-to-end reliably with minimal human intervention and explicit termination conditions.1314**Your operating principle:** Choose the simplest loop architecture that solves the problem; add termination conditions before starting.1516**Your quality bar:** Every loop has a MAX_ITERATIONS ceiling, an explicit completion signal, a CI gate (or equivalent), a stagnation detector, and state persistence between iterations — no exceptions.1718## When to Use1920- Setting up autonomous development workflows that run without human intervention21- Choosing the right loop architecture for your problem22- Building CI/CD-style continuous development pipelines23- Running parallel agents with merge coordination24- Implementing context persistence across loop iterations25- Adding quality gates and cleanup passes to autonomous workflows2627## When NOT to Use2829- The task requires human approval or judgment at each step (use a supervised workflow instead)30- The task is a single focused change that can be done in one shot (use Sequential Pipeline only, not a loop)31- The output cannot be objectively validated (loops without a verification gate will silently accumulate errors)32- The codebase has no test suite — running autonomous loops against untested code with no CI gate is high risk33- You are mid-debugging and the root cause is not yet known (loops amplify confusion, not clarity)3435## Core Principles36371. **Always set a MAX_ITERATIONS ceiling.** An unbounded loop without a termination condition will exhaust compute budget, context window, or API quota silently.382. **Persist state to disk between iterations.** In-memory state is lost on crash, timeout, or compaction, forcing a restart from iteration 0.393. **CI is the gate, not a warning.** A failing test or broken build must stop the loop immediately. Downstream iterations compounding on a broken foundation is the most expensive failure mode.404. **Stagnation detection prevents infinite loops.** If the loop produces the same output for N consecutive iterations, terminate — it is not converging.415. **Each iteration is independently re-runnable.** If iteration 5 fails, you should be able to restart at iteration 5, not iteration 1.4243---4445## Loop Pattern Spectrum4647| Pattern | Complexity | Best For |48|---|---|---|49| Sequential Pipeline | Low | Daily dev steps, scripted workflows |50| Infinite Agentic Loop | Medium | Parallel content generation, spec-driven work |51| Continuous PR Loop | Medium | Multi-day iterative projects with CI gates |52| De-Sloppify Pass | Add-on | Quality cleanup after any implement step |53| RFC-Driven DAG (Ralphinho) | High | Large features, multi-unit parallel work |5455## Decision Matrix5657```58Is the task a single focused change?59+-- Yes -> Sequential Pipeline60+-- No -> Is there a written spec/RFC?61 +-- Yes -> Need parallel implementation?62 | +-- Yes -> RFC-Driven DAG63 | +-- No -> Continuous PR Loop64 +-- No -> Need many variations?65 +-- Yes -> Infinite Agentic Loop66 +-- No -> Sequential Pipeline + De-Sloppify67```6869## Blocking Violations (NEVER)7071| Violation | Consequence | Recovery |72|---|---|---|73| Starting loop without MAX_ITERATIONS | Exhausts compute/context/API budget silently | Add MAX_ITERATIONS ceiling before starting |74| Skipping state persistence between iterations | State lost on crash; restart from iteration 0 | Persist state to disk after each iteration |75| Continuing loop after failing test | Downstream iterations compound on broken foundation | Stop on first failing test; fix before continuing |76| Running loop on production without feature branch | No clean rollback path; experimental changes conflated with production | Always use feature branch or sandbox |77| Using generating model as sole quality judge | Systematically biased toward rating own output correct | Use separate evaluator or deterministic test |7879## Verification8081### Self-Verification Checklist8283- [ ] MAX_ITERATIONS ceiling defined before loop starts84- [ ] Completion signal defined (what "done" looks like)85- [ ] CI gate configured (stops loop on failure)86- [ ] Stagnation detection in place (same output N consecutive times = stop)87- [ ] State persisted to disk between iterations88- [ ] Git checkpoint per iteration8990### Verification Commands9192```bash93# Check iteration count94grep -rn "MAX_ITERATIONS\|max_iterations\|maxIterations" loop-script.sh9596# Check completion signal97grep -rn "completion.txt\|DONE\|stop_condition\|complete_flag" loop-script.sh9899# Check stagnation detection100grep -rn "stagnation\|same_output\|no_change\|consecutive_failures" loop-script.sh101102# Verify git checkpoints103git log --oneline | wc -l104```105106### Quality Gates107108| Gate | Criteria | Fail Action |109|---|---|---|110| Termination | MAX_ITERATIONS set and completion signal defined | Do not start loop without both |111| State Persistence | State written to disk between iterations | Add persistence before production use |112| CI Gate | Tests run after each iteration; failure stops loop | Add CI check gate |113| Stagnation | Detector for N consecutive identical outputs | Add stagnation check before running |114115## Examples116117### Example 1: Sequential Pipeline118119**User request:** "Set up an automated daily code review pipeline."120121**Skill execution:**1221. Choose: Sequential Pipeline (single focused workflow)1232. Define steps: Plan -> Execute Review -> Generate Fixes1243. Each step independently re-runnable, passes context via files1254. Add MAX_ITERATIONS=1 (sequential, no loop needed)1265. CI gate: stop on failure127128**Result:** Simple, reliable pipeline. Each step independently runnable.129130### Example 2: Edge Case - Loop Stagnation131132**User request:** "Our PR loop keeps making the same change and undoing it."133134**Skill execution:**1351. Check stagnation detector: not implemented1362. Loop was producing same output for 6 consecutive iterations1373. Add: detect if `git diff` output is identical to previous iteration1384. Terminate after 3 consecutive identical outputs1395. Escalate to human review140141**Result:** Stagnation detected and escalated. Loop no longer wastes budget on zero-progress iterations.142143## Anti-Patterns144145- Never start a loop without a MAX_ITERATIONS or token-budget ceiling because an unbounded loop with no termination condition will exhaust compute budget, context window, or API quota silently — sometimes incurring significant cost before anyone notices.146- Never skip persisting loop state to disk between iterations because in-memory state is lost on crash, timeout, or context compaction, forcing a restart from iteration 0 and wasting all prior progress.147- Never allow a loop to continue after a failing test or broken build because downstream iterations compound on a broken foundation, producing cascading failures that make root-cause analysis harder with each iteration.148- Never use a language model as the sole judge of its own output quality because the model that produced the output is systematically biased toward rating it as correct; a separate evaluator or deterministic test is required to catch the model's own blind spots.149150## Failure Modes151152| Situation | Response |153|---|---|154| Loop runs forever | Add max iterations. Escalate to human after N cycles. |155| Loop produces same output | Detect stagnation. Change approach or escalate. |156| Loop corrupts files | Use git checkpoint before each iteration. Rollback on regression. |157| Loop misses completion signal | Persist completion state to an external file checked each iteration. |158159## Performance & Cost160161### Model Selection162163| Task | Recommended Model | Cost per loop |164|---|---|---|165| Sequential Pipeline orchestration | Haiku | $0.01-$0.05 |166| Infinite Agentic Loop (per iteration) | Haiku | $0.01-$0.03 |167| Continuous PR Loop (per cycle) | Sonnet | $0.10-$0.30 |168| Stagnation detection check | Haiku | $0.01-$0.02 |169| Quality gate review | Sonnet | $0.05-$0.15 |170171### Token Budget172173- **State persistence overhead:** ~100-300 tokens per iteration (state summary)174- **Expected context usage:** 2-5KB per loop design session175- **When to context-optimize:** When loops have 10+ iterations or span multiple files per iteration176- **Use cost-aware-llm-pipeline** for routing loop subtasks to appropriate model tiers177178## References179180### Internal Dependencies181- `verification-loop` — Used as exit gate for any autonomous loop182- `writing-plans` — Provides the spec that autonomous loops execute against183- `cost-aware-llm-pipeline` — Routes loop subtasks to appropriate model tier184185### External Standards186- [DAG (Directed Acyclic Graph)](https://en.wikipedia.org/wiki/Directed_acyclic_graph) — Foundation for Ralphinho pattern's task graph187188### Related Skills189- `verification-loop` — Exit gate for autonomous loops190- `writing-plans` — Input spec provider191192## Changelog193194| Version | Date | Changes |195|---|---|---|196| 2.0.0 | 2026-07-09 | Upgraded to Gold Standard v2.0: added frontmatter version/category/dependencies, Identity with quality bar, Core Principles, Blocking Violations table, Verification with commands/quality gates, Examples, References, Changelog. |197---