Skip to main content
blog.philz.dev

Ralph and Lisa

We know the Ralph Wiggum loop:

# Ralph
echo "TASK" > PROMPT.md
while true; do
  claude -p "$(cat PROMPT.md)"
done

The Ralph loop is about context management; doing things one "turn" at a time can be more effective and cheaper than doing many turns (see "Expensively Quadratic").

Let me introduce you to the Lisa loop:

PROMPT1.md:

Write a script x.sh that does this or that. If it fails, be sure to exit non-zero, and another agent will fix it.

PROMPT2.md:

Script x.sh failed (with last output out.txt). It was intending to do what was described in PROMPT1.md. Fix it in place. When your agent loop finishes, it will execute again, and the agent will be re-invoked if there are errors. Use AGENT-NOTES.md to leave notes for future iterations.

# Lisa
claude -p "$(cat PROMPT1.md)"
while true; do
  if ! ./x.sh > out.txt; then
    claude -p "$(cat PROMPT2.md)"
  fi
  sleep 60
done

Lisa is self-sufficient. Lisa is self-healing. Lisa is smart.