Advanced Topics¶
Deep dives into Ralph's internals and advanced usage patterns.
In This Section¶
| Topic | Description |
|---|---|
| Architecture | System design and crate structure |
| Creating Custom Hats | Design and implement custom hats |
| Event System Design | How events route between hats |
| Memory System | Persistent learning mechanics |
| Task System | Runtime work tracking |
| Testing & Validation | Smoke tests, E2E tests, TUI validation |
| Diagnostics | Debug with full visibility |
| Parallel Loops | Run multiple loops concurrently with worktrees |
When to Read This¶
These guides are for you if:
- You're building complex multi-hat workflows
- You want to understand how Ralph works internally
- You're contributing to Ralph development
- You need to debug tricky issues
- You're extending Ralph with custom backends
Key Concepts¶
Crate Architecture¶
Ralph is organized as a Cargo workspace:
ralph-orchestrator/
├── crates/
│ ├── ralph-proto/ # Protocol types
│ ├── ralph-core/ # Orchestration engine
│ ├── ralph-adapters/ # CLI backends
│ ├── ralph-telegram/ # Telegram bot for human-in-the-loop
│ ├── ralph-tui/ # Terminal UI
│ ├── ralph-cli/ # Binary entry point
│ ├── ralph-e2e/ # End-to-end testing
│ └── ralph-bench/ # Benchmarking
Event Flow¶
Events are the nervous system of hat-based Ralph:
flowchart LR
A[starting_event] --> B[EventBus]
B --> C[Hat Selection]
C --> D[Hat Execution]
D --> E[Event Emission]
E --> B State Management¶
Ralph uses files for all persistent state:
| File | Purpose |
|---|---|
.agent/memories.md | Cross-session learning |
.agent/tasks.jsonl | Runtime work tracking |
.agent/event_history.jsonl | Event audit log |
.agent/scratchpad.md | Legacy state (deprecated) |
Quick Reference¶
Enable Diagnostics¶
Run E2E Tests¶
Record a Session¶
Validate TUI¶
Next Steps¶
Start with Architecture for the big picture.