Pi Agent Rust - High Performance AI Coding Assistant
Discover pi_agent_rust - Rust port of Pi Agent with high performance, strong security, and small footprint.
When you want an AI coding assistant in your terminal, existing tools often face problems: slow startup, high RAM consumption, unreliability, and difficulty in extension. pi_agent_rust was created to solve all these problems.
Current Problems#
Existing AI coding assistants:
- Slow to start: Node.js/Python runtimes add 500ms+ before you can type
- Memory hungry: Electron apps or heavy runtimes eat gigabytes
- Unreliable: Streaming breaks, sessions corrupt, tools fail silently
- Hard to extend: Closed ecosystems or complex plugin systems
The Solution: pi_agent_rust#
pi_agent_rust is a from-scratch Rust port of Pi Agent ↗ by Mario Zechner ↗ (made with his blessing!). Single binary, instant startup, stable streaming, and 8 built-in tools.
Rather than a direct line-by-line translation, this port builds on two purpose-built Rust libraries:
- asupersync ↗: A structured concurrency async runtime with built-in HTTP, TLS, and SQLite
- rich_rust ↗: A Rust port of Rich ↗ by Will McGugan ↗, providing beautiful terminal output with markup syntax
Quick Start#
# Install latest release
curl -fsSL "https://raw.githubusercontent.com/Dicklesworthstone/pi_agent_rust/main/install.sh?$(date +%s)" | bash
# Start a session
pi "Help me refactor this function to use async/await"
# Continue a previous session
pi --continue
# Single-shot mode (no session)
pi -p "What does this error mean?" < error.logbashWhy Should You Care?#
If you already use Pi Agent, especially through OpenClaw, this project keeps the core workflow while upgrading the engine under the hood:
- Substantially faster in realistic end-to-end flows (not synthetic microbenchmarks)
- Dramatically smaller memory footprint in long-running sessions
- Materially stronger security model for extension/tool execution, including command-level blocking of dangerous extension shell patterns
Security is a First-class Design Goal#
Security is not a bolt-on but a first-class design goal:
- Capability-gated hostcalls (
tool/exec/http/session/ui/events) - Two-stage extension
execenforcement: capability gate first, then command mediation that blocks critical shell classes by default (for example recursive delete, disk/device writes, reverse shell) and can tighten to block high-tier classes in strict/safe policy - Policy + runtime risk + quota enforcement on the execution path
- Per-extension trust lifecycle (
pending->acknowledged->trusted->killed) with kill-switch audit logs and explicit operator provenance - Hostcall-lane emergency controls that can force compatibility-lane execution globally or for one extension when fast-lane behavior needs immediate containment
- Structured concurrency via
asupersyncfor more predictable cancellation/lifecycle behavior - Auditable runtime signals/ledgers and redacted security alerts for extension behavior
Extension Runtime Guarantees#
| Extension assurance signal | Why you should care |
|---|---|
Two-stage exec guard (exec capability policy + command-level mediation + DCG/heredoc AST signals) | Dangerous shell intent is caught before spawn, including destructive payloads hidden in multiline wrappers |
Trust lifecycle + kill switch (pending/acknowledged/trusted/killed) | You can quarantine an extension instantly, log who pulled the switch and why, and require explicit re-acknowledgement before restoring access |
Hostcall lane kill-switch controls (forced_compat_global_kill_switch, forced_compat_extension_kill_switch) | Fast-path regressions can be contained immediately by forcing compatibility-lane execution without disabling the extension system |
| Deterministic hostcall reactor mesh (shard affinity, bounded SPSC lanes, backpressure telemetry, optional NUMA slab tracking) | Runtime behavior stays predictable under contention; queue pressure and routing decisions are observable instead of opaque |
| Startup prewarm + warm isolate reuse for JS runtimes | Runtime creation overlaps startup and warm reuse keeps repeated extension runs low-latency without a Node/Bun process model |
Tamper-evident runtime risk ledger (verify / replay / calibrate) | Security decisions are hash-linked and can be replayed or threshold-tuned from real runtime traces |
How We Made It So Fast#
The speed gains come from runtime design, not one trick:
| Technique | What we do | Runtime effect |
|---|---|---|
| Cold-start minimization | Single static binary, no Node/Bun runtime bootstrap, no JIT warmup, startup prewarm for extension runtime paths | Faster time-to-first-interaction |
| Less copying on hot paths | Arc/Cow message flow, zero-copy hostcall/tool payload handling, reduced clone-heavy provider/session paths | Lower CPU and allocation pressure |
| Deterministic dispatch core | Typed hostcall opcodes, fast-lane/compat-lane routing, bounded shard queues with reactor-mesh telemetry | Better tail latency under concurrent extension load |
| Efficient long-session storage | SQLite session index + v2 sidecar (segmented log + offset index) with O(index+tail) reopen path | Fast resume on large histories |
| Streaming parser tuned for real networks | SSE parser tracks scanned bytes, handles UTF-8 tails, normalizes chunk boundaries, interns event-type strings | Lower streaming overhead and fewer parser stalls |
| Safe fast-path controls | Shadow dual execution sampling, automatic backoff on divergence/overhead, compatibility-lane kill switches for containment | Keeps optimizations fast without silent behavior drift |
| CI-level performance governance | Scenario matrices, strict artifact contracts, fail-closed perf gates | Regressions are caught before release |
Features#
- Single binary: No runtime dependencies
- Instant startup: No 500ms+ delay from Node.js/Python
- Stable streaming: SSE parser tuned for real networks
- 8 built-in tools: File operations, bash execution, HTTP requests, and more
- Extension system: Secure, auditable, with kill-switch controls
- Session management: SQLite-based with efficient compaction
- Beautiful terminal output: Via rich_rust with markup syntax
- Zero unsafe code: Written in safe Rust
Installation#
Script (recommended)#
curl -fsSL "https://raw.githubusercontent.com/Dicklesworthstone/pi_agent_rust/main/install.sh?$(date +%s)" | bashbashManual download#
Download from GitHub Releases ↗ for your platform.
How to Use#
Basic Usage#
After installation, you can start using pi_agent_rust immediately:
# Start an interactive session
pi "Help me understand this codebase"
# Ask a specific question
pi "What does this function do?"bashSession Management#
pi_agent_rust maintains session state, allowing you to continue conversations:
# Continue your last session
pi --continue
# Start a new session (discards previous context)
pi --new "Let's start fresh"bashSingle-Shot Mode#
For quick questions without session persistence:
# One-off question about an error
pi -p "Why is this failing?" < error.log
# Explain a file
pi -p "Explain this code" < src/main.rs
# Get help with a specific command
pi -p "How do I use git rebase?"bashWorking with Files#
pi_agent_rust can read and analyze your codebase:
# Ask about a specific file
pi "Read src/utils/helpers.rs and suggest improvements"
# Compare two files
pi "Compare the old and new implementations in src/old.rs and src/new.rs"
# Analyze the entire project structure
pi "Give me an overview of this project's architecture"bashCode Refactoring#
Get help with code improvements:
# Refactor a function
pi "Refactor this function to be more readable" < src/auth/login.rs
# Add error handling
pi "Add proper error handling to this code" < src/api/client.rs
# Optimize performance
pi "Suggest performance improvements for this loop" < src/data/processor.rsbashDebugging Assistance#
Use pi_agent_rust as a debugging partner:
# Debug an error
pi "Help me debug this error" < error.log
# Explain a stack trace
pi "Explain this stack trace and suggest fixes" < stacktrace.txt
# Find the root cause
pi "Why is this test failing?" < test_output.logbashConfiguration#
Configure your API provider and settings:
# Set your API key (example for OpenAI)
export OPENAI_API_KEY="your-api-key-here"
# Use a different model
pi --model gpt-4 "Help me with this complex algorithm"
# Configure the output format
pi --format json "Analyze this code structure"bashWorking with Extensions#
pi_agent_rust supports secure extensions:
# List available extensions
pi --list-extensions
# Enable an extension
pi --enable extension-name
# Check extension status
pi --extension-statusbashPractical Workflows#
Daily Development#
# Morning standup: review recent changes
pi "Summarize the changes I made yesterday"
# Feature development: get guidance
pi "Help me implement user authentication"
# Code review: get feedback
pi "Review my recent commits for potential issues"bashLearning New Codebases#
# First exploration
pi "Give me a high-level overview of this project"
# Deep dive into specific areas
pi "Explain how the authentication system works"
# Understand dependencies
pi "Map out the key dependencies and their relationships"bashTroubleshooting#
# Quick fix
pi -p "How do I fix this merge conflict?" < git_conflict.txt
# Systematic debugging
pi "Help me trace through this bug systematically"
# Performance investigation
pi "Identify potential performance bottlenecks in this code"bash[!TIP] Best Practices
- Be specific in your requests for better results
- Use single-shot mode for quick questions
- Leverage session context for multi-step tasks
- Review and test suggested code changes
- Use extensions to extend functionality safely
When Should You Use pi_agent_rust?#
pi_agent_rust is right for you if:
- You want a fast, reliable AI coding assistant in your terminal
- You care about security with strong extension execution controls
- You need to run long sessions with large state
- You want a small memory footprint
- You prefer a single binary over complex runtime dependencies
Conclusion#
pi_agent_rust represents a significant leap forward in AI coding assistants - Rust-based, security-first, with performance measured by realistic workloads. With structured concurrency, extension runtime guarantees, and small memory footprint, it’s an excellent choice for developers who want AI assistance without sacrificing performance or security.