Ralph Autonomous Agent
Orchestrates autonomous code generation through repeated iterations using fresh agent instances until all tasks are complete.
Execution Contract
Inputs
When invoking ralph, provide:
- Plan file path: Absolute or workspace-relative path to the plan markdown file
- Starting task (optional): Task ID to resume from (e.g., "Task 3")
- Max iterations (optional): Default 20
State Files
Ralph creates a companion progress file alongside the plan:
.agents/plans/in-progress/
├── my-feature.md # The plan
└── my-feature.progress.md # Progress log (auto-created)
Task Status Markers
In plan files, tasks use checkbox status with optional annotations:
| Marker | Meaning |
|---|---|
- [ ] |
Not started |
- [x] |
Completed |
- [ ] (blocked) |
Blocked, needs intervention |
- [ ] (manual-verify) |
Requires manual verification |
Stop Conditions
The loop exits when ANY of these occur:
- All tasks complete: Every task checkbox is
[x] - Blocked encountered: A task is marked
(blocked) - Max iterations reached: Default 20 iterations
- Only manual-verify remaining: All incomplete tasks require manual verification
- Explicit stop: User interrupts
Handoff Payload
When handing off to fresh iteration, include:
Continue ralph execution for: [plan file path]
Current task: [Task ID and title]
Last progress: [Most recent progress entry summary]
Next action: [Specific next step]
Load the ralph skill and continue execution.
Phases
Phase 1: Setup
Before running the loop, ensure the plan has proper structure.
Required task format:
- [ ] **Task N: Short descriptive title**
- Scope: `path/to/affected/files` or package name
- Depends on: Task M (or "none")
- Acceptance:
- Specific criterion 1
- Specific criterion 2
- Notes: Optional implementation hints
Task sizing rule: If you can't describe the task in 2-3 sentences, it's too big. Split it.
Dependency ordering: Schema → Service → API → UI → Tests
Phase 2: Execution Loop
Each iteration follows this workflow:
- Load context: Read plan file, identify next incomplete task
- Check dependencies: Ensure all
Depends ontasks are complete - Implement: Complete the task following its scope and acceptance criteria
- Verify: Run verification commands (see Verification section)
- Update progress: Append entry to
.progress.md - Update plan: Check off completed task
[x] - Commit: One task = one commit with proper footers
- Handoff or complete: Continue to next task or exit if done
Git discipline:
- One task = one commit
- Never push to main branch
- Include footers:
Amp-Thread-IDandCo-authored-by: Amp <amp@ampcode.com> - Commit format:
feat: [Task ID] - [Task Title]
Verification Strategy
Use Cargo and just commands for verification:
| Situation | Command |
|---|---|
| Every task | just check (fast typecheck) |
| After code changes | just lint (clippy) |
| Logic changes | just test |
| Pre-commit | just ci (fmt + lint + test) |
Quick reference:
just check # cargo check
just lint # cargo clippy -- -D warnings
just test # cargo test
just ci # full verification
Stuck Detection & Safety
Limits
- Max iterations: 20 per session
- Max retries per task: 2 attempts before marking blocked
- Scope control: Only modify files in declared
Scope
Blocking a Task
When a task cannot proceed:
- Add
(blocked)annotation to the task checkbox - Add blocker details to progress file
- Stop the loop and surface to user
Example blocked task:
- [ ] (blocked) **Task 5: Integrate payment API**
- Scope: `cloud/functions/payments`
- Depends on: Task 4
- Acceptance: Payment webhook handler works
- Notes: Blocked - need API credentials from finance team
Manual Verification Tasks
Tasks marked (manual-verify) require human interaction:
- Don't retry these automatically
- Stop loop when only manual-verify tasks remain
- Surface verification instructions to user
Guardrails
- Scope control: Only touch files in declared
Scope - No scope creep: Expanding scope requires explicit plan edit
- No prod commands: Never run production deployments
- No secrets: Never commit credentials or API keys
- Branch safety: Never push to main
Usage
Starting Fresh
Run ralph on .agents/plans/tech-debt/in-progress/my-feature.md
Resuming
Continue ralph from Task 5 on .agents/plans/tech-debt/in-progress/my-feature.md
Checking Status
Show ralph progress for .agents/plans/tech-debt/in-progress/my-feature.md
Integration with Plans
Ralph works with plans in the standard directory structure:
- Plans live in
.agents/plans/in-progress/ - Create plans manually following the task format above
- Use ralph to execute plans autonomously
Converted and distributed by TomeVault — claim your Tome and manage your conversions.