Loop Pattern Library
Twenty operational patterns turn the Loop Contract into repeatable ways of working. Choose a pattern because recurring jobs fail in different ways: a PR can wait on checks, a rollout can breach a threshold, and a security review can cross an approval boundary. Each needs its own trigger, permissions, evidence gate, state, budget, and human handoff even when the underlying agent is the same.
Use a loop when the work returns, an external signal can verify progress, useful state should survive between runs, and action can be bounded. Prefer one supervised agent run when the task is one-off, completion is mainly subjective, or a safe permission boundary cannot be stated.
Use The Library In Three Steps
- Start from the recurring symptom and verified outcome in the coverage map below.
- Open the pattern to review its trigger, external gate, state, failure boundaries, and worked example.
- Adapt its linked JSON contract to your permissions and budgets, then choose a runtime starter.
The layers have different jobs:
| Layer | Question it answers | Artifact |
|---|---|---|
| Pattern | How should this class of recurring work operate? | Human-readable operating playbook |
| Contract | What exactly may this loop read, change, verify, spend, and escalate? | Schema-valid JSON in examples/ |
| Runtime starter | Where and how does the contract execute? | Copy/paste and executable starters in examples/runnable/ |
Coverage Map
Build And Maintain
| Symptom | Pattern | Verified outcome |
|---|---|---|
| A pull request is stalled | PR babysitter | Required checks pass, review threads are resolved, and merge state is current |
| CI keeps failing | CI repair loop | The original failing command passes with a scoped patch |
| Documentation may be stale | Docs drift collector | Verified code/docs mismatches are patched and examples still run |
| Dependency updates pile up | Dependency triage loop | Safe updates pass tests and risky upgrades have an owner-backed escalation |
| Bugs need systematic discovery | Bug hunting loop | Each accepted finding has reproducible steps or a failing test |
| Release notes are incomplete | Release-note loop | Every shipped change maps to a merged source and audience-facing note |
Operate And Observe
| Symptom | Pattern | Verified outcome |
|---|---|---|
| A rollout needs watching | Deploy verifier | Synthetic checks and rollout thresholds remain within policy |
| An incident just paged | Incident response loop | Impact, evidence, timeline, and accountable owner are recorded |
| A dataset keeps drifting | Data-quality loop | Hard quality rules pass before a new version is promoted |
| Agent spend is rising | Cost-control loop | Spend falls on a comparable workload without quality regression |
| Model choice is ad hoc | Model-routing loop | Routing decisions meet quality, latency, privacy, and cost tolerances |
| Latency, throughput, or memory regressed | Performance regression loop | A controlled benchmark confirms recovery with correctness intact |
Learn And Optimize
| Symptom | Pattern | Verified outcome |
|---|---|---|
| Feedback is noisy and unsorted | Feedback clusterer | Themes cite source items and separate frequency from severity |
| Agent evaluations regressed | Evaluation regression loop | Targeted evals return to the accepted baseline without scorer changes |
| A system should improve against a metric | Benchmark optimization loop | Repeated measurements confirm an improvement with protected metrics intact |
| An agent's knowledge is stale | Knowledge freshness loop | A versioned corpus passes provenance, freshness, retrieval, and leakage gates |
Govern And Protect
| Symptom | Pattern | Verified outcome |
|---|---|---|
| A sensitive change needs review | Security review loop | Findings cite concrete evidence and approval boundaries stay intact |
| A change needs formal sign-off | Enterprise approval loop | Every required gate has a recorded decision and audit trail |
| A UI introduced an accessibility failure | Accessibility regression loop | The exact regression is fixed and required human criteria are approved |
| An agent system needs adversarial testing | Adversarial red-team loop | Confirmed findings are reproduced, minimized, privately reported, and regression-tested |
Choosing Between Similar Patterns
| If the work sounds like... | Choose | Not |
|---|---|---|
| "A known code change may be unsafe" | Security review | Adversarial red team, which actively discovers behavior failures |
| "Find new failures in a sandboxed agent" | Adversarial red team | Bug hunting, which is broader and not threat-model driven |
| "Our eval score dropped" | Evaluation regression | Benchmark optimization, which seeks new improvement from a stable baseline |
| "Make this system measurably better" | Benchmark optimization | Performance regression, unless the target is specifically latency, throughput, memory, or cost |
| "Our repo docs no longer match code" | Docs drift | Knowledge freshness, which maintains a multi-source retrieval corpus |
| "The retrieval corpus is stale" | Knowledge freshness | Data quality, unless the artifact is a general dataset rather than an agent knowledge index |
| "A scanner found an accessibility issue" | Accessibility regression | General CI repair, because automated checks do not cover all human accessibility criteria |
Compare trigger, state, gate, budget, escalation, and runtime across every pattern in the full matrix.
Pattern Quality Bar
A pattern qualifies for this library only when it:
- solves a recurring job that is materially distinct from an existing pattern;
- has an external feedback signal stronger than the acting model's opinion;
- names durable state, a hard budget, and a human handoff;
- states what the loop must not do;
- includes a worked scenario and a schema-valid contract;
- can map to at least one practical runtime without assuming unlimited permissions.
Reject patterns whose only gate is "the agent says it looks good." Prefer exit codes, score distributions, changed files, source manifests, trace IDs, dashboard thresholds, screenshots, or named reviewer decisions.