Topic 8 of 9 · Level 4: Durable systems
Loop Engineering
For automation with agents, the most reliable way to reach a consistent result is to use loops: force an agent to repeat work until it meets defined pass criteria. There is no settled best framework yet; this note covers the basic ingredients, while Ralph loop is the best-known project that popularised the approach.
Three ingredients
To run a loop, give the model three things:
- An objective. This can be any outcome. For the example below, the objective is an essay about animals.
- A measurable completion checklist. The checklist says exactly when the objective is complete. For the animal essay: 5,000 words, no aquatic animals, and no grammatical errors.
- An external state mechanism. The model writes its progress after each loop. Common practice is for each run to begin without memory of the prior run, so state is the record of what has already happened.
A four-loop example
Loop 1
Write a general animal essay without worrying about word count, animal mentions, or proofreading; record “baseline essay written to animals.txt”.
Loop 2
Read the state and
animals.txt, expand the essay from 2,310 to 5,000 words, and record the word-count adjustment.Loop 3
Check that no aquatic animals are mentioned and mark that checklist item confirmed.
Loop 4
Check grammar and mark the grammar checklist item confirmed.
A starting point, not a finished framework
These are the basic ingredients of a loop. Ralph loop is considerably more refined than this explanation, but the objective, checklist, and durable state are the useful foundations.