Skip to main content

Overview

The Pi bridge wraps the pi CLI (from the pi-mono project), a minimal terminal coding harness that is aggressively extensible. Pi supports multi-provider model selection, thinking levels, TypeScript extensions, skills, prompt templates, and fine-grained JSONL event streaming. It provides both token usage and cost data. The bridge is implemented by PiBridge and configured through PiBridgeBuilder. Access the builder through the AgentCtrl facade:

Prerequisites

Install Pi globally via npm or bun:
Configure an API key:

Basic Usage

With model selection:

Model Selection

Pi supports flexible model identification with optional provider prefix and thinking level shorthand:
Use withProvider() to explicitly set the provider when the model name alone is ambiguous:

Thinking Levels

Pi supports six thinking levels that control how much the model reasons before responding:
Alternatively, use the model shorthand: ->withModel('sonnet:high').

System Prompts

Replace or extend the default system prompt:

Tool Control

By default, Pi provides four tools: read, write, edit, and bash. Additional built-in tools include grep, find, and ls.

File Arguments

Attach files to the prompt using withFiles(). These are passed as @-prefixed arguments to Pi:

Extensions and Skills

Pi supports TypeScript extensions and skills that add custom tools, commands, and capabilities:

Streaming with Pi

Pi streams output as JSONL with granular event types. The bridge normalizes these into the standard callback API:

Event Normalization

Pi emits a rich set of JSONL events that are normalized:
  • MessageUpdateEvent (text_delta) — Text deltas delivered through onText().
  • ToolExecutionEndEvent — Tool results delivered through onToolUse() with tool name, call ID, result, and error flag.
  • ErrorEvent — Errors delivered through onError().
  • SessionEvent, AgentStart/End, TurnStart/End, MessageStart/End, ToolExecutionStart — Lifecycle events available through the wiretap() event system.

Session Management

Pi maintains sessions as JSONL files. Agent-Ctrl extracts session IDs from the session header event:

API Key Override

Override the API key for a specific execution without changing environment variables:

Usage and Cost Data

Pi provides token usage and cost data from the message events:

Data Availability

Complete Example

Comparison with Other Bridges

Environment Variables