Featured image of post Pi Mono Explained: The Anti-Framework for AI Coding Agents

Pi Mono Explained: The Anti-Framework for AI Coding Agents

A deep dive into Pi Mono, the radically extensible monorepo for building AI agents that refuses to dictate your workflow—and lets you build the agent you actually want.

Welcome back to another GitHub deep dive! Today, we’re cracking open Pi Mono, a monorepo by Mario Zechner (the creator of libGDX) that takes a radically different philosophy to AI coding agents.

While tools like Claude Code, Cursor, and Aider bake in features like sub-agents, plan modes, and permission popups, Pi says: “Build it yourself.” It gives you the primitives—a unified LLM API, an agent runtime, a TUI framework, and a web UI library—and lets you compose the exact workflow you need using TypeScript extensions.

Let’s break it down using our Mental Model.


Part 1: Foundations (The Mental Model)

Think of most AI coding agents like a pre-built house. The floor plan is fixed, the walls are where they are, and if you want a skylight, you’re submitting a PR and hoping the maintainer agrees.

Pi is more like a construction toolkit. It gives you the steel beams (the LLM API), the electrical wiring (the agent runtime), the interior design tools (TUI & Web UI), and says: “Go build your house.”

The result? A coding agent that ships with 4 default tools (read, write, edit, bash) and is immediately useful—but also an agent you can fundamentally reshape without forking the codebase.

The Mental Model: Pi Mono = Unified LLM API + Stateful Agent Runtime + Terminal UI Framework + Web Components + Extension System = Your AI Agent, Your Way.


Part 2: The Investigation

Pi Mono is a TypeScript monorepo containing 7 packages, each solving a distinct problem in the AI agent stack. Here’s the architecture:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
┌──────────────────────────────────────────────────────────────┐
                     pi-coding-agent                          
  Interactive CLI with sessions, branching, compaction         
  Extensions | Skills | Prompt Templates | Themes             
├──────────────────────────────────────────────────────────────┤
        pi-agent-core                pi-web-ui              
  Agent loop, tools, events    Chat panels, artifacts       
  Steering & follow-up         JS REPL, attachments         
├─────────────────────────────┤  CORS proxy, IndexedDB        
           pi-ai             ├────────────────────────────────┤
  Unified multi-provider API          pi-tui                
  20+ LLM providers            Differential rendering       
  Cross-provider handoffs      Editor, Markdown, Image      
  Tool calling & validation    Synchronized output          
├─────────────────────────────┼────────────────────────────────┤
          pi-mom                      pi-pods               
  Self-managing Slack bot      GPU pod management           
  Docker sandboxed             vLLM auto-configuration      
  Events & scheduled tasks     Multi-GPU support            
└─────────────────────────────┴────────────────────────────────┘

The 7 Packages, Explained

PackageWhat It Does
pi-aiThe foundation. A unified API that talks to OpenAI, Anthropic, Google, Bedrock, Mistral, xAI, Groq, Cerebras, and more. One stream() call, any provider.
pi-agent-coreThe brain. A stateful agent with tool execution, event streaming, steering (interrupt mid-tool), and follow-up queues.
pi-coding-agentThe product. An interactive terminal agent with session branching, auto-compaction, file references via @, and a full extension API.
pi-tuiThe screen. A terminal UI library with differential rendering, flicker-free output, and components like Editor, Markdown renderer, and inline Image display.
pi-web-uiThe browser. Web components for chat interfaces, JavaScript REPL, artifact rendering (HTML, SVG, Markdown), and IndexedDB storage.
pi-momThe assistant. A Slack bot that self-manages its environment—installing tools, writing scripts, and building its own CLI skills autonomously.
pi-podsThe GPU manager. Deploy and manage LLMs on remote GPU pods with automatic vLLM configuration for agentic workloads.

Part 3: The Diagnosis

This is where Pi gets genuinely interesting for developers.

1. The Extension System: Build Anything

Pi’s killer feature is its extension API. Extensions are TypeScript modules that can:

  • Replace built-in tools entirely (swap write for a version that auto-commits to git)
  • Add custom UI components (status lines, headers, overlays—even Doom)
  • Implement sub-agents and plan mode (Pi intentionally doesn’t ship these, so you build them to match your workflow)
  • Gate permissions and protect paths
  • Integrate MCP servers
  • Build SSH and sandbox execution
1
2
3
4
5
export default function (pi: ExtensionAPI) {
  pi.registerTool({ name: "deploy", ... });
  pi.registerCommand("stats", { ... });
  pi.on("tool_call", async (event, ctx) => { ... });
}

The philosophy is clear: features that other tools bake in can be built as extensions, keeping the core minimal and your agent shaped exactly how you work.

