autonomous-loops

Six proven autonomous agent loop patterns with guard rails. Provides reusable patterns for generate->validate->fix, explore->hypothesize->test, and other autonomous workflows. Includes the reviewer-never-authored principle for quality assurance. Use when: (1) Building autonomous agent workflows, (2) Designing self-correcting pipelines, (3) Implementing agent retry/fix loops, (4) Setting up multi-agent review processes, (5) User asks about agent loop patterns.

Best use case

autonomous-loops is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Six proven autonomous agent loop patterns with guard rails. Provides reusable patterns for generate->validate->fix, explore->hypothesize->test, and other autonomous workflows. Includes the reviewer-never-authored principle for quality assurance. Use when: (1) Building autonomous agent workflows, (2) Designing self-correcting pipelines, (3) Implementing agent retry/fix loops, (4) Setting up multi-agent review processes, (5) User asks about agent loop patterns.

Teams using autonomous-loops should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/autonomous-loops/SKILL.md --create-dirs "https://raw.githubusercontent.com/stevengonsalvez/agents-in-a-box/main/toolkit/packages/skills/autonomous-loops/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/autonomous-loops/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How autonomous-loops Compares

Feature / Agentautonomous-loopsStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Six proven autonomous agent loop patterns with guard rails. Provides reusable patterns for generate->validate->fix, explore->hypothesize->test, and other autonomous workflows. Includes the reviewer-never-authored principle for quality assurance. Use when: (1) Building autonomous agent workflows, (2) Designing self-correcting pipelines, (3) Implementing agent retry/fix loops, (4) Setting up multi-agent review processes, (5) User asks about agent loop patterns.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# Autonomous Loop Patterns

## Core Principle: Reviewer Never Authored

**The agent that reviews work must never be the agent that authored it.**

This is the single most important principle for autonomous quality. Self-review is
unreliable -- the same blind spots that caused the error will miss it during review.

Implementation:
- Use a separate agent instance (different `subagent_type` or `name`) for review
- The reviewer receives only the output + acceptance criteria, not the generation prompt
- Reviewer can request changes but never edits directly -- sends feedback to the author

## Pattern 1: Generate -> Validate -> Fix

The most common autonomous loop. Generate output, validate against criteria, fix if needed.

```
+----------+     +----------+     +----------+
| Generate |---->| Validate |---->|   Fix    |--+
|          |     |          |     |          |  |
+----------+     +----+-----+     +----------+  |
                      | Pass                     |
                      v                          |
                 +----------+                    |
                 |  Accept  |<-------------------+
                 +----------+     (max 3 iterations)
```

**When to use:** Code generation, document creation, configuration authoring

```python
MAX_ITERATIONS = 3

for iteration in range(MAX_ITERATIONS):
    if iteration == 0:
        output = generate(prompt, context)
    else:
        output = fix(output, validation_errors, context)

    is_valid, errors = validate(output, acceptance_criteria)

    if is_valid:
        return accept(output)

return escalate_to_human(output, errors)
```

**Guard rails:**
- Hard cap on iterations (3 is typical, never exceed 5)
- Each iteration must reduce error count -- if errors increase, break
- Track token cost per iteration -- escalate if cost exceeds threshold

## Pattern 2: Explore -> Hypothesize -> Test

For debugging and investigation. Gather evidence, form theory, validate.

```
+----------+     +-------------+     +----------+
| Explore  |---->| Hypothesize |---->|   Test   |--+
| (gather  |     | (form       |     | (verify  |  |
|  evidence)|    |  theory)    |     |  theory) |  |
+----------+     +-------------+     +----+-----+  |
                                          | Fail   |
                                          v        |
                                     +----------+  |
                                     | Refine   |--+
                                     | hypothesis|
                                     +----------+
```

**When to use:** Bug investigation, root cause analysis, codebase exploration

**Guard rails:**
- Track hypotheses tested to avoid circular reasoning
- Max 5 hypotheses before requesting human input
- Evidence must be concrete (file:line references, error messages)

## Pattern 3: Plan -> Execute -> Verify -> Adjust

For multi-step implementation tasks.

```
+----------+     +----------+     +----------+     +----------+
|   Plan   |---->| Execute  |---->|  Verify  |---->|  Adjust  |--+
| (steps)  |     | (step N) |     | (tests)  |     | (plan)   |  |
+----------+     +----------+     +----------+     +----------+  |
     ^                                                            |
     +------------------------------------------------------------+
```

**When to use:** Feature implementation, refactoring, migration tasks

**Guard rails:**
- Plan must be approved before execution starts
- Verify after EACH step, not just at the end
- Adjustment can only modify future steps, never rewrite completed ones
- If >50% of plan needs adjustment, re-plan from scratch

## Pattern 4: Diverge -> Converge -> Select

For creative or design tasks where multiple approaches are valid.

```
+------------+     +------------+     +----------+
|  Diverge   |---->|  Converge  |---->|  Select  |
| (generate  |     | (evaluate  |     | (pick    |
|  N options)|     |  trade-offs)|    |  best)   |
+------------+     +------------+     +----------+
```

**When to use:** Architecture decisions, API design, UI alternatives

**Guard rails:**
- Generate minimum 3 options (avoids false dichotomies)
- Evaluation criteria defined BEFORE divergence (prevents bias)
- Selection must reference criteria -- no "gut feeling"

## Pattern 5: Seed -> Expand -> Prune

For building up content or code incrementally.

