Pi Agent
Integrate Pi Coding Agent with Ralph TUI for AI-assisted coding.
Pi Agent
The Pi agent plugin integrates with the Pi Coding Agent (pi) to execute AI coding tasks. Pi is a minimal, extensible terminal coding agent with a tiny core that supports multiple providers and models.
Pi outputs structured JSONL which enables detailed subagent tracing with tool call breakdowns.
Prerequisites
Install Pi CLI:
For other platforms, visit the Pi GitHub repository.
Verify installation:
You'll also need an API key for at least one supported provider:
- Anthropic:
ANTHROPIC_API_KEY - OpenAI:
OPENAI_API_KEY - Google:
GEMINI_API_KEY
Basic Usage
Run with Pi
Use the --agent pi flag:
Select a Model
Specify a model via --agent-options:
Or configure in TOML:
Configure Thinking Level
Set extended thinking level:
Configuration
Shorthand Config
The simplest configuration:
Full Config
For advanced control:
Options Reference
| Option | Type | Default | Description |
|---|---|---|---|
mode | string | "json" | Output mode: "json" for structured JSONL or "text" for plain text |
model | string | - | Model to use (e.g., sonnet, openai/gpt-4o, anthropic/claude-sonnet) |
thinking | string | - | Thinking level: off, minimal, low, medium, high, xhigh |
timeout | number | 0 | Execution timeout in ms (0 = no timeout) |
command | string | "pi" | Path to Pi CLI executable |
A timeout of 0 means no timeout (unlimited execution time). For production or autonomous runs, consider setting a reasonable timeout like 300000 (5 minutes) or 600000 (10 minutes).
Model Selection
Pi supports multiple providers and model patterns:
Shorthand Models
Provider/Model Format
With Thinking Suffix
List available models:
Thinking Levels
Pi supports extended thinking for supported models:
| Level | Description |
|---|---|
| (empty) | Use model defaults |
off | No extended thinking |
minimal | Minimal thinking budget |
low | Low thinking budget |
medium | Medium thinking budget |
high | High thinking budget |
xhigh | Maximum thinking |
Output Modes
JSON Mode (Default)
Enables structured JSONL output with:
- Detailed tool call tracking
- Subagent tracing
- Token usage reporting
- Cost information
Text Mode
Plain text output without structured data.
Skills Support
Pi CLI supports skills:
| Location | Description |
|---|---|
~/.pi/skills/ | Personal skills (user-specific) |
.pi/skills/ | Repository skills (project-specific) |
How It Works
When Ralph TUI executes a task with Pi:
- Build command: Constructs
pi --print --mode json [options] - Pass prompt via stdin: Avoids shell escaping issues with special characters
- Parse JSONL output: Extracts structured events for display
- Stream in real-time: Shows thinking and tool calls as they happen
- Handle completion: Reports final results with usage stats
CLI Arguments
Ralph TUI builds these arguments:
Subagent Tracing
Pi's JSON mode enables rich subagent tracing:
- Thinking: Shows reasoning process
- Tool Calls: Detailed tool invocations with inputs
- Tool Results: Tool outputs with errors
- Token Usage: Input/output tokens and cost
- Turn History: Multiple conversation turns
Troubleshooting
"Pi not found in PATH"
Ensure Pi is installed and in your PATH:
"No API key configured"
Set your provider API key:
"Invalid model"
Check available models:
"Execution timeout"
Increase the timeout for complex tasks:
Next Steps
- Claude Agent - Anthropic's Claude Code
- Kiro Agent - AWS Kiro CLI
- Configuration - Full options reference