What is Ralph?
Ralph is an autonomous AI agent loop pattern that emphasizes “naive persistence” - the agent keeps trying until it succeeds. Named after the character Ralph Wiggum from The Simpsons, it embodies a simple but effective philosophy: clear the context, read the state from files, make progress, and repeat. Key Principles:- Fresh Context: Each iteration starts with a clean LLM context window
- File-Based State: Progress persists through files and Git history, not chat memory
- Completion Promises: Agent signals task completion via explicit markers
- Doom Loop Detection: Prevents repetitive, non-productive cycles
Quick Start
With Completion Promise
<promise>DONE</promise> in its response when complete.How It Works
| Phase | Description |
|---|---|
| Initialize | Agent receives task with autonomy configuration |
| Execute | Agent works on task, writes state to files |
| Check | System checks for completion promise in output |
| Reset | If not done, context clears and loop restarts |
| Complete | Promise detected or max iterations reached |
Configuration Options
CLI Options
| Option | Short | Type | Default | Description |
|---|---|---|---|---|
--max-iterations | -n | int | 10 | Maximum loop iterations |
--completion-promise | -p | str | None | Text that signals completion |
--clear-context | -c | bool | False | Clear chat history between iterations |
--timeout | -t | float | None | Timeout in seconds |
--model | -m | str | None | LLM model to use |
--verbose | -v | bool | False | Show detailed output |
Programmatic Options
| Option | Type | Default | Description |
|---|---|---|---|
max_iterations | int | 10 | Maximum autonomous iterations |
completion_promise | str | None | Promise text for completion detection |
clear_context | bool | False | Reset context each iteration |
timeout_seconds | float | None | Overall timeout limit |
Completion Detection
The agent signals completion by including a promise marker in its output:- Promise matched: Output contains
<promise>{TEXT}</promise>matching the configured promise - Max iterations: Reached the iteration limit
- Timeout: Exceeded the time limit
- Doom loop: Detected repetitive non-productive actions
- User interrupt: Ctrl+C cancellation
Common Patterns
Long-Running Development Tasks
Debugging Sessions
Refactoring Tasks
Best Practices
Use file-based state for complex tasks
Use file-based state for complex tasks
When
--clear-context is enabled, ensure your agent writes progress to files (like progress.txt or a task list) so state persists across iterations.Set appropriate completion promises
Set appropriate completion promises
Choose unique, unmistakable completion words like
TASK_COMPLETE, DONE, or FEATURE_SHIPPED. Avoid common words that might appear accidentally.Use timeouts for safety
Use timeouts for safety
Always set
--timeout for production use to prevent runaway loops from consuming excessive resources.Enable verbose mode for debugging
Enable verbose mode for debugging
Use
-v when developing new autonomous workflows to understand the agent’s behavior across iterations.