```
+----------+     +----------+     +----------+
|   Seed   |---->|  Expand  |---->|  Prune   |--+
| (minimal |     | (add     |     | (remove  |  |
|  version)|     |  features)|    |  bloat)  |  |
+----------+     +----------+     +----------+  |
                      ^                          |
                      +--------------------------+
                      (until scope complete)
```

**When to use:** MVP development, documentation, test suite building

**Guard rails:**
- Seed must be complete and working before expansion
- Each expansion adds ONE feature/section
- Prune after every 3 expansions
- Prune agent is separate from expand agent (reviewer-never-authored)

## Pattern 6: Observe -> Orient -> Decide -> Act (OODA)

For reactive, event-driven agent workflows.

```
+----------+     +----------+     +----------+     +----------+
| Observe  |---->|  Orient  |---->|  Decide  |---->|   Act    |
| (monitor |     | (analyze |     | (choose  |     | (execute |
|  events) |     |  context)|     |  action) |     |  action) |
+----------+     +----------+     +----------+     +----------+
     ^                                                    |
     +----------------------------------------------------+
```

**When to use:** Monitoring, incident response, CI/CD automation

**Guard rails:**
- Observation must be fresh (re-check state before acting)
- Orientation must include context from previous loops
- Decision must be logged for audit trail
- Action must be reversible or confirmed

## Applying Patterns

### Choosing the Right Pattern

| Task Type | Recommended Pattern |
|-----------|-------------------|
| Code generation / editing | Generate -> Validate -> Fix |
| Bug investigation | Explore -> Hypothesize -> Test |
| Feature implementation | Plan -> Execute -> Verify -> Adjust |
| Architecture / design | Diverge -> Converge -> Select |
| Incremental building | Seed -> Expand -> Prune |
| Monitoring / ops | OODA |

### Combining Patterns

Patterns can be nested. For example:
- **Plan -> Execute** where each Execute step uses **Generate -> Validate -> Fix**
- **Diverge -> Converge** where each option is built with **Seed -> Expand -> Prune**
- **OODA** where the Act phase uses **Plan -> Execute -> Verify -> Adjust**

### Universal Guard Rails

Apply these to ALL patterns:

1. **Max iterations**: Every loop has a hard cap (typically 3-5)
2. **Cost tracking**: Monitor token spend per iteration
3. **Progress check**: Each iteration must demonstrably advance toward the goal
4. **Escalation path**: Clear handoff to human when loop exhausts iterations
5. **Audit trail**: Log each iteration's input, output, and decision

Related Skills

workflow

8
from stevengonsalvez/agents-in-a-box

Guide through structured delivery workflow with plan, implement, validate phases

webapp-testing

8
from stevengonsalvez/agents-in-a-box

Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.

validate

8
from stevengonsalvez/agents-in-a-box

Verify implementation against specifications

ui-ux-pro-max

8
from stevengonsalvez/agents-in-a-box

UI/UX design intelligence. 67 styles, 96 palettes, 57 font pairings, 25 charts, 13 stacks (React, Next.js, Vue, Svelte, Astro, Nuxt, SwiftUI, React Native, Flutter, Tailwind, shadcn/ui, Jetpack Compose). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient.

tui-style-guide

8
from stevengonsalvez/agents-in-a-box

TUI style guide for consistent terminal interface design

token-usage

8
from stevengonsalvez/agents-in-a-box

Show Claude Code token usage across sessions — daily, weekly, per-project, and per-session breakdowns. Parses {{HOME_TOOL_DIR}}/projects/**/*.jsonl for consumption data. Use when the user asks about token usage, costs, how many tokens were used, session statistics, or wants a usage report.

tmux-status

8
from stevengonsalvez/agents-in-a-box

Show status of all tmux sessions including dev environments, spawned agents, and running processes

tmux-monitor

8
from stevengonsalvez/agents-in-a-box

Monitor and report status of all tmux sessions including dev environments, spawned agents, and running processes. Uses tmuxwatch for enhanced visibility.

tmux-message

8
from stevengonsalvez/agents-in-a-box

Reliable peer-to-peer message delivery to other Claude Code instances via tmux send-keys. Use as a fallback when claude-peers MCP send_message fails to surface in the receiver's inbox (delivered server-side but receiver never picks it up — observed behaviour). Also use when sending a directive to a known Claude Code TUI session by tmux session name or fuzzy hint, or when injecting a multi-line directive into a peer's prompt and submitting it. Trigger phrases — "claude-peers fallback", "tmux send-keys", "send to peer via tmux", "inject directive", "deliver to nanoclaw/hermes peer", "peer message". Tmux-only — won't reach peers running outside tmux.

test-driven-development

8
from stevengonsalvez/agents-in-a-box

Use when implementing any feature or bugfix, before writing implementation code. Enforces RED-GREEN-REFACTOR cycle with test-first approach.

test-ainb

8
from stevengonsalvez/agents-in-a-box

Run tests for the ainb (agents-in-a-box) Rust workspace via a 5-layer strategy — unit, insta snapshot, mock-plugin compositing, real-plugin spawn, vhs recording. Wraps cargo + insta + vhs into one CLI. Use when Stevie says "/test-ainb", "test ainb", "run ainb tests", "snapshot <component>", "regenerate vhs tapes", or any phrasing about validating ainb test layers. The skill autodetects which ainb-tui worktree the cwd sits in and dispatches to scripts/run.sh.

sync-learnings

8
from stevengonsalvez/agents-in-a-box

Sync user-level agent config changes back to toolkit repository (works for Claude, Codex, Copilot)