@gjczone/pi-swarm

Agent Swarm & Team for pi-coding-agent. Single to 128 subagents: parallel swarm or collaborative team with mailbox. Live TUI, rate-limit retries, crash recovery. Ported from kimi-code, inspired by pi-crew.

Packages

Package details

extension

Install @gjczone/pi-swarm from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:@gjczone/pi-swarm
Package
@gjczone/pi-swarm
Version
0.3.5
Published
Jun 25, 2026
Downloads
593/mo · 593/wk
Author
gjczone
License
MIT
Types
extension
Size
399.4 KB
Dependencies
2 dependencies · 1 peer
Pi manifest JSON
{
  "extensions": [
    "./dist"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README

@gjczone/pi-swarm

Early release — stability not guaranteed. This is an initial version. Expect rough edges. Bug reports, feedback, feature requests, and PRs are very welcome.

Think of it as kimi-code's AgentSwarm + Claude Code's agent teams — inside pi. Parallel swarm agents and collaborative role-based teams, all dynamically spawned with no preset configuration.

What It Does

Swarm — 1 to 128 parallel agents. Like kimi-code's AgentSwarm: one template, many items, running simultaneously. Also works for single subagent delegation. Each agent is an isolated pi --print child process with its own context window.

Team — collaborative agents. Like Claude Code's agent teams or pi-crew: role-based agents (explorer, planner, coder, reviewer, tester) working in sequence. Each phase agent receives context from previous phases via a shared mailbox. Every agent runs as an independent child process. Optional per-role model tier routing: use a cheaper/faster model for exploration while keeping reasoning-heavy roles on the default model.

All agents are created on-the-fly. No agents/*.md files. The main agent decides what to spawn based on the task.

Install

pi install npm:@gjczone/pi-swarm@latest

How to Use

Swarm — "Do this to all of these" (or just one)

Use for 1 to 128 items — same interface, same isolation.

Audit src/auth.ts for security issues — use a subagent
Review every file in src/ for bugs — use a swarm
Run a security audit on these five packages in parallel: auth, api, db, cache, middleware

Or the slash command:

/swarm Find deprecated API usage across the codebase

Team — "Plan this, build it, review it"

Implement user login with JWT — use a team with planner, coder, and reviewer
Add Redis caching — explore the codebase first, then plan, implement, review, test

Or:

/swarm-team Refactor the auth module end-to-end

Resume Failed Work

If agents fail, the LLM gets resume_agent_ids and can retry:

Two of the five swarm reviews failed — retry those

Cancel Mid-Run

Press Ctrl+C during a swarm or team run. Completed agents are preserved and results are final (no post-cancellation mutation). In-progress agents are cancelled gracefully and their partial work discarded. For teams, completed phases are saved and returned as partial results. Timeout errors are correctly surfaced instead of being lost in abort/exit races.

Runtime Files

State is stored under .pi/swarm/state/. The extension auto-creates .pi/ if it doesn't exist, and auto-appends .pi/swarm/state/ to the project's .gitignore.

.pi/swarm/state/runs/{runId}/
  manifest.json          # Run metadata, agent IDs, timestamps
  tasks.json             # Task graph, per-phase status
  events.jsonl           # Append-only event log
  agents/{agentId}/
    status.json          # Per-agent status snapshot
    output.log           # Full agent session output (header, raw stdout, footer)
  mailbox/               # Team inter-agent messages
    inbox.jsonl
    outbox.jsonl
    delivery.json

Runs auto-clean: completed runs deleted after 7 days, stale runs (30min no heartbeat) marked abandoned.

Settings

Default max concurrency is 5. Recommended: 3-10. Can be set to any positive integer.

Settings file Scope
.pi/settings.json Project (current directory)
~/.pi/agent/settings.json Global (all projects)
{
  "pi-swarm": {
    "maxConcurrency": 8
  }
}

Priority: project settings > global settings > PI_SWARM_MAX_CONCURRENCY env var.

Lower values (3-5) are safer for API rate limits. Values above 10 work if your provider allows high concurrent requests. No hard upper limit.

Team Model Tier

When using SwarmTeam, you can configure a lightweight model for exploration roles to reduce costs:

{
  "pi-swarm": {
    "smallModel": "deepseek/deepseek-v4-flash"
  }
}

The explorer and tester roles (when assigned to a phase) automatically use the small model. Other roles (planner, coder, reviewer, fixer) use the default model unless overridden. No preset agents — you define phases and assign roles via the tool schema. Per-phase overrides are available via modelTier and model fields.

Credits

100% vibe-coded with deepseek-v4-pro, doubao-seed-2.1-pro, and doubao-seed-2.1-turbo. Architecture ported from MoonshotAI/kimi-code. Code implementation patterns inspired by pi-crew. Agent team workflow approach inspired by Claude Code. Thank you to all these projects for their excellent work.

License

MIT