Loop patterns

The named shapes of loop engineering — the design patterns every loop is an instance of, independent of use case.

Ralph

levels 1, 2

The hello-world of loops: feed the agent one prompt file, over and over, until it's done.

while not done: run(prompt_file)

Use when. A single, well-specified body of work that just needs many passes (build this, port this, exhaust this checklist).

Watch out. No built-in verification or memory — bolt those on or it loops forever / repeats itself.

Maintenance

levels 3

A standing loop that continues unfinished work, tends the open PR, and runs cleanup when idle.

each tick: finish-in-progress -> tend-PR -> cleanup-if-quiet

Use when. Keeping a branch or repo healthy without micromanaging it.

Watch out. Scope creep — bound it to not start new initiatives or take irreversible action unprompted.

Babysitter

levels 1, 2

Watch one thing and react: CI red -> fix, new comment -> address, green and quiet -> report.

watch(target): on-change -> respond; on-stable -> report-once

Use when. A single live target you'd otherwise refresh manually (a deploy, a PR, a long build).

Watch out. Polling too fast wastes tokens; prefer self-pacing or event push when available.

Triage fan-out

levels 4

Discover many items, isolate each in its own worktree, draft a fix, then have a SECOND agent review it.

discover[] -> per item: worktree -> fix(sub-agent) -> review(other sub-agent) -> open PR; rest -> inbox

Use when. Recurring batch of independent items (CI failures, issues, vuln bumps) you want drafted overnight.

Watch out. The reviewer must be a separate agent — self-grading is the most common silent failure.

Orchestrated

levels 5

Chain multiple loops/sub-agents into a reactive system where one loop's output feeds the next.

loopA -> events -> loopB -> events -> ...

Use when. Standing systems (a self-driving backlog) rather than a single recurring task.

Watch out. Hardest to keep comprehensible; comprehension debt accrues fastest here.