Ralph Loop
For long tasks: the agent wakes up, reads the state, makes some progress, saves, and starts over.

In one sentence
Pattern for long tasks: run the agent in a continuous loop on the same large task, resetting the context at each iteration while preserving progress in files. The agent wakes up, reads the state, makes some progress, saves, and the loop starts over.
Before
Task too large for a single session
What it does
Wakes up, reads the state, progresses, saves
After
Progress preserved in a file
Example
Migrating twelve years of correspondence to the new format is too large for a single session. The agent wakes up, reads the progress file (stopped at batch 34), converts twenty records, notes what it did, and exits.
In the next iteration, the context is new and the progress is the same. The work moves forward without depending on a giant session, which would not exist anyway.
In practice
- The progress file is the contract: what has already been done, what remains, where it stopped.
- Each iteration needs to make verifiable progress. An iteration that does not change the file is an infinite loop.
- Set an iteration cap and an alert. Without a limit, the ralph loop keeps spending without anyone noticing.
How to make it tangible
A progress file that the agent reads at the start and writes at the end, plus a loop that restarts it.
Translated from Portuguese with AI assistance.
