When you ask an AI to build a large software project, you run into a fundamental limit: The Context Window. As the conversation grows, the model has to process more history. Eventually, it hits a limit and forces a "Compaction" (summarization).
Click to add code iterations. Watch what happens when the memory overflows.
The Ralph Loop solves this by treating the AI as ephemeral (temporary) and the File System as the permanent memory. Instead of one long chat, we run a Bash loop that spawns a new AI agent for every single task.
while [ task != "DONE" ]; do
cat prompt.md | ai_agent
done
Hover over the boxes to see their roles.
Let's step through the mechanism. Notice that the "Agent" is destroyed after every step, but the project moves forward.
This isn't magic; it's a script. You can tune the loop variables.
# loop_config.sh
MAX_ITERATIONS = 10
STOP_CONDITION = "promise-COMPLETE"
CONTEXT_SOURCE = "prompt.md + progress.txt"
Standard setting. The agent has 10 attempts to finish the feature.
Why do we loop serially instead of spawning 10 agents at once? Because without shared memory synchronization, they step on each other's toes.
Click to see what happens when two agents edit the same file.