---
name: ai-loop-library
description: Use when the user wants repeated agent work done without thrashing — "keep fixing until tests pass", "stop when it's actually done", "run this as a loop", or any recurring job (CI, source QA, pre-publish checks, inbox triage) that needs verification, a stop condition, and a budget instead of open-ended autonomy. Picks a bounded, verifiable work loop from ailooplibrary.com and runs it with one change per round, the same verification every round, durable state files, and human approval gates.
---

# AI Loop Library: run bounded, verifiable work loops

A loop is not "keep going until it feels done." A useful loop names seven things before it
starts: **trigger, goal, one bounded change per round, the same verification every round,
durable state, a stop condition, and a budget** — plus a human approval boundary.
This skill picks the right loop from the AI Loop Library (63+ patterns) and runs it that way.

## Getting a loop

**Preferred — MCP tools** (if the `ai-loop-library` MCP server is connected):

1. `pick_loop_for_goal(goal)` — best loop with why-this / why-not alternatives
2. `render_run_protocol(id_or_slug, goal)` — executable protocol with state-file skeleton
3. `search_loops` / `get_loop` / `list_categories` / `catalog_stats` to browse

**Fallback — no MCP needed:**

```bash
curl -fsSL https://ailooplibrary.com/catalog.json
```

Each entry has `id`, `category`, `trigger`, `objective`, `allowed_actions`, `verification`,
`stop_condition`, `budget`, `approval_boundary`, and `url` (the canonical spec page).
Pick by matching the user's goal against category, objective, and use-when text; prefer
loops whose verification you can actually run in this environment.

## Run protocol (always the same shape)

1. **Classify the goal.** What repeats? What evidence proves a round worked? If nothing can
   verify it, say so — this library is not for open-ended vibe work.
2. **Pick the loop** (MCP or catalog match). Tell the user which loop and why, in one line.
3. **Write state first.** Create `docs/loops/<id>/progress.md` and `docs/loops/<id>/state.json`
   (goal, round 0, verification check, budget: 8 rounds / 45 min / 3 consecutive failed
   verifications unless the user set one).
4. **One change per round.** One coherent, bounded move. No batching, no scope creep —
   new work is a new loop, not round 9 of this one.
5. **Same verification every round.** Run the loop's verification check; record the result
   and evidence (command output, diff, screenshot path) in progress.md before continuing.
6. **Stop** on: verifier pass · budget exhausted · same failure after two different fixes ·
   blocker · anything crossing the approval boundary.
7. **Proof, not vibes.** Final report: rounds used, one-line change per round, final
   verification output, remaining risk, the single next human decision.

## Risk colors (approval boundary)

- **Green — proceed:** local edits, drafts, analysis, sandboxed tests.
- **Yellow — pause and show the human:** public-facing drafts, PRs to shared branches,
  config/schema changes.
- **Red — never without explicit approval:** money, production, outbound messages,
  deletion, account changes, legal or reputational commitments.

## Example invocations

- **Coding:** "Speed up CI" → `pick_loop_for_goal("speed up CI")` → CI Optimization loop →
  rounds of one pipeline change each, verified by wall-clock CI time, stop at target or budget.
- **Ops:** "Production errors keep piling up" → Production Error Sweep → one error class per
  round, verified by error-rate delta, red-gated on any prod config change.
- **Content:** "Fact-check this draft before it ships" → Pre-Publish Source Check → one claim
  per round, verified against the source table, publish stays human-gated.

Library: https://ailooplibrary.com/library/ · Agent pack: https://ailooplibrary.com/for-agents/
