@fosterg4/pi-subagent

extensionmaintained

Delegate tasks to specialized subagents with isolated context windows, structured JSON handoff, contract schemas, and live TUI streaming

by · v1.0.7 · published 1mo ago

$ pi install npm:@fosterg4/pi-subagent
downloads/mo
0
stars
0
last push
1mo ago
open issues
1

Signals

license: MITtestspi manifest: missinginstall size: —deps: 0peer deps: 0

Download trend

1.2K downloads · last 12 weeks (weekly)

README

@fosterg4/pi-subagent

npm version

Delegate complex tasks to specialized sub-agents with isolated context windows, structured JSON handoff, contract schemas, and live TUI streaming — all within pi.

Features

  • Isolated context — Each subagent runs in a separate pi process with its own context window
  • Three execution modes — Single, parallel (max 8, concurrency 4), and chain (sequential with data handoff)
  • Structured JSON handoff — Agents pass typed data between each other, not freeform markdown
  • Contract schemasinputSchema/outputSchema in agent frontmatter ensures valid handoffs
  • Live TUI streaming — Subagent tool calls (read, bash, grep, etc.) stream in real-time
  • Bundled agents — 4 built-in agents ready to use: scout, planner, reviewer, worker
  • Workflow prompts/implement, /scout-and-plan, /implement-and-review commands

Installation

pi install npm:@fosterg4/pi-subagent

For a quick test without installing:

pi -e npm:@fosterg4/pi-subagent

Usage

Single agent

Ask the LLM to use a subagent:

Use scout to find all authentication code in the project

The LLM will call the subagent tool with { agent: "scout", task: "..." }.

Parallel execution

Run 2 scouts in parallel: one to find models, one to find providers

Chained workflow

Use a chain: first have scout find the read tool, then have planner suggest improvements

Workflow prompts

/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

Bundled Agents

AgentPurposeDefault Model
scoutFast codebase recon — returns structured findingsclaude-haiku-4-5
plannerCreates implementation plans from context & requirementsclaude-sonnet-4-5
reviewerCode review — quality, security, maintainabilityclaude-sonnet-4-5
workerGeneral-purpose implementation with full capabilitiesclaude-sonnet-4-5

Each agent has a defined inputSchema and outputSchema in its frontmatter, ensuring structured data flows between chained agents.

Tool Parameters

The subagent tool accepts three mutually exclusive modes:

Single mode

{
  "agent": "scout",
  "task": "Find all authentication code",
  "cwd": "/optional/working/directory"
}

Parallel mode

{
  "tasks": [
    { "agent": "scout", "task": "Find models" },
    { "agent": "scout", "task": "Find providers" }
  ]
}

Chain mode

{
  "chain": [
    { "agent": "scout", "task": "Investigate the codebase" },
    { "agent": "planner", "task": "Create a plan from: {previous}" }
  ]
}

Common options

OptionTypeDefaultDescription
agentScope"user", "project", "both""user"Which agent directories to search
confirmProjectAgentsbooleantruePrompt before running project agents
cwdstringcurrent dirWorking directory for subprocess

Custom Agents

Create your own agents as .md files with YAML frontmatter:

---
name: my-agent
description: What this agent does
tools: read, grep, find, ls, bash
model: claude-haiku-4-5
inputSchema:
  type: object
  properties:
    query:
      type: string
  required: [query]
outputSchema:
  type: object
  properties:
    result:
      type: string
  required: [result]
---

System prompt for the agent goes here.

Agent locations (priority: project > user > bundled):

  • ~/.pi/agent/agents/*.md — User-level (always loaded)
  • .pi/agents/*.md — Project-level (requires agentScope: "project" or "both")
  • Bundled with package — Lowest priority, always available

Security

  • User agents (~/.pi/agent/agents/): Always trusted
  • Project agents (.pi/agents/): Requires confirmation prompt before execution
  • Bundled agents: Trusted by virtue of package installation

Development

# Clone and test locally
git clone https://github.com/fosterg4/pi-subagent.git
cd pi-subagent

# Test with pi
pi -e ./index.ts

# Publish
npm publish --access public

License

MIT