Skip to content

Pattern taxonomy

Loops do not differ meaningfully by which model or tool runs them. They differ along four axes that actually change behavior, cost, and trustworthiness. Classify any loop by picking one value per axis; the named patterns further down are recurring combinations of these axis values.


Axis A — Termination (when does it stop?)

Section titled “Axis A — Termination (when does it stop?)”
ValueStop conditionExampleRisk it introduces
Time-recurringFires on a schedule; never “finishes”morning triage run, scheduled automationsDoes work nobody asked for; cost drift
Goal-metRuns until a verifiable predicate is trueevaluator-optimizer, “tests pass and lint clean”Non-convergence if the predicate is unreachable
Fixed-pipelineA predetermined sequence of steps, then doneprompt chaining, spec → plan → tasks → implementRigid; cannot adapt to unforeseen subtasks
Budget-exhaustedCaps rounds, tokens, or wall-clock, then yields--rounds N, --max-fix-roundsShips partial work or stalls; needs a fail-safe

Mature loops use goal-met with a budget fail-safe: run until the goal is met, but never past N rounds. Pure time-recurring loops are the newest and most cost-dangerous class, because they run on infrastructure time, not your attention, which is the whole point and the whole hazard.

Axis B — Verification diversity (how good is the check?)

Section titled “Axis B — Verification diversity (how good is the check?)”

This is the axis that actually separates a trustworthy loop from a plausible-looking one. Ordered weakest to strongest:

  1. Self-check — the same model, same context, grades its own output. Cheapest, weakest. Prone to sycophantic self-review: the model that wrote the work is too nice grading its own homework.
  2. Fresh-context, same model — a new instance of the same model, with no memory of the generation, re-judges from scratch. Removes conversational sycophancy; still shares the model’s blind spots.
  3. Cross-model adversarial — a different model family reviews. Catches failures correlated within one model’s training. This is the core reason AIOS keeps model diversity in the loop.
  4. Deterministic evals / tests / types — non-LLM ground truth: unit tests, typecheck, linters, secret scanners. Cannot be sweet-talked. The “back pressure” that makes coding the killer domain for agents.
  5. Layered — several of the above stacked with a human gate. Strongest, most expensive. Where aios ship lives.

Axis C — Control flow (who decides the next step?)

Section titled “Axis C — Control flow (who decides the next step?)”
ValueWho drivesAnthropic’s termWhen it wins
Scripted orchestrationFixed code paths call the modelWorkflowTask decomposes cleanly; you want predictability, auditability, lower cost
Model-drivenThe model chooses its own next action in a loopAgentOpen-ended tasks where you cannot predict the steps or the number of iterations

Anthropic’s central prescriptive point: start with workflows; reach for agent autonomy only when the task genuinely cannot be hardcoded. Most production value is simpler than people build. Real systems mix the two: a scripted outer loop (gates, sequencing) around model-driven inner work.

Axis D — State across iterations (what persists between turns?)

Section titled “Axis D — State across iterations (what persists between turns?)”
ValueWhere memory livesConsequence
Fresh context each turnNothing carries in-context; each turn starts coldCheap, avoids context rot, forces externalized state. The agent forgets; the repo does not.
Accumulated conversationFull history threaded through each callRich context; degrades as the window fills, costs more, eventually compacts
Externalized stateFiles, git history, a plan or TODO file, a board, a logDurable across crashes and sessions; the spine of every long-running loop

The strongest long-running loops keep per-turn context small and push durable state to disk so a fresh-context turn can still make correct forward progress. Externalized state is what makes a loop resumable and schedulable.


Each is a recurring point in the four-axis space. For each: what it is, when to use it, and how it fails.

One call generates, a second call evaluates against criteria and feeds back, in a loop. Goal-met termination, a separate-model verifier, a scripted two-role loop.

2. Reflection loop (Reflexion / self-refine family)

Section titled “2. Reflection loop (Reflexion / self-refine family)”

The agent reflects on a failure signal, writes the reflection to memory, and retries with that reflection in context. Budget or goal termination, model-driven, an accumulated reflection buffer.

3. Ralph loop (while-loop agent / fresh-context autonomy)

Section titled “3. Ralph loop (while-loop agent / fresh-context autonomy)”

The same prompt, fresh context every turn, one item per loop, progress accumulating in files and git rather than in the context window. Deterministic back-pressure (tests, types, compiler) is the verifier.

Generate, grade against an explicit written rubric, revise, bounded by a budget; the rubric, not vibes, is the pass bar.

Run the task or the judgment several times and aggregate: majority vote, multiple review prompts, or multi-agent debate. Parallel diversity is the verifier.

6. Loop-until-dry (queue / worklist drain)

Section titled “6. Loop-until-dry (queue / worklist drain)”

A loop pulls the next item from an externalized worklist, actions it, marks it done, and repeats until the list is empty.

The loop does everything in a shadow copy, and a separate, explicit gate promotes output to a shared or production surface only on approval.

8. Plan-build-review pipeline (spec-driven loop)

Section titled “8. Plan-build-review pipeline (spec-driven loop)”

A fixed outer sequence — spec → plan (reviewed) → build (reviewed) → merge (gated) — each stage a sub-loop with its own verifier.


Cross-cutting failure modes to design against

Section titled “Cross-cutting failure modes to design against”

These recur in every pattern above:

  • Reward-hacking the evaluator — the optimizer satisfies the measurable proxy, not the goal (placeholder code that compiles, text that pleases the critic). Mitigation: make the check deterministic and hard to game, and diversify the verifier.
  • Sycophantic / self-review collapse — author and grader share a model and context and agree too easily. Mitigation: fresh context, then a different model, then a non-LLM check.
  • Non-convergence — the loop never reaches its stop condition. Mitigation: always pair goal-met with a budget fail-safe; on budget exhaustion, stop and hand to a human rather than force-ship.
  • Cost blowup — unattended and time-recurring loops and juror panels burn tokens fast. Mitigation: budgets, cheap-model stop-checkers, one item per loop.
  • Comprehension / intent debt — the faster the loop ships work you did not write, the wider the gap between what exists and what you understand. Mitigation: read the output; keep the human as reviewer, not just the person who presses go.