pi-mono/packages/coding-agent/examples
Armin Ronacher 2498ca492e refactor(agent,coding-agent): isolate codemode, tool search, and MCP from the core
The agent loop is back to main's tool execution: it only exports runToolCall(), honors isError results, and passes structuredContent through afterToolCall. Nested calls (ctx.executeTool, ids, events with parentToolCallId, the nestedCalls record) live in coding-agent and start on the first call.

AgentSession no longer knows exec or tool_search. Tools adjust the declared loadout through a generic prepareLoadout hook, and codemode and tool_search use it like any other tool.

exec and tool_search move to built-in extensions under src/extensions/ and register inactive (defaultActive: false). The CLI loads them with MCP; SDK sessions add createCodemodeExtension(), createToolSearchExtension(), and createMcpExtension(). Extensions gain pi.getSettings() and model catalog and classifier access on ModelRegistry.
2026-09-27 21:15:56 +02:00
..
extensions feat: build with TypeScript 7 and run sources with plain node 2026-09-25 13:14:33 +02:00
plugins/pi-example-plugin feat: add transactional replicated state 2026-09-21 16:07:59 +02:00
sdk refactor(agent,coding-agent): isolate codemode, tool search, and MCP from the core 2026-09-27 21:15:56 +02:00
README.md feat: build with TypeScript 7 and run sources with plain node 2026-09-25 13:14:33 +02:00
rpc-client.ts feat: build with TypeScript 7 and run sources with plain node 2026-09-25 13:14:33 +02:00
rpc-extension-ui.ts feat: build with TypeScript 7 and run sources with plain node 2026-09-25 13:14:33 +02:00

Examples

Example code for the pi-coding-agent SDK, process integration, and extensions.

CLI integration

rpc-client.ts uses the typed RpcClient to run Pi in a child process, stream events, and wait for the run to settle.

Build the coding-agent package before running it from a repository checkout:

node examples/rpc-client.ts "Explain this repository"

Directories

sdk/

Programmatic usage via createAgentSession(). Shows how to customize models, prompts, tools, extensions, and session management.

extensions/

Example extensions demonstrating:

  • Lifecycle event handlers (tool interception, safety gates, context modifications)
  • Custom tools (todo lists, questions, subagents, output truncation)
  • Commands and keyboard shortcuts
  • Custom UI (footers, headers, editors, overlays)
  • Git integration (checkpoints, auto-commit)
  • System prompt modifications and custom compaction
  • External integrations (SSH, file watchers, system theme sync)
  • Custom providers (Anthropic with custom streaming, GitLab Duo)

plugins/pi-example-plugin/

An experimental plugin package that Pi automatically builds into separate Session-worker and TUI Chord facets.

Documentation