A robust, self-correcting workflow for AI agents.
The Ralph Loop implements a self-correcting mechanism that utilizes an AI agent's ability to observe its own outputs and errors across multiple runs to complete complex tasks. This pattern is particularly useful for tasks that require multiple iterations to achieve full compliance with success criteria.
- Comprehensive Prompting: Use a
PROMPT.mdwith explicit SUCCESS CRITERIA and a COMPLETION PROMISE. - Iterative Execution: The agent runs in a loop.
- Self-Correction: If the agent exits without outputting the completion promise, it restarts and observes the current filesystem state, logs, and previous errors to continue.
To maximize effectiveness, your PROMPT.md should include:
- TASK: Detailed objective description.
- SUCCESS CRITERIA: Measurable conditions for completion.
- PROCESS: Recommended steps for the agent.
- COMPLETION PROMISE: A specific string (e.g.,
<promise>COMPLETE</promise>) that the agent MUST output only when all criteria are met.
You can run a loop manually using the provided bash script:
/bin/bash scripts/ralph-loop.sh --prompt PROMPT.md --command "claude-code" --promise "COMPLETE" --max-iterations 20When deployed as a skill in Antigravity or Gemini CLI, the agent will automatically utilize this pattern when invoked.
SKILL.md: Metadata and skill definition.scripts/: Containsralph-loop.shimplementation.examples/: Template prompts for reference.