---
name: pi-subagent-ui
description: Delegate focused review, testing, planning, research, and analysis work to configured Pi subagents through the `subagent` tool. Supports parallel/chain runs, background fire-and-forget runs, and child→parent intercom.
---

# Pi Subagent UI

Use this skill when specialized or parallel subagent work would improve quality without stuffing the full parent transcript into each child.

## Required First Step

Before every `subagent` call, read the injected "Available subagents for the `subagent` tool" list. It contains each usable agent's `name`, optional `id`, source, tools/model hints, and description.

Use only an exact `name` or `id` from that list. Do not invent generic names such as `pi`, `reviewer`, `tester`, `analyst`, or `planner` unless they appear in the list.

## How To Choose

- Match the task to the agent description.
- Prefer a specialized configured agent when its description fits.
- For generic work, choose the most general configured agent from the list.
- Use `agentScope: "both"` only when you intentionally want project-local `.pi/agents` definitions included.

## How To Invoke

Single subagent:

```ts
subagent({
  agent: "exact-agent-name-or-id",
  task: "Review the current diff for correctness and edge cases"
})
```

Parallel subagents:

```ts
subagent({
  tasks: [
    { agent: "exact-agent-name-or-id", task: "Research the current market context" },
    { agent: "another-exact-agent-name-or-id", task: "Review the implementation risks" }
  ],
  concurrency: 2
})
```

Chain mode (each task can embed the previous output via `{previous}`):

```ts
subagent({
  chain: [
    { agent: "exact-agent-name-or-id", task: "Analyze the current implementation" },
    { agent: "another-exact-agent-name-or-id", task: "Create an execution plan from this analysis:\n{previous}" }
  ]
})
```

## Background runs

For long-running work, set `background: true`. The tool returns immediately with a `runId`; you can keep working and you'll be notified when it finishes.

```ts
subagent({ tasks: [/* … */], background: true })   // → runId
subagent_status({ runId: "run_…" })                 // non-blocking snapshot
subagent_result({ runId: "run_…" })                 // full finalText + usage
await_subagent({ runId: "run_…" })                  // block until done
```

## Intercom (child → parent)

When a child may need information only the parent has, set `allowIntercom: true`. The child can then call `ask_parent` (blocks until you answer), `notify_parent` (one-way), or `update_progress`. Answer a child's question with `reply_subagent`.

```ts
subagent({
  agent: "implementer",
  task: "Add feature X; ask me if the API contract is ambiguous",
  allowIntercom: true
})
// child calls ask_parent("…") → you answer:
reply_subagent({ runId: "run_…", taskId: "task_1", message: "Use POST /v2" })
```

Use intercom sparingly — keep children autonomous by default.

## Agent Sources

The subagent tool discovers agents from:

1. pi-web agents configured in `~/.pi/agent/agents.json`.
2. User-level markdown agents in `~/.pi/agent/agents/*.md`.
3. Project-local markdown agents in `.pi/agents/*.md` when `agentScope` includes project.

## Guardrails

- Keep child prompts concise and task-specific.
- Ask for concise final outputs.
- Prefer read-only work unless the user explicitly wants implementation.
- Never call `subagent` with an agent name that was not listed in the injected available-subagents context.
- Use `background: true` for long-running work so you can continue; you will be notified on completion.
- Use `allowIntercom: true` only when you expect the child may genuinely need to ask you something.
