Skip to main content

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 discovery

Key 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() and complete() 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:
Built-in APIs:
  • anthropic-messages: Anthropic Messages API
  • openai-completions: OpenAI Chat Completions (used by Mistral, xAI, Groq, etc.)
  • openai-responses: OpenAI Responses API
  • google-generative-ai: Google Gemini API
  • google-vertex: Google Vertex AI
  • bedrock-converse-stream: Amazon Bedrock

Model Registry

Models are typed by their API:
Query models with full type safety:
The model registry is automatically regenerated during the build process by fetching the latest model data from providers.

pi-agent-core

Stateful agent with tool execution and streaming events

Key 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):
Follow-up (queue for after completion):

pi-tui

Terminal UI framework with differential rendering

Key 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

  1. Line Diff: Compare line-by-line, update only changed lines (default)
  2. Box Diff: Send changed regions as rectangular boxes
  3. Full: Redraw entire screen (fallback)

pi-coding-agent

Interactive terminal coding agent with extension system

Key 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.md support

Session Architecture

Sessions are stored as JSON files with a tree structure:
Branching: Each entry has a 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 an ExtensionAPI:
Extension locations:
  • Global: ~/.pi/agent/extensions/
  • Project: .pi/extensions/
  • Explicit: --extension path/to/extension.ts

Skills System

Skills are markdown files with frontmatter:
The agent can load skills with /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 agent

Key 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 interfaces

Key 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 pods

Key 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 together

Next Steps

Architecture

Understand the overall system design

Extensibility

Learn how to extend and customize