Package Reference
The Pi monorepo contains seven npm packages, each serving a specific purpose. This guide provides detailed information about each package’s capabilities, APIs, and use cases.Overview
pi-ai
Unified multi-provider LLM API with automatic model discoveryKey Features
- Provider Support: OpenAI, Anthropic, Google, Vertex AI, Mistral, Groq, Cerebras, xAI, OpenRouter, Bedrock, and more
- 50+ Pre-configured Models: Automatically maintained model registry
- Tool Calling: TypeBox-based schemas with automatic validation
- Streaming & Batched: Both
stream()andcomplete()interfaces - Token Tracking: Automatic cost and usage calculation
- Cross-Provider Handoff: Continue conversations across different models
- OAuth Providers: Built-in support for Anthropic, OpenAI Codex, GitHub Copilot, Google Gemini CLI
Core APIs
Provider Architecture
Each provider implements a standard stream interface:anthropic-messages: Anthropic Messages APIopenai-completions: OpenAI Chat Completions (used by Mistral, xAI, Groq, etc.)openai-responses: OpenAI Responses APIgoogle-generative-ai: Google Gemini APIgoogle-vertex: Google Vertex AIbedrock-converse-stream: Amazon Bedrock
Model Registry
Models are typed by their API:pi-agent-core
Stateful agent with tool execution and streaming eventsKey Features
- Agent Loop: Automatic turn management with tool execution
- Event System: Fine-grained events for streaming UIs
- Message Queue: Steering (interrupt) and follow-up messages
- State Management: Immutable conversation history
- Custom Messages: Declaration merging for app-specific message types
- Abort Handling: Graceful cancellation with partial results
Core APIs
Event Flow
The agent emits a sequence of events during execution:Tool Definition
Tools use TypeBox schemas for type-safe parameter validation:Message Queue System
Steering (interrupt current work):pi-tui
Terminal UI framework with differential renderingKey Features
- Differential Rendering: Three-strategy rendering (line-diff, box-diff, full)
- Synchronized Output: CSI 2026 for flicker-free updates
- Component-Based: Simple
render()interface - Built-in Components: Text, Editor, Markdown, Image, SelectList, Box
- Theme Support: Customizable styling via theme objects
- Inline Images: Kitty and iTerm2 graphics protocols
- Bracketed Paste: Handles large paste operations
Core APIs
Component Interface
All components implement a simple interface:Rendering Strategies
- Line Diff: Compare line-by-line, update only changed lines (default)
- Box Diff: Send changed regions as rectangular boxes
- Full: Redraw entire screen (fallback)
pi-coding-agent
Interactive terminal coding agent with extension systemKey Features
- Four Modes: Interactive (TUI), Print, JSON, RPC
- Session Management: Branching, compaction, tree navigation
- Extension System: TypeScript modules with lifecycle hooks
- Skills: Markdown-based task instructions
- Prompt Templates: Reusable prompts with arguments
- Built-in Tools: read, write, edit, bash, grep, find, ls
- Context Files:
.contextdocs,.context.mdsupport
Session Architecture
Sessions are stored as JSON files with a tree structure:parentId, creating a tree. Navigate with /tree.
Compaction: When context exceeds limits, older messages are summarized into a CompactionEntry.
Extension System
Extensions are TypeScript modules that receive anExtensionAPI:
- Global:
~/.pi/agent/extensions/ - Project:
.pi/extensions/ - Explicit:
--extension path/to/extension.ts
Skills System
Skills are markdown files with frontmatter:/skill python-debug or they’re auto-discovered and presented in the system prompt.
Skill locations:
- Global:
~/.pi/agent/skills/ - Project:
.pi/skills/ - Explicit:
--skill path/to/skill.md
pi-mom
Slack bot that delegates messages to pi coding agentKey Features
- Receives Slack messages via Socket Mode
- Spawns pi-coding-agent instances for each conversation
- Manages concurrent sessions
- Scheduled task execution with cron syntax
- Shared session pool for team collaboration
Architecture
pi-web-ui
Reusable web components for AI chat interfacesKey Features
- Built with mini-lit (Lit compatible)
- Chat message rendering
- Model selection dropdown
- Markdown and code highlighting
- File attachment support
- Integrates with pi-ai for browser usage
Core Components
pi-pods
CLI for managing vLLM deployments on GPU podsKey Features
- Deploy LLM inference servers on GPU infrastructure
- Manage pod lifecycle (start, stop, scale)
- Monitor resource usage
- Configure model weights and parameters
Usage
Package Relationships
Dependency Flow
Shared Patterns
Event-driven: All packages emit events for extensibility TypeScript-first: Full type safety across the stack Stream-based: Designed for real-time streaming responses Composable: Use packages independently or togetherNext Steps
Architecture
Understand the overall system design
Extensibility
Learn how to extend and customize