Part 2 · Strategy

Loop Engineering · ~8 min

Loop Strategy & Autonomy

Two dials decide a loop's character: how much context it carries between iterations, and how much rope you hand it. Set both on purpose, not by habit.

Why this, for you: your long-running agent degraded after a few dozen iterations — missing fixes, repeating itself, drifting off the objective. That is almost never a model problem. It is a strategy problem: you reached for accumulated context when the workload wanted a fresh slate, or you let it run wide open when it needed a budget cap.

Last lesson you learned to name which loop you are in. This one is about the two choices that shape it: the context strategy (what carries forward) and the autonomy level (how the loop knows when to stop). Get these wrong and even a perfect inner loop rots.

1 The context spectrum: accumulated, compressed, fresh

There are three ways a loop can carry context between iterations, and the right one depends on the workload — not on what your harness happens to default to.

StrategyBest forPrimary risk
Accumulated contextSynthesis, cross-referencing, discoveryContext rot degrades reasoning
Within-session compressionMedium-horizon mixed tasksLossy compression, objective drift
Fresh context per iterationExecution-heavy, unattended workFragmented research coherence
The split tracks synthesis vs execution. Synthesis needs to cross-reference findings and spot patterns, so it wants accumulated context. Execution is a stream of bounded units, so it wants a fresh slate each time. Choose by workload, not by habit.

The reason fresh context is not just "starting over" is context rot: reasoning quality degrades as the window fills. Anthropic calls this a "performance gradient" that appears "across all models," and BABILong benchmarks show reasoning tasks retain only 10–20% effective context at high fill. Karpathy's autoresearch agent — an accumulated-context loop running ~12 experiments per hour — began producing spurious correlations that needed manual correction as its sessions lengthened. That is context rot in the wild.

These compose; they don't compete

The strongest real systems are hybrid. Research then implement: accumulate context while exploring, write findings to durable artifacts, then spin up fresh-context sessions per implementation task. Anthropic's multi-agent research system does exactly this — accumulated context at the orchestrator level, fresh context at each worker.

2 The Ralph loop: fresh context as a discipline

The fresh-context extreme has a name: the Ralph Wiggum Loop, named and popularized by Geoff Huntley. Each iteration opens a clean window, reads persistent state from disk, completes one bounded unit of work, writes results back, and restarts. State lives in files — task lists, specs, AGENTS.md, progress markers — never in conversation history.

It works because quality degrades non-linearly past roughly 60–70% context fill — the "dumb zone" — where compaction starts discarding tokens. Restarting with a fresh window prevents compaction entirely, so every iteration runs at full capacity.

Two properties fall out for free. Natural recovery: a failed iteration leaves disk state at the last successful write, so the next cycle continues cleanly without inheriting the failed session's misconceptions. Unattended operation: a wrapper script restarts the agent each cycle and a human reviews from time to time rather than supervising continuously.

# loop-runner.sh — fresh context each cycle, state on disk while [[ $CYCLE -lt $MAX_CYCLES ]]; do remaining=$(grep -c "^- \[ \]" tasks.md) [ "$remaining" -eq 0 ] && echo "Done." && exit 0 claude --no-cache --prompt "Read tasks.md. Do the next unchecked task. Mark it done. Write output. Stop." CYCLE=$((CYCLE + 1)) done

Ralph is brute force — and it has teeth

The cheapness is real but bounded. A fifty-iteration loop on a medium codebase typically runs $50–$100+ in API credits, architectural coherence suffers (the code reflects the path to a working state, not intentional structure), and an agent facing an impossible task can overbake — iterate destructively for hours. An iteration cap alone is a financial circuit breaker, not a quality gate. Every loop still needs a non-convergence detector (Lesson 4).

3 Autonomy is a spectrum — and stop conditions define it

Ralph is one autonomy extreme: cheap, external, brute-force. The other end keeps a single accumulating session but steers it. The goal-driven autonomous loop — shipped in OpenAI's Codex CLI and Anthropic's Claude Managed Agents — injects a continuation prompt at each turn end that re-states the objective, reports remaining budget, and demands a completion audit before the agent may declare done.

PatternContext modelStop condition
Ralph Wiggum loopFresh per cycle, state on diskExternal: empty task list or iteration cap
Goal-driven loopSingle session, accumulatingGoal-complete tool call OR token budget
The load-bearing element of a goal-driven loop is the completion audit: proxy signals like "tests pass" or "I made progress" do not certify completion unless they map every requirement to concrete evidence. Anthropic reports outcomes-style grading "improved task success by up to 10 points over a standard prompting loop."

The sharpest autonomy gotcha lives here: who audits? When the worker is also its own auditor — Codex's design — long transcripts produce false-positive completion, the documented LLM-as-judge self-enhancement bias. Anthropic runs the grader in a separate context window "to avoid being influenced by the main agent's implementation choices." A separate-context grader is a structural defense the same-session self-audit cannot match.

Vague objectives defeat every autonomy level

No continuation prompt rescues an objective with no testable success criteria — it just burns budget without converging. And the budget cap that fires at the end is deterministic, not diagnostic: 200K stops at 200K whether the artifact is done or half-done. Pair the cap with the convergence detection you'll build in Lesson 4.

↪ Your win: pick context and autonomy on purpose

Retrieval practice — recall, don't peek

Question 1Accumulated context is the right strategy when the workload is mainly…

Question 2The Ralph Wiggum loop avoids the "dumb zone" by…

Question 3An iteration or budget cap is best described as a…

Question 4The structural defense against a worker rationalizing "done" is…

Question 5 · spaced recall from an earlier lessonBefore debugging a misbehaving loop, the first move is to…

Ask me anything. Want help deciding whether a real workload of yours is synthesis- or execution-heavy, or how to wire a separate-context grader into a goal-driven loop? Next in Part 3: Loop Structure & Orchestration — giving the loop a structured body instead of an ad-hoc while-true.
✎ Feedback