7 Essential Pi Agent Components for Transparency, Cost & MCP Integration
This article details seven Pi Agent extensions that add MCP ecosystem access, language server integration, cost tracking, cache hit visualization, per-turn telemetry, session introspection, and tool output compression, explaining each component's capabilities, implementation highlights, and limitations for building more transparent and efficient AI agents.
01 pi-mcp-adapter: Access the Entire MCP Ecosystem in ~200 Tokens
Capability: Enables Pi to use any MCP server — the model discovers and invokes real tools on demand via a single proxy tool; servers start only when first called. Databases, browsers, APIs — the whole MCP ecosystem becomes available without waiting for official native support.
Highlight: Replaces "capability definition" with "proxy convergence": a single server's tool definitions can exceed 10k tokens, but this adapter registers zero per-server definitions. All calls converge into one ~200-token proxy tool; the more servers you add, the more tokens you save. Existing configurations migrate at zero cost — standard .mcp.json works out of the box; Cursor, Claude Code, and Codex configs preview via /mcp setup and import with one click.
Boundary: Tool discovery responsibility shifts to the model; if the model doesn't actively explore, the tools go unused. Server security and quality are not improved by token savings.
02 pi-lsp: Universal Language Server Socket
Capability: Connects Pi to real language servers: after every successful write/edit, the file syncs to the server and diagnostics return instantly so the model sees exact line/column errors immediately. Also registers five model tools — lsp_diagnostics, lsp_hover, lsp_definition, lsp_references, lsp_symbols — enabling type queries, go-to-definition, and reference search via the actual server instead of guessing.
Highlight: (1) Declarative configuration: one JSON declares bin, args, file match patterns, and rootMarkers; adding a language means adding config, not installing a new plugin. Each server runs one long-lived process per project root, reused repeatedly. (2) Measured feedback: diagnostics are appended, not treated as failures — writes still succeed, errors become context fed back to the model while also showing a user-visible hint.
Boundary: Language server binaries must be installed and on PATH; server startup and diagnostic wait add slight latency per write.
Best for: Multi-language projects where the model should know errors immediately instead of waiting for test runs.
03 pi-cost: Token Spend Ledger
Capability: Turns token spend into a drillable ledger: overview → project → session → message (four levels). Actual vs. estimated spend shown side by side, making it obvious where money goes.
Highlight: Implemented as a standalone local web panel (default port 5461), independent of the TUI. /cost toggles it within a session; npx pi-cost runs it detached from the agent for reviewing historical sessions without launching Pi.
Boundary: Only answers "where money went," not "how to save it."
04 pi-cache-graph: Visible Cache Hit Rates
Capability: Gives context caching a check-up: /cache graph renders a three-view TUI of hit-rate curves (per-turn, cumulative, cumulative token volume). /cache stats lists per-message token breakdown. /cache export outputs CSV for external analysis.
Highlight: Built as the observation layer for the pi-context-prune extension — want to know if pruning blows up the cache? One glance at the graph tells you. Hit-rate formula cacheRead / (input + cacheRead + cacheWrite) normalizes reporting differences between Anthropic and OpenAI.
Boundary: Observes only, does not optimize; value peaks when paired with compression extensions.
05 pi-tps: Per-Turn Speed & Cost Bill
Capability: At the end of every agent turn, automatically pops a speed bill — TPS, TTFT, total latency, input/output tokens, pause count, and blended cost rate ($/M). On session resume or /tree branch switch, auto-backfills the latest entry. /tps-export dumps telemetry as JSONL and broadcasts tps:telemetry events to other extensions.
Highlight: Bundled from the tps example extension in pi-mono; npm package has zero runtime dependencies. Timing is rigorous: TTFT measured at first real token arrival; network latency and tool-execution gaps excluded from generation speed; streaming gaps >500ms counted as inference pauses and subtracted from TPS. Three-gate speed algorithm shows — when burst delivery or unreliable timing occurs, never reporting an inflated number.
Boundary: Reports speed and rate only; root cause (model, network, queue) requires correlating TTFT and pauses. $/M depends on model pricing table; omitted when pricing data unavailable.
06 pi-inspect: Session X-Ray
Capability: Answers "what's actually in this session": loaded tools (with parameter schemas and sources), slash commands, skills, and the full initial system prompt — all laid out in a local dashboard (port 5462). Snapshots persist and are replayable.
Highlight: Share button deflate-compresses the snapshot, base64url-encodes it into the URL hash; recipient opens a static hosted page and sees it instantly — no server, no upload. Warning: link contains system prompt and cwd; don't share secrets.
Boundary: Debugging tool, not a daily driver; value concentrates in "something's off" moments.
07 pi-rtk-optimizer: Tool Output Compression Pipeline
Capability: Slims context: bash commands auto-rewritten to token-frugal rtk equivalents; verbose output from bash, read, grep compressed before feeding back to model; test, build, git, lint output each have dedicated aggregation strategies.
Highlight: Multi-stage pipeline with two safety nets: ANSI stripping → test aggregation → build error extraction → git compression → lint aggregation → grep grouping → source filtering, processed stepwise; smart truncation + hard truncation fallback. Rewrite decisions delegated to external rtk CLI; if not installed, commands pass through unchanged. Reads ≤80 lines keep byte-for-byte fidelity; outputs with hashline anchors preserve full edit anchors, never truncating the model's positioning marks.
Boundary: Depends on external rtk binary; aggressive mode strips comments and whitespace — validate on small scale first.
Project List
pi-mcp-adapter: https://github.com/nicobailon/pi-mcp-adapter pi-lsp: https://pi.dev/packages/pi-lsp pi-cost: https://github.com/NikiforovAll/pi-cost pi-cache-graph: https://github.com/championswimmer/pi-cache-graph pi-tps: https://github.com/monotykamary/pi-tps pi-inspect:
https://github.com/NikiforovAll/pi-inspectSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
AI Step-by-Step
Sharing AI knowledge, practical implementation records, and more.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
