← Catalog

@piotr-oles/pi-subagents

Pi Agent extension: spawn specialized subagents with isolated sessions

Package

Install

Install with PiG

pig install npm:@piotr-oles/pi-subagents

Install with Pi

pi install npm:@piotr-oles/pi-subagents
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "extensions": [
    "./src/index.ts"
  ]
}

README

Written by the package's publisher, shown as published in version 1.0.5 (README.md). PiG does not review it.

pi-subagents

A pi coding agent extension that lets the agent spawn specialized subagents — each running in its own isolated session with its own model, tools, and instructions.

Install

pi install npm:@piotr-oles/pi-subagents

Agent templates

Define agents as markdown files with YAML frontmatter. Two locations are supported:

LocationScope
~/.pi/agent/subagents/<name>.mdGlobal — available in all projects
.pi/subagents/<name>.mdProject — available in current project only

A project template overrides a global template with the same name.

Example .pi/subagents/coder.md:

---
description: Specialist for writing and editing code
model: anthropic/claude-opus-4-5
thinking: low
max_turns: 30
included_tools: bash, read, edit, write
---

You are an expert software engineer. Focus only on the assigned task.
Write clean, well-tested code. Do not ask for clarification — make reasonable assumptions.

Frontmatter fields:

FieldTypeDescription
descriptionstringShort description shown in the UI. Defaults to the filename.
modelstringModel to use (e.g. anthropic/claude-haiku-4-5). Inherits from parent session if omitted.
thinkingstringThinking level: off, minimal, low, medium, high, xhigh.
max_turnsnumberHard turn limit. When reached the agent is given grace turns to wrap up.
grace_turnsnumberExtra turns after max_turns before the agent is force-stopped.
enabledbooleanSet to false to disable this agent type without deleting the file.
included_toolsstringComma-separated list of tool names available to this agent. Omit to inherit all tools from the parent session.
included_skillsstringComma-separated list of skill names available to this agent. Omit to inherit all skills.
included_subagentsstringComma-separated list of subagent template names this agent may spawn.

If no matching template is found the agent falls back to general-purpose, or a plain default if that is also absent.

Tools

subagent

Spawns a subagent to handle a task, or follows up on a previously completed one.

ParameterTypeDescription
namestringName of the agent template to use. Required for both spawn and follow-up.
idstringID of a done subagent to follow-up. Omit when spawning fresh.
descriptionstringShort description of the task (shown in UI).
promptstringTask prompt sent to the subagent.

Blocks until the subagent completes and returns its result inline. To follow up on a finished subagent, call subagent again with the id returned in the previous result plus a new prompt.

How it works

  1. On before_agent_start, templates are reloaded from disk.
  2. When subagent is called, the extension resolves the template, builds an AgentConfig, and starts an isolated pi session.
  3. The subagent session inherits the parent's model registry and working directory but gets its own system prompt built from the template's instructions.
  4. The subagent tool is excluded from subagent sessions unless included_subagents is set — only then can a subagent spawn further subagents (limited to the listed templates).
  5. A concurrency queue limits how many agents run simultaneously; excess agents are queued and started as slots free up.

Flags

pi --pi-subagents-max-concurrent 4    # max agents running at once (default: 4)

Or via environment variable:

PI_SUBAGENTS_MAX_CONCURRENT=2 pi

subagent:templates command

Opens an interactive menu listing all loaded agent templates with their source (global ◦ / project •) and model. Run via the pi command palette.

Development

npm install
npm test
npm run typecheck
npm run check

To test changes manually, pass the source entry point directly to pi:

pi -ne -e packages/pi-subagents/src/index.ts