Documentation Index
Fetch the complete documentation index at: https://mintlify.com/badlogic/pi-mono/llms.txt
Use this file to discover all available pages before exploring further.
Architecture Overview
The Pi toolkit is built as a layered monorepo architecture where each package provides specific capabilities that build upon lower-level packages. This design enables you to use Pi at different levels of abstraction depending on your needs.Architectural Layers
Pi’s architecture is organized into four distinct layers:Foundation Layer
The foundation provides low-level primitives: pi-tui - Terminal UI framework with differential rendering- Component-based architecture
- Synchronized output for flicker-free updates
- Built-in components: Text, Editor, Markdown, Image, SelectList
- Theme support for customization
- Handles bracketed paste mode and autocomplete
- CLI for deploying and managing LLM inference servers
- Handles GPU resource allocation
- Independent utility for self-hosted deployments
AI Layer
pi-ai - Unified multi-provider LLM API- Abstracts differences between OpenAI, Anthropic, Google, etc.
- Automatic model discovery with 50+ pre-configured models
- Streaming and non-streaming interfaces
- Tool calling (function calling) support
- Token and cost tracking
- Cross-provider context handoff
- OAuth provider support
Agent Layer
pi-agent-core - Stateful agent runtime- Agent loop with tool execution
- Event-based architecture for streaming updates
- State management for conversations
- Message queue system for steering and follow-ups
- Abort handling and error recovery
- Custom message type support via declaration merging
- Turn management (LLM call + tool executions)
- Tool result formatting
- Context transformation
- Streaming event emission
Application Layer
Application-specific implementations built on the agent runtime: pi-coding-agent - Terminal coding agent CLI- Interactive TUI mode with editor
- Session management with branching
- Extension system
- Skills and prompt templates
- Built-in tools: read, write, edit, bash, grep, find
- Multiple output modes: interactive, print, JSON, RPC
- Delegates Slack messages to pi-coding-agent
- Manages multiple concurrent conversations
- Scheduled task execution
- Shared session management
- Chat interface components
- Model selection UI
- Integration with pi-ai for browser-based apps
- Works with Lit or mini-lit
Data Flow
User Request Flow
Event Flow
The agent system is event-driven at every layer:Package Dependencies
The dependency graph shows clear separation of concerns:Extension Points
The architecture provides multiple extension points:At the AI Layer (pi-ai)
- Custom models with
Model<Api>interface - Provider registration for new LLM APIs
- Custom stream functions for proxy backends
At the Agent Layer (pi-agent-core)
- Custom message types via declaration merging
- Tool registration with
AgentToolinterface - Context transformation hooks
- Custom
convertToLlmfunction
At the Application Layer (pi-coding-agent)
- Extensions: TypeScript modules with full access to agent lifecycle
- Skills: Markdown files with instructions for specific tasks
- Prompt Templates: Reusable prompt snippets with argument substitution
- Themes: JSON-based UI customization
Design Principles
1. Layered Abstraction
Each layer exposes a clean API that hides implementation details from layers above:- pi-ai abstracts provider differences
- pi-agent-core abstracts the agent loop
- pi-coding-agent abstracts session management and UI
2. Event-Driven Architecture
All layers communicate via events:- Enables streaming UIs
- Allows extensions to observe without blocking
- Supports multiple subscribers (extensions, logging, metrics)
3. Type Safety
TypeScript types flow through all layers:- Model types enforce API compatibility
- Tool schemas use TypeBox for runtime validation
- Extension types ensure compile-time correctness
4. Composability
Packages can be used independently:- Use pi-ai alone for LLM calls in any app
- Use pi-agent-core for custom agent implementations
- Use pi-tui for any terminal UI application
- Use pi-coding-agent as a library or CLI
Next Steps
Package Details
Explore what each package provides
Extensibility
Learn how to customize and extend Pi