packages/coding-agent/examples/extensions/subagent/README.md
Delegate tasks to specialized subagents with isolated context windows.
pi processsubagent/
├── README.md # This file
├── index.ts # The extension (entry point)
├── agents.ts # Agent discovery logic
├── agents/ # Sample agent definitions
│ ├── scout.md # Fast recon, returns compressed context
│ ├── planner.md # Creates implementation plans
│ ├── reviewer.md # Code review
│ └── worker.md # General-purpose (full capabilities)
└── prompts/ # Workflow presets (prompt templates)
├── implement.md # scout -> planner -> worker
├── scout-and-plan.md # scout -> planner (no implementation)
└── implement-and-review.md # worker -> reviewer -> worker
From the repository root, symlink the files:
# Symlink the extension (must be in a subdirectory with index.ts)
mkdir -p ~/.pi/agent/extensions/subagent
ln -sf "$(pwd)/packages/coding-agent/examples/extensions/subagent/index.ts" ~/.pi/agent/extensions/subagent/index.ts
ln -sf "$(pwd)/packages/coding-agent/examples/extensions/subagent/agents.ts" ~/.pi/agent/extensions/subagent/agents.ts
# Symlink agents
mkdir -p ~/.pi/agent/agents
for f in packages/coding-agent/examples/extensions/subagent/agents/*.md; do
ln -sf "$(pwd)/$f" ~/.pi/agent/agents/$(basename "$f")
done
# Symlink workflow prompts
mkdir -p ~/.pi/agent/prompts
for f in packages/coding-agent/examples/extensions/subagent/prompts/*.md; do
ln -sf "$(pwd)/$f" ~/.pi/agent/prompts/$(basename "$f")
done
This tool executes a separate pi subprocess with a delegated system prompt and tool/model configuration.
Project-local agents (.pi/agents/*.md) are repo-controlled prompts that can instruct the model to read files, run bash commands, etc.
Default behavior: Only loads user-level agents from ~/.pi/agent/agents.
To enable project-local agents, pass agentScope: "both" (or "project"). Only do this for repositories you trust.
When running interactively, the tool prompts for confirmation before running project-local agents. Set confirmProjectAgents: false to disable.
Use scout to find all authentication code
Run 2 scouts in parallel: one to find models, one to find providers
Use a chain: first have scout find the read tool, then have planner suggest improvements
/implement add Redis caching to the session store
/scout-and-plan refactor auth to support OAuth
/implement-and-review add input validation to API endpoints
| Mode | Parameter | Description |
|---|---|---|
| Single | { agent, task } | One agent, one task |
| Parallel | { tasks: [...] } | Multiple agents run concurrently (max 8, 4 concurrent) |
| Chain | { chain: [...] } | Sequential with {previous} placeholder |
Collapsed view (default):
3 turns ↑input ↓output RcacheRead WcacheWrite $cost ctx:contextTokens modelExpanded view (Ctrl+O):
Parallel mode streaming:
Tool call formatting (mimics built-in tools):
$ command for bashread ~/path:1-10 for readgrep /pattern/ in ~/path for grepAgents are markdown files with YAML frontmatter:
---
name: my-agent
description: What this agent does
tools: read, grep, find, ls
model: claude-haiku-4-5
---
System prompt for the agent goes here.
Locations:
~/.pi/agent/agents/*.md - User-level (always loaded).pi/agents/*.md - Project-level (only with agentScope: "project" or "both")Project agents override user agents with the same name when agentScope: "both".
| Agent | Purpose | Model | Tools |
|---|---|---|---|
scout | Fast codebase recon | Haiku | read, grep, find, ls, bash |
planner | Implementation plans | Sonnet | read, grep, find, ls |
reviewer | Code review | Sonnet | read, grep, find, ls, bash |
worker | General-purpose | Sonnet | (all default) |
| Prompt | Flow |
|---|---|
/implement <query> | scout → planner → worker |
/scout-and-plan <query> | scout → planner |
/implement-and-review <query> | worker → reviewer → worker |