Ralph loop (Ralph Wiggum technique)
Running the same prompt against a coding agent again and again, each time with a fresh context, while progress lives in files and tests decide when it is done.
A Ralph loop runs the same prompt against a coding agent again and again, each time with a fresh context. Progress lives in files (plan, todo list, notes), and tests or an audit decide when the work is done. Geoffrey Huntley named the technique after the Simpsons character who keeps going whatever happens.
At its simplest it is a shell loop that pipes one prompt file into the agent. Each run starts with an empty context, reads the plan, todo and notes files, does one piece of work and writes its progress back, so it avoids context rot in long sessions. What makes it converge is the verifier: tests, a linter or an audit that fails until the work is right. Without one, the loop keeps producing code and nobody knows when it is finished. Every run costs tokens, so a spending limit belongs in the loop from the start.
The wider practice of designing such loops, instead of prompting agents by hand, is sometimes called loop engineering. It sits at the opposite end from an agent graph: less design up front, less control over each step. Compared with the evaluator-optimizer pattern, the critic is a test suite instead of a second model. It is one of the building blocks of a software factory.
Sources
Related terms
- Agentic loop: The cycle of model call, tool call and result that an agent repeats until it stops.
- Context rot: Model quality drops as the context fills with old, irrelevant or conflicting material.
- Hooks: Scripts the harness runs automatically at fixed points, such as before a tool call or after an edit.
- Audit-driven development: A loop for code you maintain: an AI agent audits it against a checklist, the findings become small fixes, and it audits again until nothing is left.
- Software factory (AI agents): A pipeline where agents write and fix most of the code while people write specs, set guardrails, design the checks and decide what ships.
- Evaluator-optimizer (maker-checker): One model drafts, another checks the draft against stated criteria and returns feedback, in a loop until it passes or a round limit stops it.
- Agent graph (state graph): Modeling an agent as explicit nodes, edges and shared state, with checkpoints, so each step can be paused, resumed, inspected and tested.
- Validation loop (agent backpressure): Commands a coding agent runs after every change (tests, types, lint, build) and fixes against until they pass, so it checks itself before a person looks.
- Research, plan, implement (RPI): Working with a coding agent in three phases, each in a fresh context: research the code into a document, write a plan from it, then implement the plan.