2. Cross-Provider Handoffs

Most LLM libraries lock you into one provider per session. Pi’s pi-ai package supports seamless mid-conversation handoffs between providers:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
import { getModel, complete, Context } from '@mariozechner/pi-ai';

// Start with Claude for analysis
const claude = getModel('anthropic', 'claude-sonnet-4-20250514');
const context: Context = {
  messages: [{ role: 'user', content: 'Analyze this complex bug' }]
};
const analysis = await complete(claude, context);
context.messages.push(analysis);

// Switch to GPT for implementation
const gpt = getModel('openai', 'gpt-4o');
context.messages.push({ role: 'user', content: 'Now fix it' });
const fix = await complete(gpt, context);

Thinking blocks from Provider A are automatically converted to text with <thinking> tags for Provider B. Tool calls and results are preserved unchanged.

3. Session Branching & Compaction

Pi stores sessions as JSONL files with a tree structure. Each entry has an id and parentId, enabling in-place branching without creating new files:

  • /tree - Navigate the entire session history, jump to any point, and continue from there
  • /fork - Create a new session from any branch point
  • /compact - Summarize older messages to free context. The full history remains in the JSONL file

This is massively useful for exploration—try one approach, branch, try another, and switch between them without losing anything.

4. Pi Mom: The Self-Managing Bot

pi-mom is unlike any chatbot framework. It’s a Slack bot that:

  • Installs its own tools (apk add git jq curl)
  • Writes its own CLI skills (need a Gmail checker? Ask Mom, she writes the script)
  • Manages its own credentials (ask for tokens, store them securely)
  • Runs in a Docker sandbox with full bash access
  • Schedules events (cron-based periodic tasks, one-shot reminders)

Each Slack channel gets its own workspace, conversation history, and memory files. Mom compacts context automatically and can grep infinite history from log.jsonl.

5. GPU Pod Management with pi-pods

For developers running their own models, pi-pods automates vLLM deployment:

1
2
3
4
5
6
7
8
9
# Setup a DataCrunch pod with NFS storage
pi pods setup dc1 "ssh [email protected]" \
  --mount "sudo mount -t nfs nfs.fin-02.datacrunch.io:/hf-models /mnt/hf-models"

# Start Qwen on a single H100
pi start Qwen/Qwen2.5-Coder-32B-Instruct --name qwen

# Interactive chat with file system tools
pi agent qwen -i

It automatically configures tool calling parsers for known models (Hermes for Qwen, GLM4 parser for GLM, Responses API for GPT-OSS) and manages multi-GPU assignments.


Part 4: The Resolution

Getting Started

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Install the coding agent
npm install -g @mariozechner/pi-coding-agent

# Authenticate
export ANTHROPIC_API_KEY=sk-ant-...
pi

# Or use your existing subscription
pi
/login  # Select provider (Claude Pro, ChatGPT Plus, GitHub Copilot, etc.)

Pi gives you 4 tools by default: read, write, edit, bash. Start talking and the model will use them to fulfill your requests.

Extending Pi

Pi’s extension ecosystem is distributed via Pi Packages—bundles of extensions, skills, prompts, and themes shared via npm or git:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Install a community package
pi install npm:@foo/pi-tools

# Or from git
pi install git:github.com/user/repo

# List, update, configure
pi list
pi update
pi config

Using as an SDK

Pi isn’t just a CLI. You can embed it in your own applications:

1
2
3
4
5
6
7
8
9
import { createAgentSession, SessionManager, AuthStorage, ModelRegistry } from "@mariozechner/pi-coding-agent";

const { session } = await createAgentSession({
  sessionManager: SessionManager.inMemory(),
  authStorage: new AuthStorage(),
  modelRegistry: new ModelRegistry(authStorage),
});

await session.prompt("What files are in the current directory?");

For non-Node.js integrations, use RPC mode over stdin/stdout: pi --mode rpc.


Final Mental Model

AspectTraditional AI AgentsPi Mono
FeaturesPre-built, take-it-or-leave-itExtension-based, build what you need
ProvidersUsually locked to 1-220+ providers, mid-session handoffs
Session ManagementLinear historyTree-structured branching with compaction
Sub-AgentsBuilt-in or nothingBuild your own via extensions
Core PhilosophyOpinionated“Aggressively extensible”

Pi Mono is for developers who see their AI coding agent as a tool that should adapt to their workflow, not the other way around. It trades a polished out-of-the-box experience for radical composability—and backs it up with a genuinely elegant set of primitives.

The monorepo is MIT-licensed, actively maintained, and backed by a growing Discord community. If you’ve ever wished your coding agent worked differently, Pi says: make it so.

Made with laziness love 🦥

Subscribe to My Newsletter