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.1 |
2026-10-14 |
Routing consistency: added the routing-matrix phrase(s) "autonomous pipeline" to frontmatter triggers so skill-level selection matches the matrix. |
| 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-loops3version: "2.0.1"4compatibility: Any AI coding agent (Antigravity, Claude Code, Copilot, Cursor, OpenCode, Codex, pi, and all tools supporting the Agent Skills open standard)5description: |6 Autonomous loop patterns for multi-step AI workflows without human intervention.7 Use when building CI-style pipelines, parallel agent coordination, or continuous autonomous development cycles.8 Covers 5 loop architectures (Sequential Pipeline, Infinite Agentic Loop, Continuous PR Loop, De-Sloppify Pass, RFC-Driven DAG) with decision matrix.9category: meta-learning10triggers:11 - "autonomous workflow"12 - "autonomous loop"13 - "run without intervention"14 - "parallel agents"15 - "continuous development"16 - "multi-step pipeline"17 - "pr loop"18 - "agentic pipeline"19 - "Ralphinho"20 - "DAG orchestration"21 - "autonomous pipeline"22dependencies:23 - verification-loop: recommended24 - writing-plans: recommended25 - content-hash-cache-pattern: optional26 - cost-aware-llm-pipeline: recommended27metadata:28 source: https://skillmd.com/skills/k1lgor/autonomous-loops29---3031# Autonomous Loops Skill3233## Identity3435You 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.3637**Your core responsibility:** Design AI pipelines that run end-to-end reliably with minimal human intervention and explicit termination conditions.3839**Your operating principle:** Choose the simplest loop architecture that solves the problem; add termination conditions before starting.4041**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.4243## When to Use4445- Setting up autonomous development workflows that run without human intervention46- Choosing the right loop architecture for your problem47- Building CI/CD-style continuous development pipelines48- Running parallel agents with merge coordination49- Implementing context persistence across loop iterations50- Adding quality gates and cleanup passes to autonomous workflows5152## When NOT to Use5354- The task requires human approval or judgment at each step (use a supervised workflow instead)55- The task is a single focused change that can be done in one shot (use Sequential Pipeline only, not a loop)56- The output cannot be objectively validated (loops without a verification gate will silently accumulate errors)57- The codebase has no test suite — running autonomous loops against untested code with no CI gate is high risk58- You are mid-debugging and the root cause is not yet known (loops amplify confusion, not clarity)5960## Core Principles61621. **Always set a MAX_ITERATIONS ceiling.** An unbounded loop without a termination condition will exhaust compute budget, context window, or API quota silently.632. **Persist state to disk between iterations.** In-memory state is lost on crash, timeout, or compaction, forcing a restart from iteration 0.643. **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.654. **Stagnation detection prevents infinite loops.** If the loop produces the same output for N consecutive iterations, terminate — it is not converging.665. **Each iteration is independently re-runnable.** If iteration 5 fails, you should be able to restart at iteration 5, not iteration 1.6768---6970## Loop Pattern Spectrum7172| Pattern | Complexity | Best For |73|---|---|---|74| Sequential Pipeline | Low | Daily dev steps, scripted workflows |75| Infinite Agentic Loop | Medium | Parallel content generation, spec-driven work |76| Continuous PR Loop | Medium | Multi-day iterative projects with CI gates |77| De-Sloppify Pass | Add-on | Quality cleanup after any implement step |78| RFC-Driven DAG (Ralphinho) | High | Large features, multi-unit parallel work |7980## Decision Matrix8182```83Is the task a single focused change?84+-- Yes -> Sequential Pipeline85+-- No -> Is there a written spec/RFC?86 +-- Yes -> Need parallel implementation?87 | +-- Yes -> RFC-Driven DAG88 | +-- No -> Continuous PR Loop89 +-- No -> Need many variations?90 +-- Yes -> Infinite Agentic Loop91 +-- No -> Sequential Pipeline + De-Sloppify92```9394## Blocking Violations (NEVER)9596| Violation | Consequence | Recovery |97|---|---|---|98| Starting loop without MAX_ITERATIONS | Exhausts compute/context/API budget silently | Add MAX_ITERATIONS ceiling before starting |99| Skipping state persistence between iterations | State lost on crash; restart from iteration 0 | Persist state to disk after each iteration |100| Continuing loop after failing test | Downstream iterations compound on broken foundation | Stop on first failing test; fix before continuing |101| Running loop on production without feature branch | No clean rollback path; experimental changes conflated with production | Always use feature branch or sandbox |102| Using generating model as sole quality judge | Systematically biased toward rating own output correct | Use separate evaluator or deterministic test |103104## Verification105106### Self-Verification Checklist107108- [ ] MAX_ITERATIONS ceiling defined before loop starts109- [ ] Completion signal defined (what "done" looks like)110- [ ] CI gate configured (stops loop on failure)111- [ ] Stagnation detection in place (same output N consecutive times = stop)112- [ ] State persisted to disk between iterations113- [ ] Git checkpoint per iteration114115### Verification Commands116117```bash118# Check iteration count119grep -rn "MAX_ITERATIONS\|max_iterations\|maxIterations" loop-script.sh120121# Check completion signal122grep -rn "completion.txt\|DONE\|stop_condition\|complete_flag" loop-script.sh123124# Check stagnation detection125grep -rn "stagnation\|same_output\|no_change\|consecutive_failures" loop-script.sh126127# Verify git checkpoints128git log --oneline | wc -l129```130131### Quality Gates132133| Gate | Criteria | Fail Action |134|---|---|---|135| Termination | MAX_ITERATIONS set and completion signal defined | Do not start loop without both |136| State Persistence | State written to disk between iterations | Add persistence before production use |137| CI Gate | Tests run after each iteration; failure stops loop | Add CI check gate |138| Stagnation | Detector for N consecutive identical outputs | Add stagnation check before running |139140## Examples141142### Example 1: Sequential Pipeline143144**User request:** "Set up an automated daily code review pipeline."145146**Skill execution:**1471. Choose: Sequential Pipeline (single focused workflow)1482. Define steps: Plan -> Execute Review -> Generate Fixes1493. Each step independently re-runnable, passes context via files1504. Add MAX_ITERATIONS=1 (sequential, no loop needed)1515. CI gate: stop on failure152153**Result:** Simple, reliable pipeline. Each step independently runnable.154155### Example 2: Edge Case - Loop Stagnation156157**User request:** "Our PR loop keeps making the same change and undoing it."158159**Skill execution:**1601. Check stagnation detector: not implemented1612. Loop was producing same output for 6 consecutive iterations1623. Add: detect if `git diff` output is identical to previous iteration1634. Terminate after 3 consecutive identical outputs1645. Escalate to human review165166**Result:** Stagnation detected and escalated. Loop no longer wastes budget on zero-progress iterations.167168## Anti-Patterns169170- 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.171- 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.172- 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.173- 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.174175## Failure Modes176177| Situation | Response |178|---|---|179| Loop runs forever | Add max iterations. Escalate to human after N cycles. |180| Loop produces same output | Detect stagnation. Change approach or escalate. |181| Loop corrupts files | Use git checkpoint before each iteration. Rollback on regression. |182| Loop misses completion signal | Persist completion state to an external file checked each iteration. |183184## Performance & Cost185186### Model Selection187188| Task | Recommended Model | Cost per loop |189|---|---|---|190| Sequential Pipeline orchestration | Haiku | $0.01-$0.05 |191| Infinite Agentic Loop (per iteration) | Haiku | $0.01-$0.03 |192| Continuous PR Loop (per cycle) | Sonnet | $0.10-$0.30 |193| Stagnation detection check | Haiku | $0.01-$0.02 |194| Quality gate review | Sonnet | $0.05-$0.15 |195196### Token Budget197198- **State persistence overhead:** ~100-300 tokens per iteration (state summary)199- **Expected context usage:** 2-5KB per loop design session200- **When to context-optimize:** When loops have 10+ iterations or span multiple files per iteration201- **Use cost-aware-llm-pipeline** for routing loop subtasks to appropriate model tiers202203## References204205### Internal Dependencies206- `verification-loop` — Used as exit gate for any autonomous loop207- `writing-plans` — Provides the spec that autonomous loops execute against208- `cost-aware-llm-pipeline` — Routes loop subtasks to appropriate model tier209210### External Standards211- [DAG (Directed Acyclic Graph)](https://en.wikipedia.org/wiki/Directed_acyclic_graph) — Foundation for Ralphinho pattern's task graph212213### Related Skills214- `verification-loop` — Exit gate for autonomous loops215- `writing-plans` — Input spec provider216217## Changelog218219| Version | Date | Changes |220|---|---|---|221| 2.0.1 | 2026-10-14 | Routing consistency: added the routing-matrix phrase(s) "autonomous pipeline" to frontmatter triggers so skill-level selection matches the matrix. |222| 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. |223---