Multi-Agent Patterns
✓ Fresh · 2026-02-24Pi supports multiple multi-agent patterns through extensions. These enable sophisticated orchestration where multiple agent instances collaborate to solve complex tasks.
Pattern Overview
Agent Teams (Dispatcher Pattern)
The agent-team.ts extension implements a dispatcher pattern where a primary agent evaluates requests and delegates to specialists.
How It Works
- The primary agent receives the user's request
- It evaluates which specialist is best suited
- It delegates via the
dispatch_agenttool - The specialist completes the work and returns the result
- The primary agent presents the final answer
Configuration
Teams are defined in .pi/agents/teams.yaml:
teams:
- name: "fullstack"
agents:
- name: "frontend"
system: "You are a frontend specialist. Expert in React, CSS, and accessibility."
triggers:
- "UI"
- "component"
- "CSS"
- "styling"
- name: "backend"
system: "You are a backend specialist. Expert in APIs, databases, and server architecture."
triggers:
- "API"
- "database"
- "server"
- "endpoint"
- name: "devops"
system: "You are a DevOps specialist. Expert in CI/CD, Docker, and infrastructure."
triggers:
- "deploy"
- "Docker"
- "CI/CD"
- "infrastructure"Running
pi -e extensions/agent-team.tsAgent Chains (Sequential Pipeline)
The agent-chain.ts extension implements sequential pipelines where each agent's output feeds into the next.
How It Works
- Agent 1 receives the initial prompt
- Agent 1's output becomes
$INPUTfor Agent 2 - Agent 2's output becomes
$INPUTfor Agent 3 - And so on through the chain
Variables
| Variable | Contains |
|---|---|
$INPUT | Output from the previous agent in the chain |
$ORIGINAL | The original user prompt (available to all agents) |
Configuration
Chains are defined in .pi/agents/agent-chain.yaml:
chains:
- name: "plan-build-review"
steps:
- agent: "planner"
system: "You are a software architect. Create a detailed implementation plan."
- agent: "builder"
system: "You are a senior developer. Implement the plan from $INPUT."
- agent: "reviewer"
system: "You are a code reviewer. Review the implementation from $INPUT against the original request: $ORIGINAL."Running
pi -e extensions/agent-chain.tsSub-Agents (Background Workers)
The subagent-widget.ts extension spawns background Pi agent instances with live progress tracking.
Usage
/sub Refactor the auth module to use JWT tokens
/sub Write integration tests for the payment service
/sub Update the API documentationEach /sub command spawns a background agent that works independently. Live progress widgets appear above the editor showing each sub-agent's status.
Running
pi -e extensions/subagent-widget.tsPi-Pi (Meta-Agent)
The pi-pi.ts extension is a meta-agent that uses parallel expert researchers to build Pi extensions collaboratively.
How It Works
- You describe the extension you want to build
- Pi-Pi spawns multiple expert researcher agents in parallel
- Each expert focuses on a different aspect (API design, event handling, UI, testing)
- Results are synthesized into a complete extension
Running
pi -e extensions/pi-pi.tsExpert Agents
Located in .pi/agents/pi-pi/:
.pi/agents/pi-pi/
├── api-expert.md # Extension API patterns
├── events-expert.md # Event system knowledge
├── ui-expert.md # TUI widget patterns
└── testing-expert.md # Extension testingAgent Personas
Define agent personas as Markdown files in .pi/agents/:
<!-- .pi/agents/code-reviewer.md -->
# Code Reviewer
You are a meticulous code reviewer. Focus on:
- Security vulnerabilities
- Performance bottlenecks
- Code maintainability
- Test coverage gaps
Always provide specific line references and actionable suggestions.Switch between personas using the system-select.ts extension:
pi -e extensions/system-select.ts
# Then use /system to switch personasProject Structure
.pi/
├── agents/
│ ├── pi-pi/ # Meta-agent expert definitions
│ │ ├── api-expert.md
│ │ ├── events-expert.md
│ │ └── ui-expert.md
│ ├── agent-chain.yaml # Pipeline definitions
│ ├── teams.yaml # Team configurations
│ ├── code-reviewer.md # Agent persona
│ └── architect.md # Agent persona
├── skills/ # Skills available to all agents
└── settings.jsonChoosing a Pattern
| Pattern | Best For | Complexity |
|---|---|---|
| Agent Teams | Diverse tasks needing different expertise | Medium |
| Agent Chains | Sequential workflows (plan > build > review) | Medium |
| Sub-Agents | Parallel independent tasks | Low |
| Pi-Pi | Building extensions collaboratively | High |
| Persona Switching | Changing agent behavior mid-session | Low |