@fitchmultz/pi-subagents 0.0.0-stage → 0.44.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1654 -0
- package/LICENSE +21 -0
- package/README.md +1533 -2
- package/agents/context-builder.md +97 -0
- package/agents/debugger.md +51 -0
- package/agents/delegate.md +13 -0
- package/agents/fixer.md +37 -0
- package/agents/oracle.md +71 -0
- package/agents/planner.md +72 -0
- package/agents/researcher.md +51 -0
- package/agents/reviewer-claude.md +69 -0
- package/agents/reviewer-gpt.md +68 -0
- package/agents/reviewer-ponytail.md +82 -0
- package/agents/reviewer-security.md +81 -0
- package/agents/reviewer.md +69 -0
- package/agents/scout.md +66 -0
- package/agents/ui-designer.md +51 -0
- package/agents/watcher.md +26 -0
- package/agents/worker.md +46 -0
- package/agents/writer.md +36 -0
- package/dist/agents/agent-management.js +923 -0
- package/dist/agents/agent-scope.js +7 -0
- package/dist/agents/agent-selection.js +20 -0
- package/dist/agents/agent-serializer.js +100 -0
- package/dist/agents/agents.js +752 -0
- package/dist/agents/chain-serializer.js +367 -0
- package/dist/agents/frontmatter.js +21 -0
- package/dist/agents/identity.js +29 -0
- package/dist/agents/skills.js +570 -0
- package/dist/extension/build-info.js +1 -0
- package/dist/extension/compact-tools.js +112 -0
- package/dist/extension/config.js +22 -0
- package/dist/extension/control-notices.js +29 -0
- package/dist/extension/doctor.js +143 -0
- package/dist/extension/fanout-child.js +326 -0
- package/dist/extension/index.js +577 -0
- package/dist/extension/schemas.js +416 -0
- package/dist/extension/tool-input.js +20 -0
- package/dist/extension/tool-result.js +14 -0
- package/dist/history/canonical-result.js +81 -0
- package/dist/history/database.js +72 -0
- package/dist/history/index.js +199 -0
- package/dist/history/ingest.js +468 -0
- package/dist/history/queries.js +350 -0
- package/dist/history/store.js +216 -0
- package/dist/history/types.js +4 -0
- package/dist/history/worker.js +466 -0
- package/dist/intercom/intercom-bridge.js +112 -0
- package/dist/intercom/live-intercom.js +94 -0
- package/dist/intercom/result-intercom.js +373 -0
- package/dist/pi-intercom/agent-dir.js +10 -0
- package/dist/pi-intercom/bridge.js +750 -0
- package/dist/pi-intercom/broker/broker.js +426 -0
- package/dist/pi-intercom/broker/client.js +492 -0
- package/dist/pi-intercom/broker/framing.js +65 -0
- package/dist/pi-intercom/broker/paths.js +42 -0
- package/dist/pi-intercom/broker/pid.js +66 -0
- package/dist/pi-intercom/broker/spawn.js +221 -0
- package/dist/pi-intercom/config.js +102 -0
- package/dist/pi-intercom/index.js +2942 -0
- package/dist/pi-intercom/reply-tracker.js +182 -0
- package/dist/pi-intercom/session-targets.js +128 -0
- package/dist/pi-intercom/subagent-live-events.js +132 -0
- package/dist/pi-intercom/topics.js +157 -0
- package/dist/pi-intercom/types.js +163 -0
- package/dist/pi-intercom/ui/compose.js +269 -0
- package/dist/pi-intercom/ui/inline-message.js +80 -0
- package/dist/pi-intercom/ui/session-list.js +124 -0
- package/dist/runs/background/async-control.js +95 -0
- package/dist/runs/background/async-execution.js +676 -0
- package/dist/runs/background/async-job-tracker.js +383 -0
- package/dist/runs/background/async-result-file.js +58 -0
- package/dist/runs/background/async-resume.js +305 -0
- package/dist/runs/background/async-status.js +442 -0
- package/dist/runs/background/completion-dedupe.js +69 -0
- package/dist/runs/background/completion-delivery.js +245 -0
- package/dist/runs/background/notify.js +71 -0
- package/dist/runs/background/parallel-groups.js +55 -0
- package/dist/runs/background/result-watcher.js +426 -0
- package/dist/runs/background/run-id-resolver.js +64 -0
- package/dist/runs/background/run-status.js +382 -0
- package/dist/runs/background/stale-run-reconciler.js +335 -0
- package/dist/runs/background/subagent-runner-launcher.js +55 -0
- package/dist/runs/background/subagent-runner.js +1872 -0
- package/dist/runs/background/top-level-async.js +5 -0
- package/dist/runs/foreground/chain-clarify.js +1152 -0
- package/dist/runs/foreground/clarify-invocation.js +72 -0
- package/dist/runs/foreground/execution-input.js +423 -0
- package/dist/runs/foreground/foreground-control.js +817 -0
- package/dist/runs/foreground/question-control.js +88 -0
- package/dist/runs/foreground/run-async-path.js +205 -0
- package/dist/runs/foreground/subagent-executor.js +442 -0
- package/dist/runs/foreground/subagent-params.js +165 -0
- package/dist/runs/foreground/wait-run.js +141 -0
- package/dist/runs/shared/acceptance-contract.js +253 -0
- package/dist/runs/shared/acceptance-evaluation.js +256 -0
- package/dist/runs/shared/acceptance-finalization.js +280 -0
- package/dist/runs/shared/acceptance-reports.js +147 -0
- package/dist/runs/shared/acceptance.js +4 -0
- package/dist/runs/shared/chain-outputs.js +110 -0
- package/dist/runs/shared/child-attempt.js +693 -0
- package/dist/runs/shared/child-execution-cwd.js +96 -0
- package/dist/runs/shared/child-observations.js +114 -0
- package/dist/runs/shared/claude-code.js +199 -0
- package/dist/runs/shared/completion-guard.js +31 -0
- package/dist/runs/shared/dynamic-fanout.js +274 -0
- package/dist/runs/shared/history-index.js +72 -0
- package/dist/runs/shared/mcp-direct-tool-allowlist.js +334 -0
- package/dist/runs/shared/model-fallback.js +185 -0
- package/dist/runs/shared/mutating-tool-guard.js +170 -0
- package/dist/runs/shared/native-finalization.js +101 -0
- package/dist/runs/shared/native-usage.js +153 -0
- package/dist/runs/shared/nested-events.js +700 -0
- package/dist/runs/shared/nested-path.js +48 -0
- package/dist/runs/shared/nested-render.js +108 -0
- package/dist/runs/shared/parallel-utils.js +61 -0
- package/dist/runs/shared/parent-receipts.js +68 -0
- package/dist/runs/shared/parent-usage.js +121 -0
- package/dist/runs/shared/pi-args.js +310 -0
- package/dist/runs/shared/pi-spawn.js +52 -0
- package/dist/runs/shared/run-history-queries.js +45 -0
- package/dist/runs/shared/run-history.js +110 -0
- package/dist/runs/shared/run-id-ambiguity.js +4 -0
- package/dist/runs/shared/run-records.js +679 -0
- package/dist/runs/shared/session-cwd-preload.js +33 -0
- package/dist/runs/shared/single-output.js +222 -0
- package/dist/runs/shared/streaming-text.js +15 -0
- package/dist/runs/shared/structured-output.js +55 -0
- package/dist/runs/shared/subagent-control.js +179 -0
- package/dist/runs/shared/subagent-prompt-runtime.js +197 -0
- package/dist/runs/shared/subagent-tool-loop-guard.js +66 -0
- package/dist/runs/shared/supervisor-questions.js +350 -0
- package/dist/runs/shared/workflow-graph.js +214 -0
- package/dist/runs/shared/workflow-policy.js +84 -0
- package/dist/runs/shared/worktree.js +525 -0
- package/dist/shared/agent-context-policy.js +126 -0
- package/dist/shared/artifacts.js +96 -0
- package/dist/shared/atomic-json.js +13 -0
- package/dist/shared/cooperative.js +20 -0
- package/dist/shared/execution-cwd.js +14 -0
- package/dist/shared/file-coalescer.js +21 -0
- package/dist/shared/fork-context.js +49 -0
- package/dist/shared/formatters.js +85 -0
- package/dist/shared/journal-reader.js +407 -0
- package/dist/shared/lazy-tools.js +32 -0
- package/dist/shared/model-info.js +68 -0
- package/dist/shared/native-session.js +15 -0
- package/dist/shared/native-tui.js +18 -0
- package/dist/shared/native-typebox.js +20 -0
- package/dist/shared/post-exit-stdio-guard.js +197 -0
- package/dist/shared/prompt-sections.js +8 -0
- package/dist/shared/session-entries.js +52 -0
- package/dist/shared/session-identity.js +14 -0
- package/dist/shared/settings.js +254 -0
- package/dist/shared/status-format.js +111 -0
- package/dist/shared/temp-root.js +114 -0
- package/dist/shared/types.js +207 -0
- package/dist/shared/ui-mode.js +3 -0
- package/dist/shared/utils.js +334 -0
- package/dist/slash/prompt-template-bridge.js +298 -0
- package/dist/slash/slash-bridge.js +116 -0
- package/dist/slash/slash-commands.js +607 -0
- package/dist/slash/slash-live-state.js +246 -0
- package/dist/tui/action-hints.js +75 -0
- package/dist/tui/agent-history.js +197 -0
- package/dist/tui/agent-view.js +1656 -0
- package/dist/tui/render.js +1515 -0
- package/docs/intercom-bridge.md +212 -0
- package/docs/intercom.md +581 -0
- package/docs/performance.md +121 -0
- package/package.json +102 -4
- package/prompts/gather-context-and-clarify.md +14 -0
- package/prompts/parallel-cleanup.md +62 -0
- package/prompts/parallel-context-build.md +56 -0
- package/prompts/parallel-handoff-plan.md +62 -0
- package/prompts/parallel-research.md +51 -0
- package/prompts/parallel-review.md +59 -0
- package/prompts/review-loop.md +42 -0
- package/scripts/build.mjs +134 -0
- package/scripts/check-compat.mjs +48 -0
- package/scripts/compat-host.mjs +19 -0
- package/scripts/intercom-bridge-credentials.mjs +143 -0
- package/scripts/intercom-remote.mjs +103 -0
- package/scripts/linux-smoke.sh +51 -0
- package/scripts/local-install-smoke.mjs +66 -0
- package/scripts/native-package-smoke.mjs +82 -0
- package/scripts/package-smoke.mjs +209 -0
- package/scripts/prepare.mjs +67 -0
- package/scripts/real-pi-smoke.mjs +415 -0
- package/scripts/run-tests.mjs +149 -0
- package/skills/pi-intercom/SKILL.md +113 -0
- package/skills/pi-intercom/evals/evals.json +29 -0
- package/skills/pi-intercom/evals/trigger-evals.json +47 -0
- package/skills/pi-intercom/references/peer-sessions.md +69 -0
- package/skills/pi-subagents/SKILL.md +76 -0
- package/skills/pi-subagents/evals/evals.json +29 -0
- package/skills/pi-subagents/evals/trigger-evals.json +42 -0
- package/skills/pi-subagents/references/full-orchestration-guide.md +863 -0
- package/src/agents/agent-management.ts +813 -0
- package/src/agents/agent-scope.ts +7 -0
- package/src/agents/agent-selection.ts +23 -0
- package/src/agents/agent-serializer.ts +99 -0
- package/src/agents/agents.ts +916 -0
- package/src/agents/chain-serializer.ts +329 -0
- package/src/agents/frontmatter.ts +21 -0
- package/src/agents/identity.ts +30 -0
- package/src/agents/skills.ts +637 -0
- package/src/extension/build-info.ts +2 -0
- package/src/extension/compact-tools.ts +114 -0
- package/src/extension/config.ts +23 -0
- package/src/extension/control-notices.ts +47 -0
- package/src/extension/doctor.ts +171 -0
- package/src/extension/fanout-child.ts +312 -0
- package/src/extension/index.ts +649 -0
- package/src/extension/schemas.ts +444 -0
- package/src/extension/tool-input.ts +19 -0
- package/src/extension/tool-result.ts +16 -0
- package/src/history/canonical-result.ts +62 -0
- package/src/history/database.ts +59 -0
- package/src/history/index.ts +156 -0
- package/src/history/ingest.ts +349 -0
- package/src/history/queries.ts +241 -0
- package/src/history/store.ts +203 -0
- package/src/history/types.ts +166 -0
- package/src/history/worker.ts +321 -0
- package/src/intercom/intercom-bridge.ts +123 -0
- package/src/intercom/live-intercom.ts +104 -0
- package/src/intercom/result-intercom.ts +429 -0
- package/src/pi-intercom/agent-dir.ts +9 -0
- package/src/pi-intercom/bridge.ts +668 -0
- package/src/pi-intercom/broker/broker.ts +463 -0
- package/src/pi-intercom/broker/client.ts +558 -0
- package/src/pi-intercom/broker/framing.ts +77 -0
- package/src/pi-intercom/broker/paths.ts +47 -0
- package/src/pi-intercom/broker/pid.ts +59 -0
- package/src/pi-intercom/broker/spawn.ts +248 -0
- package/src/pi-intercom/config.ts +142 -0
- package/src/pi-intercom/index.ts +2929 -0
- package/src/pi-intercom/reply-tracker.ts +211 -0
- package/src/pi-intercom/session-targets.ts +172 -0
- package/src/pi-intercom/subagent-live-events.ts +133 -0
- package/src/pi-intercom/topics.ts +125 -0
- package/src/pi-intercom/types.ts +271 -0
- package/src/pi-intercom/ui/compose.ts +289 -0
- package/src/pi-intercom/ui/inline-message.ts +92 -0
- package/src/pi-intercom/ui/session-list.ts +139 -0
- package/src/runs/background/async-control.ts +89 -0
- package/src/runs/background/async-execution.ts +850 -0
- package/src/runs/background/async-job-tracker.ts +385 -0
- package/src/runs/background/async-result-file.ts +62 -0
- package/src/runs/background/async-resume.ts +333 -0
- package/src/runs/background/async-status.ts +481 -0
- package/src/runs/background/completion-dedupe.ts +79 -0
- package/src/runs/background/completion-delivery.ts +195 -0
- package/src/runs/background/notify.ts +123 -0
- package/src/runs/background/parallel-groups.ts +53 -0
- package/src/runs/background/result-watcher.ts +423 -0
- package/src/runs/background/run-id-resolver.ts +69 -0
- package/src/runs/background/run-status.ts +384 -0
- package/src/runs/background/stale-run-reconciler.ts +369 -0
- package/src/runs/background/subagent-runner-launcher.ts +56 -0
- package/src/runs/background/subagent-runner.ts +2053 -0
- package/src/runs/background/top-level-async.ts +13 -0
- package/src/runs/foreground/chain-clarify.ts +1340 -0
- package/src/runs/foreground/clarify-invocation.ts +77 -0
- package/src/runs/foreground/execution-input.ts +467 -0
- package/src/runs/foreground/foreground-control.ts +821 -0
- package/src/runs/foreground/question-control.ts +82 -0
- package/src/runs/foreground/run-async-path.ts +243 -0
- package/src/runs/foreground/subagent-executor.ts +501 -0
- package/src/runs/foreground/subagent-params.ts +320 -0
- package/src/runs/foreground/wait-run.ts +124 -0
- package/src/runs/shared/acceptance-contract.ts +257 -0
- package/src/runs/shared/acceptance-evaluation.ts +275 -0
- package/src/runs/shared/acceptance-finalization.ts +353 -0
- package/src/runs/shared/acceptance-reports.ts +152 -0
- package/src/runs/shared/acceptance.ts +33 -0
- package/src/runs/shared/chain-outputs.ts +114 -0
- package/src/runs/shared/child-attempt.ts +623 -0
- package/src/runs/shared/child-execution-cwd.ts +91 -0
- package/src/runs/shared/child-observations.ts +99 -0
- package/src/runs/shared/claude-code.ts +243 -0
- package/src/runs/shared/completion-guard.ts +35 -0
- package/src/runs/shared/dynamic-fanout.ts +295 -0
- package/src/runs/shared/history-index.ts +69 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.ts +376 -0
- package/src/runs/shared/model-fallback.ts +219 -0
- package/src/runs/shared/mutating-tool-guard.ts +194 -0
- package/src/runs/shared/native-finalization.ts +128 -0
- package/src/runs/shared/native-usage.ts +113 -0
- package/src/runs/shared/nested-events.ts +752 -0
- package/src/runs/shared/nested-path.ts +52 -0
- package/src/runs/shared/nested-render.ts +119 -0
- package/src/runs/shared/parallel-utils.ts +153 -0
- package/src/runs/shared/parent-receipts.ts +59 -0
- package/src/runs/shared/parent-usage.ts +121 -0
- package/src/runs/shared/pi-args.ts +350 -0
- package/src/runs/shared/pi-spawn.ts +52 -0
- package/src/runs/shared/run-history-queries.ts +44 -0
- package/src/runs/shared/run-history.ts +100 -0
- package/src/runs/shared/run-id-ambiguity.ts +4 -0
- package/src/runs/shared/run-records.ts +607 -0
- package/src/runs/shared/session-cwd-preload.ts +27 -0
- package/src/runs/shared/single-output.ts +267 -0
- package/src/runs/shared/streaming-text.ts +18 -0
- package/src/runs/shared/structured-output.ts +68 -0
- package/src/runs/shared/subagent-control.ts +219 -0
- package/src/runs/shared/subagent-prompt-runtime.ts +201 -0
- package/src/runs/shared/subagent-tool-loop-guard.ts +89 -0
- package/src/runs/shared/supervisor-questions.ts +415 -0
- package/src/runs/shared/workflow-graph.ts +220 -0
- package/src/runs/shared/workflow-policy.ts +125 -0
- package/src/runs/shared/worktree.ts +635 -0
- package/src/shared/agent-context-policy.ts +184 -0
- package/src/shared/artifacts.ts +95 -0
- package/src/shared/atomic-json.ts +16 -0
- package/src/shared/cooperative.ts +21 -0
- package/src/shared/execution-cwd.ts +14 -0
- package/src/shared/file-coalescer.ts +29 -0
- package/src/shared/fork-context.ts +68 -0
- package/src/shared/formatters.ts +84 -0
- package/src/shared/journal-reader.ts +333 -0
- package/src/shared/lazy-tools.ts +36 -0
- package/src/shared/model-info.ts +81 -0
- package/src/shared/native-session.ts +8 -0
- package/src/shared/native-tui.ts +10 -0
- package/src/shared/native-typebox.ts +14 -0
- package/src/shared/post-exit-stdio-guard.ts +204 -0
- package/src/shared/prompt-sections.ts +10 -0
- package/src/shared/session-entries.ts +49 -0
- package/src/shared/session-identity.ts +18 -0
- package/src/shared/settings.ts +384 -0
- package/src/shared/status-format.ts +123 -0
- package/src/shared/temp-root.ts +107 -0
- package/src/shared/types.ts +1260 -0
- package/src/shared/ui-mode.ts +5 -0
- package/src/shared/utils.ts +342 -0
- package/src/slash/prompt-template-bridge.ts +408 -0
- package/src/slash/slash-bridge.ts +178 -0
- package/src/slash/slash-commands.ts +617 -0
- package/src/slash/slash-live-state.ts +292 -0
- package/src/tui/action-hints.ts +69 -0
- package/src/tui/agent-history.ts +210 -0
- package/src/tui/agent-view.ts +1323 -0
- package/src/tui/render.ts +1550 -0
- package/tsconfig.build.json +12 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,863 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: pi-subagents
|
|
3
|
+
description: "Pi subagent orchestration reference for single, parallel, chain, async/background, forked-context, acceptance, worktree, intercom, status/control, and agent-management workflows. Do not use for Agent Skill maintenance or non-Pi delegation."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Pi Subagents
|
|
7
|
+
|
|
8
|
+
The original agent owns integration, review synthesis, and final delivery. Helpers with delegation enabled may split their assigned work when it saves time or improves quality. Use the available child-safe tools and preserve the assigned scope.
|
|
9
|
+
|
|
10
|
+
Use this skill when the parent orchestrator needs to launch a specialized subagent, compose multiple agents into a workflow, or create/edit agents and chains on demand.
|
|
11
|
+
|
|
12
|
+
## When to Use
|
|
13
|
+
|
|
14
|
+
- **Advisory review**: use fresh-context `reviewer` agents for adversarial code review, or fork to `oracle` when inherited decisions and drift matter
|
|
15
|
+
- **Implementation handoff**: use `oracle` advice when helpful, then `worker` implements within existing authority
|
|
16
|
+
- **Recon and planning**: use `scout` or `context-builder`, then `planner`
|
|
17
|
+
- **Parallel exploration**: run multiple non-conflicting tasks concurrently
|
|
18
|
+
- **Long-running work**: launch async/background runs and inspect them later
|
|
19
|
+
- **Long-running observation**: use ordinary tools for routine waiting and check collection; use `watcher` when ongoing interpretation adds value
|
|
20
|
+
- **Subagent control**: watch needs-attention signals and soft-interrupt only when a delegated run is genuinely blocked
|
|
21
|
+
- **Subagent definition management**: create, update, or override Pi agents and chains for a project
|
|
22
|
+
|
|
23
|
+
## Tool vs Slash Commands
|
|
24
|
+
|
|
25
|
+
Prefer the compact tools for ordinary delegation:
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
agent_runs({ action: "profiles" })
|
|
29
|
+
delegate({ agent: "worker", task: "Implement the approved fix", worktree: true })
|
|
30
|
+
agent_runs({ action: "list" })
|
|
31
|
+
agent_runs({ action: "inspect", id: "<run-id>" })
|
|
32
|
+
agent_runs({ action: "review", id: "<run-id>", decision: "accepted", message: "Checked the evidence." })
|
|
33
|
+
agent_runs({ action: "list", text: "login", sort: "newest", limit: 20 })
|
|
34
|
+
agent_runs({ action: "history", id: "<run-id>", index: 0, limit: 100 })
|
|
35
|
+
agent_runs({ action: "search", query: '"login timeout"', agent: "worker", limit: 20 })
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
These share the full executor, including acceptance and isolated single-writer worktrees. The list prioritizes pending questions, failures/interrupted or unconfirmed work, and completed-but-unreviewed results. Global `agent`/`state`/`text` filters and attention/newest/oldest sorting apply before paging (default 20, maximum 100), never cap retained history. Reuse the returned cursor with the same query, or use `offset`; restart without a cursor when the indexed snapshot changes. `history` requires an owned ID and a child index for multi-child runs, defaults to 100 native-entry previews, and returns an earlier-page cursor. `search` accepts 1–12 lexical words or one quoted phrase, excludes thinking/arguments/hidden payloads, and supports relevance/newest order and owned ID/child/agent filters. Finished attempts keep their own terminal/time boundary even when a continuation shares the source. Browse freshness and excerpts are observations, not canonical completion or delivery proof. For validated full selected bodies, use Agents details/Reply; oversized or changed records fail explicitly. `review` records `accepted` or `needs_changes` separately from execution, validation, and notification; it never launches a repair or reviewer. Use `continue` explicitly for more work. Use `load_subagent` and `subagent(...)` for parallel groups, chains, detailed overrides, and profile administration.
|
|
39
|
+
Humans often use the slash-command layer instead:
|
|
40
|
+
|
|
41
|
+
- `/run` — launch a single agent
|
|
42
|
+
- `/chain` — launch a chain of steps
|
|
43
|
+
- `/parallel` — launch top-level parallel tasks
|
|
44
|
+
- `/run-chain` — launch a saved `.chain.md` or `.chain.json` workflow
|
|
45
|
+
- `/subagents-doctor` — diagnose setup, discovery, async paths, and the paired intercom target
|
|
46
|
+
|
|
47
|
+
Prefer the tool when you are writing agent logic. Prefer the slash commands when
|
|
48
|
+
you are guiding a human through an interactive flow.
|
|
49
|
+
|
|
50
|
+
The repository keeps example prompts for repeatable workflows. Treat them as reusable orchestration recipes. When the user asks for one of these shapes, or when the workflow clearly fits, apply the same pattern directly with `subagent(...)` and other tools:
|
|
51
|
+
- `prompts/parallel-review.md` — fresh-context reviewers with distinct review angles, then synthesis
|
|
52
|
+
- `prompts/review-loop.md` — parent-orchestrated worker, fresh-reviewer, and fix-worker cycles until clean or capped
|
|
53
|
+
- `prompts/parallel-research.md` — combine `researcher` and `scout` for external evidence plus local code context
|
|
54
|
+
- `prompts/parallel-context-build.md` — parallel `context-builder` passes that produce planning handoff context and meta-prompts
|
|
55
|
+
- `prompts/parallel-handoff-plan.md` — external-reference research plus local `context-builder` passes, followed by a synthesis handoff plan and implementation-ready meta-prompt
|
|
56
|
+
- `prompts/gather-context-and-clarify.md` — scout/research first, then ask the user clarifying questions with the available clarification tool (`ask_question` in pi)
|
|
57
|
+
- `prompts/parallel-cleanup.md` — two fresh-context reviewers (deslop + verbosity passes) for an adversarial cleanup review of the current diff
|
|
58
|
+
|
|
59
|
+
## Applying Example Prompt Techniques
|
|
60
|
+
|
|
61
|
+
The examples in `prompts/` encode workflows the parent agent can run on demand. If the user provides a URL, issue, PR, plan, local file, screenshot, or freeform target, treat that target as the primary scope: read or fetch it before launching children, then include it explicitly in every child task. For every fresh child, include relevant exact original user instructions and settled decisions, or readable source references, alongside the bounded assignment. Summaries do not replace those requirements. The harness does not automatically forward the owner's transcript; do not switch to fork as a workaround.
|
|
62
|
+
|
|
63
|
+
### Parallel review technique
|
|
64
|
+
|
|
65
|
+
Use this when the user wants adversarial review of a diff, plan, issue, file, or implemented work. Launch fresh-context `reviewer` agents with distinct angles generated from the actual target. Common angles are correctness/regressions, tests/validation, and simplicity/maintainability; adapt for TypeScript, UI, security, docs, or large structural changes. Reviewers should inspect files and diffs directly, return concise evidence-backed findings with file/line references, and avoid edits unless the user explicitly asks for a writer pass. The parent synthesizes fixes worth doing now, optional improvements, and feedback to ignore/defer before applying anything.
|
|
66
|
+
|
|
67
|
+
### Review-loop technique
|
|
68
|
+
|
|
69
|
+
Use this when the user wants implementation or current diff review to continue until reviewers stop finding fixes worth doing now. Keep the loop in the parent session: one `worker` implements or fixes, fresh-context `reviewer` agents inspect the actual repo and diff, the parent synthesizes accepted fixes, and one `worker` applies them. Prefer separate async reviewer runs so each completion wakes the parent instead of waiting for the whole panel. Continue useful parent work while they run; if none remains, end the turn and wait instead of polling. Do not put reviewer panels inside one async chain because the aggregate result hides individual reviewer completions; continue with explicit follow-up runs after each completion. An incomplete active Pi goal follows the same async workflow: yield when child evidence gates the next step, then resume the goal after automatic completion delivery. Treat an async implementation worker handoff as an intermediate state, not final completion, unless the user explicitly asked for worker-only work, review-only output, or to stop after implementation. Stop when reviewers find no blockers or fixes worth doing now, remaining feedback is optional or deferred, a concrete decision outside the existing authority appears, or the max review-round cap is reached. Default to 3 review rounds unless the user sets a different cap. Do not loop for optional polish. Helpers may delegate within their assigned work; the original agent decides the loop outcome.
|
|
70
|
+
|
|
71
|
+
### Parallel research technique
|
|
72
|
+
|
|
73
|
+
Use this when the question needs both external evidence and local implications. Combine `researcher` for official docs, specs, ecosystem behavior, recent changes, benchmarks, and primary sources with `scout` for repository files, patterns, constraints, tests, and likely integration points. Give each child a distinct angle: external evidence, local code context, and practical tradeoffs. Ask for source links or file ranges, confidence level, gaps, and decision implications. Do not ask these children to edit unless implementation was explicitly requested.
|
|
74
|
+
|
|
75
|
+
### Parallel context-build technique
|
|
76
|
+
|
|
77
|
+
Use this before planning or implementation when a stronger handoff is needed. Run a chain with one parallel step of `context-builder` agents rather than top-level parallel tasks, so relative output files live under the temporary chain directory. Give every task a distinct output path such as `context-build/request-and-scope.md`, `context-build/codebase-and-patterns.md`, and `context-build/validation-and-risks.md`. Choose two or three builders: request/scope, codebase/patterns, and validation/risks. Each builder must read every relevant file needed to understand its slice, follow imports/callers/tests/docs/config, conduct tool-available web research when needed, and include a compact `meta-prompt` section. The parent synthesizes the outputs into important context, recommended next meta-prompt, open questions, assumptions, and artifact paths.
|
|
78
|
+
|
|
79
|
+
Example shape:
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
subagent({
|
|
83
|
+
chain: [{
|
|
84
|
+
parallel: [
|
|
85
|
+
{ agent: "context-builder", task: "Build request/scope context for: ...", output: "context-build/request-and-scope.md" },
|
|
86
|
+
{ agent: "context-builder", task: "Build codebase/pattern context for: ...", output: "context-build/codebase-and-patterns.md" },
|
|
87
|
+
{ agent: "context-builder", task: "Build validation/risk context for: ...", output: "context-build/validation-and-risks.md" }
|
|
88
|
+
]
|
|
89
|
+
}],
|
|
90
|
+
context: "fresh"
|
|
91
|
+
})
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Parallel handoff-plan technique
|
|
95
|
+
|
|
96
|
+
Use this when the user needs a solution brief or implementation-ready handoff from an external reference plus local code context, such as “study this library behavior, inspect our codebase, then produce a worker prompt.” Run a chain with a first parallel group and a second synthesis `context-builder` step. The first group usually includes `researcher` for external projects/docs/prompt guidance and `context-builder` for local code context; add a second `context-builder` for implementation strategy only when the scope is large enough to benefit. Use distinct output paths under `handoff/`, then have the synthesis `context-builder` read those outputs and write `handoff/final-handoff-plan.md` with the recommended approach, likely files, constraints, non-goals, validation, risks, unresolved questions, and final compact implementation-ready meta-prompt.
|
|
97
|
+
|
|
98
|
+
Example shape:
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
subagent({
|
|
102
|
+
chain: [
|
|
103
|
+
{ parallel: [
|
|
104
|
+
{ agent: "researcher", task: "Research the external reference and transferable implementation ideas for: ...", output: "handoff/external-reference.md" },
|
|
105
|
+
{ agent: "context-builder", task: "Build local codebase context for: ...", output: "handoff/local-context.md" },
|
|
106
|
+
{ agent: "context-builder", task: "Compare evidence and propose implementation strategy for: ...", output: "handoff/implementation-strategy.md" }
|
|
107
|
+
] },
|
|
108
|
+
{ agent: "context-builder", task: "Read {previous} and synthesize the final handoff plan and implementation-ready meta-prompt.", output: "handoff/final-handoff-plan.md" }
|
|
109
|
+
],
|
|
110
|
+
context: "fresh"
|
|
111
|
+
})
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Gather-context-and-clarify technique
|
|
115
|
+
|
|
116
|
+
Use this at the start of non-trivial work when material ambiguity remains. Launch `scout` for local context and `researcher` only when external docs, recent sources, ecosystem context, or primary evidence would materially improve understanding. Ask children for concise findings plus remaining clarification questions. Then synthesize what is known and use the available clarification tool (`ask_question` in pi) only for unresolved questions that affect scope, acceptance, constraints, or implementation.
|
|
117
|
+
|
|
118
|
+
### Parallel cleanup technique
|
|
119
|
+
|
|
120
|
+
Use this after implementation when the user wants cleanup review or when a final pass would reduce AI-slop. Launch two fresh-context `reviewer` tasks with `output: false` and `progress: false`: one deslop pass and one verbosity pass. If the `deslop` or `verbosity-cleaner` skills are available, pass the relevant skill to that reviewer; otherwise inline the criteria. Both reviewers are review-only and should flag concrete issues with severity, file/line references, and smallest safe fixes. Phrase the constraint as “Do not modify project/source files; returning findings through the configured output artifact is allowed” when you use `output` or `outputMode: "file-only"`. The parent applies worthwhile fixes when cleanup or implementation is already authorized; review-only requests remain read-only.
|
|
121
|
+
|
|
122
|
+
### Staged fix orchestration technique
|
|
123
|
+
|
|
124
|
+
Use this when a broad diff has known reviewer findings across several items and the user wants the parent to “orchestrate subagents like a boss.” Normally keep these stages under parent control with separate async reviewers and one writer. If the caller explicitly chooses a fixed foreground workflow with no parent decisions between steps, use a three-stage chain:
|
|
125
|
+
|
|
126
|
+
1. A parallel read-only planning fanout, one planner/reviewer per issue cluster. Each child inspects the real diff and returns exact files, line refs, proposed fixes, and focused validation. They must not edit.
|
|
127
|
+
2. One writer worker. It receives the planner summaries through `{previous}`, the parent’s accepted scope, stop rules, and verification contract. It is the only child allowed to edit the active worktree.
|
|
128
|
+
3. A parallel read-only validation fanout. Validators inspect the worker diff from fresh context with distinct angles, report pass/fail, remaining blockers, and missing verification.
|
|
129
|
+
|
|
130
|
+
Prefer `context: "fresh"` for planners/validators, `outputMode: "file-only"` for large summaries, and per-stage output names that will not collide. For an explicitly chosen foreground chain, set `async: false`; `forceTopLevelAsync` must be disabled because it overrides foreground requests. Otherwise, including under an active goal, run the same stages under parent control: launch each planning or validation reviewer as a separate async single-agent run, synthesize after their individual completions, then launch the sole writer. Add `phase` and `label` to make foreground chain status readable, and use `as` plus `{outputs.name}` when a later step needs a specific earlier result instead of the whole `{previous}` blob. Use this pattern instead of launching several writer workers into a dirty worktree. Include non-blocking suggestions in the writer prompt only when they are small, safe, and do not expand product scope; otherwise record them as deferred.
|
|
131
|
+
|
|
132
|
+
When the first step can return a structured target list, prefer dynamic fanout instead of hand-authoring a static parallel group. Use `outputSchema` and `as` on the producer, then an `expand` step with `from: { output, path }`, an explicit `maxItems`, one `parallel` child template, and `collect.as`. Item templates may use `{item}` or a named item such as `{target.path}`. Do not use dynamic fanout for prose outputs, nested fanout, dynamic agent selection, reducers, `when` conditions, or arbitrary expressions; `.chain.md` does not support this syntax, so use direct JSON or a saved `.chain.json`.
|
|
133
|
+
|
|
134
|
+
Example shape:
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
subagent({
|
|
138
|
+
// Explicitly chosen foreground workflow; requires forceTopLevelAsync to be disabled.
|
|
139
|
+
async: false,
|
|
140
|
+
context: "fresh",
|
|
141
|
+
chain: [
|
|
142
|
+
{ parallel: [
|
|
143
|
+
{ agent: "reviewer", phase: "Planning", label: "Deploy docs", as: "deployPlan", task: "Plan fixes for deploy docs/workflow. Inspect the current diff. Do not modify project/source files; returning findings via the configured output artifact is allowed.", output: "plans/deploy.md", outputMode: "file-only" },
|
|
144
|
+
{ agent: "reviewer", phase: "Planning", label: "Scheduler contract", as: "schedulerPlan", task: "Plan fixes for scheduler contract. Inspect the current diff. Do not modify project/source files; returning findings via the configured output artifact is allowed.", output: "plans/scheduler.md", outputMode: "file-only" },
|
|
145
|
+
{ agent: "reviewer", phase: "Planning", label: "Sandbox/security", as: "sandboxPlan", task: "Plan fixes for sandbox/security. Inspect the current diff. Do not modify project/source files; returning findings via the configured output artifact is allowed.", output: "plans/sandbox.md", outputMode: "file-only" }
|
|
146
|
+
], concurrency: 3 },
|
|
147
|
+
{ agent: "worker", phase: "Implementation", label: "Apply accepted fixes", as: "workerResult", task: "Apply only the accepted fixes from these planning summaries. You are the sole writer for the active worktree.\n\nDeploy plan:\n{outputs.deployPlan}\n\nScheduler plan:\n{outputs.schedulerPlan}\n\nSandbox plan:\n{outputs.sandboxPlan}", acceptance: { criteria: ["Accepted fixes from each planning summary are applied", "Focused validation for changed behavior passes", "Changed files, validation commands, failures, and residual risks are reported"], evidence: ["changed-files", "commands-run", "validation-output", "residual-risks"], stopRules: ["Do not expand product scope beyond accepted fixes", "Stop and report if a fix requires information or authority you cannot obtain"], maxFinalizationTurns: 3 }, output: "worker/fixes.md", outputMode: "file-only", progress: true },
|
|
148
|
+
{ parallel: [
|
|
149
|
+
{ agent: "reviewer", phase: "Validation", label: "Deploy/scheduler validation", task: "Validate the post-worker diff for deploy and scheduler fixes. Start from the worker result: {outputs.workerResult}. Do not modify project/source files; returning findings via the configured output artifact is allowed.", output: "validation/deploy-scheduler.md", outputMode: "file-only" },
|
|
150
|
+
{ agent: "reviewer", phase: "Validation", label: "Sandbox validation", task: "Validate the post-worker diff for sandbox/security fixes. Start from the worker result: {outputs.workerResult}. Do not modify project/source files; returning findings via the configured output artifact is allowed.", output: "validation/sandbox.md", outputMode: "file-only" }
|
|
151
|
+
], concurrency: 2 }
|
|
152
|
+
]
|
|
153
|
+
})
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Builtin Agents
|
|
157
|
+
|
|
158
|
+
Builtin agents load at the lowest priority. Project agents override user agents,
|
|
159
|
+
and user/project agents override builtins with the same name.
|
|
160
|
+
|
|
161
|
+
Use `agent_runs({ action: "profiles" })` for the effective roles, model/thinking/fallback defaults (including truthful inheritance), and context defaults. The [README](../../../README.md#builtin-agents-in-plain-english) describes the bundled roles. Do not infer installed model routes from an old workflow example. Profiles without a model inherit the parent model at launch, including fresh-context runs; inspect the effective profile rather than assuming a role has no model configured.
|
|
162
|
+
|
|
163
|
+
For one run, use inline config:
|
|
164
|
+
|
|
165
|
+
```text
|
|
166
|
+
/run reviewer[model=anthropic/claude-sonnet-4] "Review this diff"
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
For persistent tweaks, edit `subagents.agentOverrides` in user or project settings. User overrides apply everywhere. Project overrides apply only in that repo and win over user overrides.
|
|
170
|
+
|
|
171
|
+
## Prompting role subagents
|
|
172
|
+
|
|
173
|
+
Use profile defaults for routine launches; warranted overrides follow the [skill's model policy](../SKILL.md#agent-selection), using `model: "provider/model:high"`, never a standalone execution `thinking` field. Explicit overrides pin route/effort with same-choice transport retries but no profile fallback; unavailable choices fail for the parent to replace. Write the task prompt as a compact contract, not a long procedural script. Define the destination and let the role choose the efficient path.
|
|
174
|
+
|
|
175
|
+
A strong subagent prompt usually includes:
|
|
176
|
+
- **Goal**: the concrete outcome the child should produce.
|
|
177
|
+
- **Context/evidence**: relevant plan paths, files, diffs, decisions, or user constraints already approved.
|
|
178
|
+
- **Success criteria**: what must be true before the child can finish.
|
|
179
|
+
- **Hard constraints**: true invariants only, such as no edits for review-only tasks, one writer thread or escalation for decisions outside the approved outcome.
|
|
180
|
+
- **Validation**: targeted checks to run, or the next-best check when validation is impossible.
|
|
181
|
+
- **Output**: the expected summary shape, artifact path, or finding format.
|
|
182
|
+
- **Stop rules**: when to ask via `intercom`, when to stop after enough evidence, and when not to keep searching.
|
|
183
|
+
|
|
184
|
+
Avoid carrying over old prompt habits that over-specify every step. Use `must`, `always`, and `never` for real invariants; for judgment calls, give decision rules. For example, tell a reviewer to inspect the staged diff directly and report only evidence-backed findings, rather than prescribing every file or command. Tell a researcher the retrieval budget: start with broad targeted searches, fetch only the strongest sources, search again only when a required fact is missing, then stop.
|
|
185
|
+
|
|
186
|
+
For implementation handoffs, name the approved scope and success criteria more clearly than the process. Good prompts say what to change, what not to change, where the evidence lives, how to validate, and when to escalate. Useful helpers may split the assigned work within native limits; they must not take over the parent's workflow or continue its conversation.
|
|
187
|
+
|
|
188
|
+
Settings locations:
|
|
189
|
+
- User scope: `~/.pi/agent/settings.json`
|
|
190
|
+
- Project scope: `.pi/settings.json`
|
|
191
|
+
|
|
192
|
+
Direct settings example:
|
|
193
|
+
|
|
194
|
+
```json
|
|
195
|
+
{
|
|
196
|
+
"subagents": {
|
|
197
|
+
"agentOverrides": {
|
|
198
|
+
"reviewer": {
|
|
199
|
+
"model": "anthropic/claude-sonnet-4",
|
|
200
|
+
"thinking": "high",
|
|
201
|
+
"fallbackModels": ["openai/gpt-5-mini"]
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Useful override fields: `model`, `fallbackModels`, `thinking`,
|
|
209
|
+
`systemPromptMode`, `inheritProjectContext`, `inheritSkills`, `defaultContext`,
|
|
210
|
+
`disabled`, `skills`, `tools`, and `systemPrompt`. Create a user or project
|
|
211
|
+
agent with the same name only when you want a substantially different agent.
|
|
212
|
+
|
|
213
|
+
## Discovery and Scope Rules
|
|
214
|
+
|
|
215
|
+
Agent files can live in:
|
|
216
|
+
- `~/.pi/agent/agents/**/*.md` — user scope
|
|
217
|
+
- `.pi/agents/**/*.md` — canonical project scope
|
|
218
|
+
- legacy `.agents/**/*.md` — still read for compatibility, but `.pi/agents/` wins on conflicts
|
|
219
|
+
|
|
220
|
+
Chains live in:
|
|
221
|
+
- `~/.pi/agent/chains/**/*.chain.md` and `~/.pi/agent/chains/**/*.chain.json` — user scope
|
|
222
|
+
- `.pi/chains/**/*.chain.md` and `.pi/chains/**/*.chain.json` — project scope
|
|
223
|
+
|
|
224
|
+
Discovery is recursive. `.chain.md` files do not define agents. Use `.chain.md` for simple saved chains and `.chain.json` for dynamic fanout or inline schema objects. Agents and chains can set optional frontmatter/package metadata; `name: scout` plus `package: code-analysis` registers as runtime name `code-analysis.scout` while serialization keeps `name` and `package` separate.
|
|
225
|
+
|
|
226
|
+
Precedence is by parsed runtime name:
|
|
227
|
+
1. project scope
|
|
228
|
+
2. user scope
|
|
229
|
+
3. builtin agents
|
|
230
|
+
|
|
231
|
+
## Running Subagents
|
|
232
|
+
|
|
233
|
+
### Single agent
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
subagent({
|
|
237
|
+
agent: "oracle",
|
|
238
|
+
task: "Review my current direction and challenge assumptions."
|
|
239
|
+
})
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Forked context
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
subagent({
|
|
246
|
+
agent: "oracle",
|
|
247
|
+
task: "Review my current direction and challenge assumptions."
|
|
248
|
+
})
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
`context: "fork"` creates a branched child session from the current persisted
|
|
252
|
+
parent session. It does **not** create a fresh minimal review context or filter
|
|
253
|
+
history down to only the relevant parts. Use it when you want a separate review
|
|
254
|
+
or execution thread that can still reference the parent session history. Fork
|
|
255
|
+
is rejected when an affected agent's actual primary or fallback candidate uses
|
|
256
|
+
the `anthropic/` provider. A pinned non-Anthropic override excludes profile
|
|
257
|
+
fallbacks; an Anthropic override remains ineligible.
|
|
258
|
+
|
|
259
|
+
### Parallel execution
|
|
260
|
+
|
|
261
|
+
```typescript
|
|
262
|
+
subagent({
|
|
263
|
+
tasks: [
|
|
264
|
+
{ agent: "scout", task: "Explore the auth module" },
|
|
265
|
+
{ agent: "researcher", task: "Research API client retry behavior" }
|
|
266
|
+
]
|
|
267
|
+
})
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
Top-level parallel tasks can override per-task behavior:
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
subagent({
|
|
274
|
+
tasks: [
|
|
275
|
+
{ agent: "scout", task: "Map auth", output: "auth-context.md", progress: true },
|
|
276
|
+
{ agent: "researcher", task: "Research OAuth best practices", output: "oauth-research.md" },
|
|
277
|
+
{ agent: "scout", task: "Map auth test coverage", model: "anthropic/claude-sonnet-4" }
|
|
278
|
+
],
|
|
279
|
+
concurrency: 3
|
|
280
|
+
})
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
Avoid duplicate explicit output paths in parallel tasks. Concurrent children should not be told to write the same explicit file. Explicit output paths persist at their resolved cwd/workspace path; relative output paths that come from agent defaults are automatically materialized under the run artifact directory with unique names, so default `context.md`/`review.md` handoffs do not collide or leave project-root files. For large saved outputs, set `outputMode: "file-only"` together with an `output` path. The parent result then contains only a compact reference like `Output saved to: /abs/report.md (48.2 KB, 2847 lines). Read this file if needed.` instead of the full saved content. Do not use `output: false` for this; `output: false` means no file output. When a task is review-only, say “do not modify project/source files” rather than “do not write files” if you also configured `output`; otherwise the child may treat the output artifact as forbidden. Failed runs and save errors still return inline details for debugging.
|
|
284
|
+
|
|
285
|
+
### Chain execution
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
subagent({
|
|
289
|
+
chain: [
|
|
290
|
+
{ agent: "scout", task: "Map the auth flow and summarize key files" },
|
|
291
|
+
{ agent: "planner", task: "Create an implementation plan from {previous}" },
|
|
292
|
+
{ agent: "worker", task: "Implement the approved plan based on {previous}" }
|
|
293
|
+
]
|
|
294
|
+
})
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
Chain steps can use templated variables such as `{task}`, `{previous}`,
|
|
298
|
+
`{chain_dir}`, and `{outputs.name}`. Use `as: "name"` on a successful step or
|
|
299
|
+
parallel task to make that output available to later steps. Prefer named outputs
|
|
300
|
+
when a later step needs one specific result; keep `{previous}` for simple linear
|
|
301
|
+
handoffs or full fan-in summaries. Use `phase` and `label` for status readability.
|
|
302
|
+
Use `outputSchema` when later steps need reliable structured data; the child must
|
|
303
|
+
call `structured_output` with schema-valid JSON, or the step fails.
|
|
304
|
+
|
|
305
|
+
### Async/background
|
|
306
|
+
|
|
307
|
+
Subagent launches default to async mode when `async` is omitted. Use that default for scouts, researchers, workers, reviewers, validators, oracle checks, one-off delegates, chains, and non-review parallel groups. Launch each member of a reviewer or validator panel as a separate single-agent call; do not put the panel in one parallel group or chain. Keep the write path single-threaded even when the run is async.
|
|
308
|
+
|
|
309
|
+
An incomplete active Pi goal does not require foreground execution. If child evidence gates the next step, end the current turn and continue the goal after automatic completion delivery; do not advance past missing evidence. Use `async: false` only for explicitly chosen foreground execution or non-interactive one-shot callers that need the result on stdout.
|
|
310
|
+
|
|
311
|
+
Async does not mean parallel writes. Do not edit the same active worktree while an async worker is changing it. Parent-side overlap should be reading, validation prep, synthesis, command planning, or review of unaffected context unless the writer is isolated in a separate worktree.
|
|
312
|
+
|
|
313
|
+
After launching an async child, continue promised or useful independent work. If none remains, end your turn and wait instead of sleep-polling; Pi will deliver the completion.
|
|
314
|
+
|
|
315
|
+
A reviewer timeout is never sign-off. Prefer separate default-async runs for final reviewers, including under active goals, so each completion wakes the parent. Runtime automatically raises foreground reviewer timeouts below 15 minutes to prevent false non-signoff failures. Planner/researcher-style roles raise short foreground budgets only when local run history shows they need longer; async/background runs still reject foreground timeout fields. Do not use short foreground timeouts such as 3–4 minutes for broad reviewer/scout/research tasks. If a reviewer times out, resume, rerun with enough budget, or split the review into narrower reviewers before claiming reviewed completion.
|
|
316
|
+
|
|
317
|
+
```typescript
|
|
318
|
+
subagent({
|
|
319
|
+
agent: "worker",
|
|
320
|
+
task: "Run the full test suite"
|
|
321
|
+
})
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
Use ordinary tools for routine waiting and CI status collection. When observation requires ongoing interpretation, give `watcher` the target, material transitions, and terminal condition. It should report meaningful findings without repeating unchanged status.
|
|
325
|
+
|
|
326
|
+
File-only output mode also works for async single runs, top-level parallel task items, sequential chain steps, and chain parallel task items. In chains, `{previous}` receives the compact saved-file reference when the prior step used file-only mode.
|
|
327
|
+
|
|
328
|
+
For review fanout where the parent continues a local audit:
|
|
329
|
+
|
|
330
|
+
```typescript
|
|
331
|
+
const run = subagent({
|
|
332
|
+
agent: "reviewer",
|
|
333
|
+
task: "Review the current diff for correctness issues. Do not edit files.",
|
|
334
|
+
context: "fresh"
|
|
335
|
+
})
|
|
336
|
+
// Continue local inspection; completion will wake the parent.
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
Inspect async runs with `subagent({ action: "status", id: "..." })` or `subagent({ action: "status" })` for active runs. Use status for diagnostics, not as a wait loop; healthy runs deliver completion automatically. Foreground and background handles remain inspectable and continuable after native reload/restart of the same saved parent. `subagent({ action: "status", id: "latest" })` / `id: "last"` selects the latest owned run. `inspect` shows saved effective configuration and profile provenance, result references, review state, and the root/predecessor/continuation history. If a delegated fanout child launches nested runs, the parent status view shows them as a tree and you can target a nested run directly with its nested id.
|
|
340
|
+
|
|
341
|
+
Use `extend` when an active foreground child has an explicit timeout and is still doing useful work:
|
|
342
|
+
|
|
343
|
+
```typescript
|
|
344
|
+
subagent({ action: "extend", id: "foreground-run-id", extendMs: 300000 })
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
`extend` adds time to the current foreground child deadline. It does not revive an already timed-out child; use `resume` after a timeout or transient failure.
|
|
348
|
+
|
|
349
|
+
Use `resume` for follow-up work after a delegated run:
|
|
350
|
+
|
|
351
|
+
```typescript
|
|
352
|
+
subagent({ action: "resume", id: "run-id", message: "Follow up on this point." })
|
|
353
|
+
subagent({ action: "resume", id: "run-id", index: 1, message: "Continue reviewer 2." })
|
|
354
|
+
subagent({ action: "resume", id: "nested-run-id", message: "Continue this nested reviewer." })
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
Resume behavior:
|
|
358
|
+
- If a foreground or async child is still running and reachable, `resume` sends the follow-up to that live child over intercom.
|
|
359
|
+
- If a live foreground or async child needs a prompt but not a blocking reply, `nudge` sends a steered intercom message through the same bridge.
|
|
360
|
+
- If an async child has completed, `resume` revives it by starting a new async child from the persisted child session file.
|
|
361
|
+
- Multi-child async runs require `index` unless only one running child is selectable.
|
|
362
|
+
- Completed foreground single, parallel, and chain runs can also be revived by `index`; ownership and results are restored from persistent session records, not only extension memory.
|
|
363
|
+
- Continuation without `agent` keeps saved launch settings, including resolved model/thinking and override pinning. Explicit `agent` adopts the current profile's model, thinking and fallback policy; a separate `model` override wins and pins its choice. Other saved output, limits and acceptance settings remain unless overridden. Live guidance is not a new launch and cannot mutate model or acceptance. Old receipts without a profile snapshot require an explicit `agent` rather than silently rediscovering defaults.
|
|
364
|
+
- `agent_runs` supports `model`, `cwd`, `output`, and `acceptance` overrides on `continue`/`answer`. Use legacy `resume` for detailed output/skill/control overrides. A deleted worktree needs an explicit replacement `cwd`; a missing native child session cannot be revived.
|
|
365
|
+
- If another continuation of the same saved child is already live, `continue` forwards to it rather than duplicating its process. A new continuation has its own review outcome.
|
|
366
|
+
- Timed-out or transient-error foreground children can be revived the same way when their `.jsonl` session file was persisted.
|
|
367
|
+
- Nested runs can be resumed by nested id when a live route or persisted nested session metadata is available.
|
|
368
|
+
- Revive starts a new child process from the old session context; it does not restart the same OS process.
|
|
369
|
+
- If the chosen child has no persisted `.jsonl` session file, resume fails and reports that directly.
|
|
370
|
+
|
|
371
|
+
Use diagnostics when setup or child startup looks wrong:
|
|
372
|
+
|
|
373
|
+
```typescript
|
|
374
|
+
subagent({ action: "doctor" })
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
Humans can use `/subagents-doctor` for the same read-only report. It checks runtime paths, discovery counts, async support, current session context, and intercom bridge state.
|
|
378
|
+
|
|
379
|
+
### Subagent control
|
|
380
|
+
|
|
381
|
+
Subagent control is the runtime visibility and intervention layer for delegated runs. It is separate from lifecycle status. Lifecycle status says whether a child is `queued`, `running`, `paused`, `complete`, or `failed`. Activity reporting is factual: it tracks the last observed activity time and the current tool when known. It does not pretend to know that a child is truly stuck.
|
|
382
|
+
|
|
383
|
+
Default behavior is intentionally conservative. When no activity has been observed past the configured threshold (10 minutes by default), the run emits a `needs_attention` control event. Foreground runs can push this as a `subagent:control-event` event, and async runs persist it to `events.jsonl` so the parent tracker can surface it without constant manual polling. Notification-worthy control events are also inserted into the visible transcript so both the user and the parent agent can see them, with a proactive hint plus concrete `nudge`, `status`, and `interrupt` options. Use `status` to see an `extend` command when the active foreground child has an extendable timeout. Visible notifications fire once per child run and attention state.
|
|
384
|
+
|
|
385
|
+
Use soft interrupt when a child is clearly blocked or drifting and the parent needs to regain control:
|
|
386
|
+
|
|
387
|
+
```typescript
|
|
388
|
+
subagent({ action: "interrupt" })
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
Pass `id` when targeting a specific controllable run, including a nested run shown in the parent status tree:
|
|
392
|
+
|
|
393
|
+
```typescript
|
|
394
|
+
subagent({ action: "interrupt", id: "abc123" })
|
|
395
|
+
subagent({ action: "interrupt", id: "nested-run-id" })
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
A soft interrupt cancels the current child turn and leaves the run paused. It does not mean the delegated task succeeded or failed. Bare `interrupt` does not target hidden nested descendants; use the explicit nested id. After an interrupt, decide the next explicit action: resume with clearer instructions, replace the task, ask the user, or stop the workflow.
|
|
399
|
+
|
|
400
|
+
Per-run control thresholds can be overridden when a task legitimately runs without observable output for longer than usual:
|
|
401
|
+
|
|
402
|
+
```typescript
|
|
403
|
+
subagent({
|
|
404
|
+
agent: "worker",
|
|
405
|
+
task: "Run the slow migration test suite",
|
|
406
|
+
control: {
|
|
407
|
+
needsAttentionAfterMs: 1800000,
|
|
408
|
+
notifyOn: ["needs_attention"]
|
|
409
|
+
}
|
|
410
|
+
})
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
Needs-attention notifications can also prepare a compact intercom ping for the paired orchestrator target. Prefer `subagent({ action: "nudge", id: "...", message: "..." })` for live guidance, answers, corrections, or blockers; it is a non-blocking steer that supplements the active child task unless it explicitly replaces it. Use the status-shown intercom ask only when the parent must remain alive waiting for a reply. Do not invent a target; use the resolved target shown in status or injected instructions. An explicit agent `extensions` allowlist that omits `pi-intercom` still sandboxes child-side coordination tools.
|
|
414
|
+
|
|
415
|
+
## Clarify TUI
|
|
416
|
+
|
|
417
|
+
Single and parallel runs support a clarification TUI when you want to preview or
|
|
418
|
+
edit parameters before launch:
|
|
419
|
+
|
|
420
|
+
```typescript
|
|
421
|
+
subagent({
|
|
422
|
+
agent: "worker",
|
|
423
|
+
task: "Implement feature X",
|
|
424
|
+
clarify: true
|
|
425
|
+
})
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
Clarify is opt-in for tool calls. Set `clarify: true` when you want to preview or edit a single, parallel, or chain run before launch. Clarify edits affect only the next run; use management actions, settings, or markdown files for persistent changes.
|
|
429
|
+
Programmatic launches run in the background by default. Omit `clarify` or set `clarify: false` to launch directly; `async: false`, `clarify: true`, or a foreground timeout keeps the run foreground.
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
## Worktree Isolation
|
|
433
|
+
|
|
434
|
+
When multiple agents might write concurrently, use worktrees instead of letting
|
|
435
|
+
them share one filesystem view.
|
|
436
|
+
|
|
437
|
+
```typescript
|
|
438
|
+
subagent({
|
|
439
|
+
tasks: [
|
|
440
|
+
{ agent: "worker", task: "Implement feature A" },
|
|
441
|
+
{ agent: "worker", task: "Implement feature B" }
|
|
442
|
+
],
|
|
443
|
+
worktree: true
|
|
444
|
+
})
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
`worktree: true` gives each parallel task its own git worktree branched from
|
|
448
|
+
HEAD. This requires a clean git state and is mainly for intentionally parallel
|
|
449
|
+
write workflows. If you want one writer thread and several advisory agents,
|
|
450
|
+
prefer a single-writer pattern instead.
|
|
451
|
+
|
|
452
|
+
## The Oracle Workflow
|
|
453
|
+
|
|
454
|
+
The intended oracle loop is:
|
|
455
|
+
1. the main agent forks to `oracle`
|
|
456
|
+
2. `oracle` reviews direction, drift, assumptions, and risks
|
|
457
|
+
3. `oracle` can coordinate back through `contact_supervisor` when the bridge injects it
|
|
458
|
+
4. the main agent chooses an in-scope direction under existing authority
|
|
459
|
+
5. `worker` implements when the task already authorizes implementation; planning-only requests and explicit holds remain read-only
|
|
460
|
+
|
|
461
|
+
```typescript
|
|
462
|
+
// Advisory review in a branched thread. Oracle defaults to forked context.
|
|
463
|
+
subagent({
|
|
464
|
+
agent: "oracle",
|
|
465
|
+
task: "Review my current direction, challenge assumptions, and propose the best next move."
|
|
466
|
+
})
|
|
467
|
+
|
|
468
|
+
// Existing implementation authority is sufficient. Worker defaults to fresh context.
|
|
469
|
+
subagent({
|
|
470
|
+
agent: "worker",
|
|
471
|
+
task: "Implement the approved approach: ..."
|
|
472
|
+
})
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
`oracle` is not a fresh-context reviewer in the Cognition article sense. It is
|
|
476
|
+
a forked advisory thread that inherits the parent session history and uses that
|
|
477
|
+
history as a baseline contract.
|
|
478
|
+
|
|
479
|
+
Use `oracle` as a smart-friend escalation when the parent needs help with trajectory rather than diff inspection: architectural boundaries, model capability routing, merge conflicts, reviewer disagreement, context drift after long work, a worker about to invent a pattern, or fixes that require product/scope tradeoffs. Ask broad questions when the right concern is unclear, and let `oracle` point out missing context or files the parent should inspect before asking again. Keep `oracle` advisory unless it has been explicitly assigned the single writer role.
|
|
480
|
+
|
|
481
|
+
## Subagent + Intercom Coordination
|
|
482
|
+
|
|
483
|
+
`pi-subagents` bundles its intercom extension. Children get fixed default bridge instructions and a private coordination channel back to the parent session unless an explicit `extensions` allowlist omits `pi-intercom`.
|
|
484
|
+
|
|
485
|
+
Most agents should not call generic `intercom` directly unless bridge instructions provide a target and `contact_supervisor` is unavailable. Do not invent a target. Prefer the tool from the injected bridge instructions.
|
|
486
|
+
|
|
487
|
+
Use blocking `contact_supervisor` only when an ephemeral child cannot safely continue and must remain alive for the reply:
|
|
488
|
+
- `reason: "need_decision"` for one decision, approval, or product/API/scope clarification
|
|
489
|
+
- `reason: "interview_request"` when multiple structured answers are all required before safe progress
|
|
490
|
+
|
|
491
|
+
Both reasons persist the question before steering the supervisor, and neither uses the ordinary intercom ask timeout. After supervisor reload, reconnect, or child exit, resume the same saved supervisor session and use:
|
|
492
|
+
|
|
493
|
+
```typescript
|
|
494
|
+
agent_runs({ action: "questions" })
|
|
495
|
+
agent_runs({ action: "answer", id: "<run-id>", questionId: "<question-id>", message: "Use the stable API." })
|
|
496
|
+
agent_runs({ action: "stop", id: "<run-id>" })
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
A live waiter reads the saved answer; an exited child is revived from its saved session with its original effective launch configuration and acceptance contract. Identical repeated answers do not duplicate work, and conflicting answers retain the original. A nudge is guidance, not an answer. `awaiting_input` and `answer_pending` are not execution completion. Stop cancels pending questions and aborts live waiters even after reload. Questions, contracts, and results live in persistent Pi session storage and survive temporary-log cleanup. Native parent custom entries retain ownership and review across reload, restart, and context-window changes. New or forked parent sessions do not automatically adopt another parent's runs. An interrupted pre-launch answer receipt gives an explicit `continue` recovery call; it never silently retries an uncertain launch.
|
|
500
|
+
|
|
501
|
+
Do not use `contact_supervisor` just to resolve review-only/no-project-edit versus progress-writing or output-artifact instructions. The child must not modify project/source files, but returning findings through its normal response or configured output artifact is allowed unless the parent explicitly set `output: false`.
|
|
502
|
+
|
|
503
|
+
Use `contact_supervisor` with `reason: "progress_update"` only for a discovery or change the supervisor needs while working. It is non-blocking and steers at the next tool boundary. Skip starts, redundant narration, and routine completion; retain material findings in the final result.
|
|
504
|
+
|
|
505
|
+
Message conventions:
|
|
506
|
+
- `reason: "need_decision"` and `reason: "interview_request"` steer, wait for the parent reply, and return it to the child.
|
|
507
|
+
- `reason: "progress_update"` steers at the next tool boundary and should contain only a finding needed during active work.
|
|
508
|
+
- Child-side routine completion handoffs are not expected. Parent-side `pi-subagents` sends grouped completion results through `pi-intercom`: one grouped message per foreground parent run and one per completed async result file. Acknowledged foreground delivery returns a compact receipt with artifact/session paths; if unacknowledged, the normal full output is preserved. Grouped messages include child intercom targets, full child summaries, and compact nested summaries under the parent child that launched them.
|
|
509
|
+
|
|
510
|
+
If bridge instructions provide the child-facing tool, a child can ask:
|
|
511
|
+
|
|
512
|
+
```typescript
|
|
513
|
+
contact_supervisor({
|
|
514
|
+
reason: "need_decision",
|
|
515
|
+
message: "The approved API contract does not specify whether this new response field may be public. Should I preserve the current response shape?"
|
|
516
|
+
})
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
The parent replies with:
|
|
520
|
+
|
|
521
|
+
```typescript
|
|
522
|
+
intercom({ action: "reply", message: "Optimize for readability." })
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
Or inspects unresolved asks first:
|
|
526
|
+
|
|
527
|
+
```typescript
|
|
528
|
+
intercom({ action: "pending" })
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
If intercom messages do not show up, run `subagent({ action: "doctor" })` or `/subagents-doctor`.
|
|
532
|
+
|
|
533
|
+
## Management Mode
|
|
534
|
+
|
|
535
|
+
The `subagent(...)` tool also supports management actions.
|
|
536
|
+
|
|
537
|
+
### List available agents and chains
|
|
538
|
+
|
|
539
|
+
```typescript
|
|
540
|
+
subagent({ action: "list" })
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
`list` and `get` show the effective runtime agent by default. If a user or project agent shadows a builtin with the same name, the agent appears once with the same precedence used for execution (`project` > `user` > `builtin`). Use `agentScope: "user"` or `agentScope: "project"` only when you need to inspect a specific shadowing scope.
|
|
544
|
+
|
|
545
|
+
### Create an agent
|
|
546
|
+
|
|
547
|
+
```typescript
|
|
548
|
+
subagent({
|
|
549
|
+
action: "create",
|
|
550
|
+
config: {
|
|
551
|
+
name: "my-agent",
|
|
552
|
+
package: "code-analysis",
|
|
553
|
+
description: "Project-specific implementation helper",
|
|
554
|
+
systemPrompt: "Your system prompt here.",
|
|
555
|
+
systemPromptMode: "replace",
|
|
556
|
+
model: "openai-codex/gpt-5.4",
|
|
557
|
+
tools: "read,grep,find,ls,bash"
|
|
558
|
+
}
|
|
559
|
+
})
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
### Update an agent
|
|
563
|
+
|
|
564
|
+
```typescript
|
|
565
|
+
subagent({
|
|
566
|
+
action: "update",
|
|
567
|
+
agent: "code-analysis.my-agent",
|
|
568
|
+
config: {
|
|
569
|
+
thinking: "high"
|
|
570
|
+
}
|
|
571
|
+
})
|
|
572
|
+
```
|
|
573
|
+
|
|
574
|
+
### Delete an agent
|
|
575
|
+
|
|
576
|
+
```typescript
|
|
577
|
+
subagent({ action: "delete", agent: "code-analysis.my-agent" })
|
|
578
|
+
```
|
|
579
|
+
|
|
580
|
+
Use management actions when the system needs to create or edit subagents on
|
|
581
|
+
demand without dropping into raw file editing.
|
|
582
|
+
|
|
583
|
+
Management actions create or update user/project agent files. `config.name` is the local frontmatter name; optional `config.package` registers and looks up the runtime name as `{package}.{name}`. Use the dotted runtime name for `get`, `update`, `delete`, slash commands, and chain steps. `get` follows effective runtime precedence by default; `update` and `delete` use `agentScope` only when the same runtime name exists in multiple mutable scopes. For small builtin changes such as a model swap, prefer `subagents.agentOverrides` in settings.
|
|
584
|
+
|
|
585
|
+
## Creating and Editing Agents by File
|
|
586
|
+
|
|
587
|
+
A minimal agent file looks like this:
|
|
588
|
+
|
|
589
|
+
```markdown
|
|
590
|
+
---
|
|
591
|
+
name: my-agent
|
|
592
|
+
package: code-analysis
|
|
593
|
+
description: What this agent does
|
|
594
|
+
---
|
|
595
|
+
|
|
596
|
+
Your system prompt here.
|
|
597
|
+
```
|
|
598
|
+
|
|
599
|
+
This defaults to fresh conversation context while appending the prompt to Pi's base prompt, inheriting project context and skills, preserving normal tools and extensions, and blocking nested delegation. Omit `package` for the traditional unqualified runtime name. Common optional fields include:
|
|
600
|
+
- `defaultProgress`
|
|
601
|
+
- `defaultReads`
|
|
602
|
+
- `output`
|
|
603
|
+
- `fallbackModels`
|
|
604
|
+
- `maxSubagentDepth`
|
|
605
|
+
|
|
606
|
+
For many customizations, builtin overrides in settings are lower-friction than
|
|
607
|
+
copying a full builtin file.
|
|
608
|
+
|
|
609
|
+
## Prompt Template Integration
|
|
610
|
+
|
|
611
|
+
The files under `prompts/` are unregistered examples of common workflows. Parent agents can apply the same recipes directly with `subagent(...)` when the user describes the workflow in natural language.
|
|
612
|
+
|
|
613
|
+
If `pi-prompt-template-model` is installed, additional user prompt templates can delegate into
|
|
614
|
+
`pi-subagents`. This is useful when a slash command should always run through a
|
|
615
|
+
particular agent or with forked context.
|
|
616
|
+
|
|
617
|
+
## Important Constraints
|
|
618
|
+
|
|
619
|
+
- **Forking requires a persisted parent session.** If the current session does not
|
|
620
|
+
have a persisted session file, forked runs fail. Packaged `oracle` defaults to
|
|
621
|
+
forked context; the other Fitch role profiles default to fresh context.
|
|
622
|
+
- **Forked runs inherit parent history.** They are branched threads, not fresh
|
|
623
|
+
filtered contexts. Use fresh context for adversarial reviewers unless the user explicitly asks for forked context.
|
|
624
|
+
- **Default subagent nesting depth is 1.** The parent can delegate; children cannot delegate again unless explicitly configured.
|
|
625
|
+
- **Attention signals are not lifecycle state.** `needs_attention` means no activity has been observed past the configured threshold. `paused` means the child turn was intentionally interrupted or is awaiting direction; it is not the same as `failed`.
|
|
626
|
+
- **Intercom asks are blocking.** A session can only maintain one pending outbound
|
|
627
|
+
ask wait state at a time.
|
|
628
|
+
- **Keep conversational authority clear.** Advisory subagents should not silently
|
|
629
|
+
become second decision-makers.
|
|
630
|
+
|
|
631
|
+
## Best Practices
|
|
632
|
+
|
|
633
|
+
### Prefer async orchestration
|
|
634
|
+
|
|
635
|
+
Launch independent subagents with the default async mode. Omit `async` for scouts, researchers, workers, reviewers, validators, oracle checks, one-off delegates, chains, and non-review parallel groups. Launch reviewer and validator panels as separate single-agent calls, not one parallel group or chain. Continue useful parent work while children run; if none remains, end the turn and wait for automatic completion instead of polling.
|
|
636
|
+
|
|
637
|
+
For an incomplete active Pi goal, keep the async default. Yield when child evidence gates the next step, then continue the goal after automatic completion delivery.
|
|
638
|
+
|
|
639
|
+
For reviewer sign-off, avoid short foreground timeouts. A timeout means review incomplete, not review failed cleanly and not sign-off. Prefer separate async runs, including under active goals. If foreground execution is explicitly chosen, avoid short `timeoutMs`/`maxRuntimeMs` budgets.
|
|
640
|
+
|
|
641
|
+
### Keep writes single-threaded by default
|
|
642
|
+
|
|
643
|
+
A strong pattern is one main decision-maker plus advisory/research/review/validation subagents around it. Use `oracle` for advice and `worker` for the actual write path. Parallelize reading, review, validation, and synthesis support, not normal writes, unless you deliberately isolate writers with worktrees. A child that writes should report what changed, what was left undone, commands run with exit codes, validation evidence, surprises, and any decisions that need parent approval.
|
|
644
|
+
|
|
645
|
+
### Use fork for branched advisory or execution threads
|
|
646
|
+
|
|
647
|
+
Forked runs are useful when the child should reason in a separate thread while
|
|
648
|
+
still inheriting the parent’s accumulated context. They are especially useful for
|
|
649
|
+
`oracle`, which audits inherited decisions and drift. For adversarial code review,
|
|
650
|
+
prefer fresh-context reviewers that inspect the repo and diff directly unless the
|
|
651
|
+
user explicitly requests forked context.
|
|
652
|
+
|
|
653
|
+
### Prefer narrow tasks
|
|
654
|
+
|
|
655
|
+
Give subagents specific tasks rather than vague mandates.
|
|
656
|
+
`Review auth.ts for null-check gaps` works better than `Review everything`.
|
|
657
|
+
|
|
658
|
+
### Escalate decisions upward
|
|
659
|
+
|
|
660
|
+
Make ordinary reversible architecture and implementation choices within the assigned outcome. Coordinate back only when required information or authority is unavailable or a choice would change the owner's settled outcome or scope.
|
|
661
|
+
|
|
662
|
+
### Intervene only on clear control signals
|
|
663
|
+
|
|
664
|
+
Use subagent control proactively when a delegated run emits `needs_attention`, or when a human asks you to regain control. Do not interrupt just because a child has briefly produced no output. Silence can be normal during long tool calls, test runs, or model reasoning.
|
|
665
|
+
|
|
666
|
+
### Name sessions meaningfully
|
|
667
|
+
|
|
668
|
+
Use `/name` so intercom targeting stays stable.
|
|
669
|
+
|
|
670
|
+
## Common Workflows
|
|
671
|
+
|
|
672
|
+
### Recon → Plan → Implement
|
|
673
|
+
|
|
674
|
+
```typescript
|
|
675
|
+
subagent({
|
|
676
|
+
chain: [
|
|
677
|
+
{ agent: "scout", task: "Map the auth flow and summarize relevant files" },
|
|
678
|
+
{ agent: "planner", task: "Plan the migration from {previous}" },
|
|
679
|
+
{ agent: "worker", task: "Implement the approved plan from {previous}" }
|
|
680
|
+
]
|
|
681
|
+
})
|
|
682
|
+
```
|
|
683
|
+
|
|
684
|
+
### Clarify → Plan → Implement → Review (self-orchestrated workflow)
|
|
685
|
+
|
|
686
|
+
When you are the orchestrating agent for a new feature or non-trivial change, use the same orchestration patterns through tools and subagents.
|
|
687
|
+
|
|
688
|
+
Keep effective agent defaults for routine runs; ordinary launches retain configured fallbacks. Warranted overrides remain subject to user instructions and provider authorization; see [Agent selection](../SKILL.md#agent-selection) for the per-run syntax and pinning policy. Packaged `oracle` defaults to forked context; the other Fitch role profiles default to fresh context. Fork is never available to effective `anthropic/` primary or fallback models; other providers continue to use the configured context policy normally.
|
|
689
|
+
|
|
690
|
+
Use the existing task authority to launch helpful subagents and write a role-specific handoff; no separate launch or handoff approval is needed. Include the approved plan path or summary, clarified requirements, non-goals, relevant context, role boundaries, files or areas to inspect, acceptance criteria, expected output, and validation expectations. Do not pass vague instructions like “implement the plan fully” or “review this” by themselves.
|
|
691
|
+
|
|
692
|
+
- Gather context and clarify: launch `scout` and, when needed, `researcher`; synthesize findings; then use the available clarification tool (`ask_question` in pi) for unresolved material questions.
|
|
693
|
+
- Parallel review: launch fresh-context `reviewer` agents with distinct review angles; synthesize the feedback before applying anything.
|
|
694
|
+
- Review loop: keep the parent in charge of worker → fresh reviewers → synthesized fix worker cycles until no fixes worth doing now remain, a concrete decision outside the existing authority appears, or the review-round cap is reached.
|
|
695
|
+
- Parallel research: combine local `scout` context with external `researcher` evidence when current docs, ecosystem behavior, or API details matter.
|
|
696
|
+
- Parallel context build: run a chain-mode parallel group of `context-builder` agents with distinct temp output paths, then synthesize their context and meta-prompt sections.
|
|
697
|
+
- Parallel handoff plan: run external `researcher` plus local/strategy `context-builder` passes, then a synthesis `context-builder` that writes an implementation handoff plan and implementation-ready meta-prompt.
|
|
698
|
+
- Parallel cleanup: use review-only cleanup passes after implementation, especially for simplicity, verbosity, and redundant tests.
|
|
699
|
+
|
|
700
|
+
For feature work, use this sequence as scaffolding for parent-agent behavior:
|
|
701
|
+
|
|
702
|
+
```text
|
|
703
|
+
clarify → validation contract → planner → worker → fresh-context reviewers/validators → fix worker → follow-up review when warranted → parent review
|
|
704
|
+
```
|
|
705
|
+
|
|
706
|
+
The validation contract defines acceptance before code is written: expected behavior, acceptance checks, commands or user flows to exercise, and evidence the worker should return. Keep it lightweight for small tasks, but make it explicit enough that reviewers and validators are checking the intended outcome rather than the worker’s own assumptions.
|
|
707
|
+
|
|
708
|
+
Use the structured `acceptance` field when the run should carry an explicit acceptance contract. If omitted, the run stays lightweight. For review-only tasks, omit it unless the user explicitly requests a same-session acceptance contract; the extra finalization turn is not independent review. When present, acceptance is object-only: define concrete `criteria`, required `evidence`, optional runtime `verify` commands, and optionally `maxFinalizationTurns`. The runtime continues the same child session for a bounded self-review/repair loop before evaluating the final report, so set `acceptance` on single runs, sequential chain steps, parallel task items, and dynamic fanout child templates, not on static parallel or dynamic fanout groups. Independent review stays parent-controlled: `acceptance.review` is unsupported and fails preflight, so launch reviewer subagents separately after the worker completes. The latest substantive finalization answer becomes the result and downstream handoff; report-only finalization preserves the previous substantive answer. Initial output remains audit evidence, not a stale replacement for the corrected result. Child-reported command success is evidence, not runtime verification.
|
|
709
|
+
|
|
710
|
+
Goal-style requests map to `acceptance`. If the user says `/goal`, “goal”, “active goal”, “continue until evidence says done”, or “verify against a goal” for a subagent run, create an explicit run-scoped acceptance contract: `criteria` for the target, `evidence` and `verify` for proof, `stopRules` for constraints, and `maxFinalizationTurns` for the bounded loop budget.
|
|
711
|
+
|
|
712
|
+
When launching a writer/worker from a plan, PRD, spec, issue, or broad fix, set structured `acceptance` proactively. Put implementation instructions, plan paths, and handoff artifacts in `task`; put the definition of done in `acceptance.criteria`, proof requirements in `acceptance.evidence` and `acceptance.verify`, constraints in `acceptance.stopRules`, and usually set `maxFinalizationTurns: 3`. Do not bury all validation requirements only in the task prompt.
|
|
713
|
+
|
|
714
|
+
Example writer handoff:
|
|
715
|
+
|
|
716
|
+
```typescript
|
|
717
|
+
subagent({
|
|
718
|
+
agent: "worker",
|
|
719
|
+
// Async is the default; set async: false for explicitly chosen foreground execution.
|
|
720
|
+
task: "Implement the plan at /Users/me/docs/mcp-alignment-plan.md. Use scout artifacts in ./handoff/ as context. Do not commit the scout artifacts.",
|
|
721
|
+
acceptance: {
|
|
722
|
+
criteria: [
|
|
723
|
+
"Implementation follows /Users/me/docs/mcp-alignment-plan.md",
|
|
724
|
+
"Plan acceptance checks are addressed",
|
|
725
|
+
"Scout handoff artifacts are not committed",
|
|
726
|
+
"Focused validation for changed behavior passes",
|
|
727
|
+
"Residual risks or skipped checks are reported"
|
|
728
|
+
],
|
|
729
|
+
evidence: ["changed-files", "commands-run", "validation-output", "residual-risks"],
|
|
730
|
+
verify: [{ id: "focused", command: "npm test -- --runInBand" }],
|
|
731
|
+
stopRules: [
|
|
732
|
+
"Do not edit unrelated files",
|
|
733
|
+
"Stop and report if the plan requires a decision outside the assigned authority"
|
|
734
|
+
],
|
|
735
|
+
maxFinalizationTurns: 3
|
|
736
|
+
}
|
|
737
|
+
})
|
|
738
|
+
```
|
|
739
|
+
|
|
740
|
+
The first `worker` implements the approved plan. The parent continues with independent inspection or validation prep while it runs only when the worker is async; do not make parallel edits to the same worktree. When an async worker completes, treat its handoff as the transition into review, not as final completion, unless the user explicitly asked for worker-only work, review-only output, or to stop after implementation. Launch parallel reviewers as separate async runs so each completion wakes the parent. Validators check behavior with the best available evidence: commands, tests, browser/CLI interaction, screenshots, logs, or manual reproduction notes. The final `worker` applies synthesized review fixes, then the parent looks over the final diff before completing. Keep these as parent-launched follow-up runs after each completion; do not hide reviewer panels inside an initial async chain. Under an incomplete active Pi goal, a fixed sequence with no intervening parent decision may instead use a bounded foreground chain. Do not stop after parallel review unless the user explicitly asked for review-only output or the review surfaced a concrete decision outside the existing authority.
|
|
741
|
+
|
|
742
|
+
For complex work, risky changes, broad refactors, or many changed lines, increase review and validation fanout rather than trusting one reviewer. Use distinct angles such as correctness/regressions, tests/validation, simplicity/maintainability, security/privacy, performance, docs/API contracts, and user-flow behavior. When reviewers find non-trivial issues or the fix worker touches many lines, run another focused review round before final validation.
|
|
743
|
+
|
|
744
|
+
When review has already produced concrete findings across several independent areas, use staged fix orchestration: parallel read-only planners for each issue cluster, one sole writer worker for the active worktree, then parallel fresh-context validators. This is the safest way to handle a dirty worktree with many prior changes because it parallelizes judgment without parallelizing writes. Non-blocking suggestions may go into the writer prompt only if they are small, safe, and inside the approved scope; otherwise defer them explicitly.
|
|
745
|
+
|
|
746
|
+
For very large work, split into serial milestones instead of launching a swarm of writers. Each milestone gets one writer, a validation contract, fresh-context review/validation, a fix pass, and parent acceptance before the next milestone starts. Use parallel subagents inside a milestone for read-only context, research, review, and validation only.
|
|
747
|
+
|
|
748
|
+
Keep final integration and delivery with the original agent. Bundled children remain leaf agents; launch routine fanout from the parent. Helpers may split their assigned work using the child-safe `subagent` tool only when the user explicitly authorized nesting and their profile/native depth budget already permits it. Parent-only management controls and inherited orchestration records remain filtered by the runtime. Do not infer permission to change `allowSubagents` or the depth budget. Implementation helpers must use real edit/write tools.
|
|
749
|
+
|
|
750
|
+
1. Clarify only material uncertainty. Gather code context with `scout` or `context-builder`, add `researcher` only when external evidence matters, then ask the user unresolved questions with the available clarification tool (`ask_question` in pi) when the answer changes scope, acceptance criteria, constraints, or non-goals.
|
|
751
|
+
2. Define the validation contract. State acceptance before implementation: expected behavior, checks to run, user flows to exercise, and evidence required in the worker handoff. For UI, CLI, integration, or workflow changes, include at least one validator angle that uses the product the way a user would rather than only reading code.
|
|
752
|
+
3. Plan when useful. Use existing authorization and make routine implementation decisions directly. Ask only when required information or authority cannot be obtained, a decision would change the owner's settled outcome or scope, or it crosses a concrete irreversible-loss, private-data, or substantial new-cost boundary.
|
|
753
|
+
4. Implement with one writer. Launch `worker` under the existing authorization with the requirements, relevant context, plan path or summary, validation expectations, and required output. Packaged `worker` defaults to fresh context. While an async worker runs, prepare validation or inspect adjacent code instead of editing the same worktree.
|
|
754
|
+
5. Require a useful worker handoff. Ask the worker to report changed files, what was implemented, what was left undone, commands run with exit codes, validation evidence, surprises or new risks, decisions made inside approved scope, and decisions needing parent approval.
|
|
755
|
+
6. Review after implementation. After the worker completes, launch fresh-context `reviewer` agents for correctness/regressions, tests/validation, and simplicity/maintainability as separate async runs so each completion wakes the parent. Add security, performance, docs/API, domain-specific, or user-flow validators for complex work, risky changes, broad refactors, or many changed lines. Use `output: false` unless review artifacts are explicitly needed.
|
|
756
|
+
7. Synthesize, then run the fix worker. Separate blockers, fixes worth doing now, optional improvements, and feedback to ignore/defer, then launch an async `worker` to apply fixes worth doing now when the workflow is implementation-authorized. Make ordinary reversible fixes within existing authority; escalate only a concrete blocker or decision outside the owner's outcome and scope.
|
|
757
|
+
8. Review again when warranted. If the fix worker made substantial changes or addressed non-trivial findings, run another focused parallel review round before final validation.
|
|
758
|
+
9. Validate and complete. After the fix worker and any follow-up review return, inspect the final diff yourself, run or confirm focused validation, update docs/changelog when relevant, and summarize what changed and why.
|
|
759
|
+
|
|
760
|
+
Example implementation handoff after clarification and optional planning:
|
|
761
|
+
|
|
762
|
+
```typescript
|
|
763
|
+
subagent({
|
|
764
|
+
agent: "worker",
|
|
765
|
+
task: "Implement the approved feature.\n\nClarified requirements:\n- ...\n\nPlan: see ~/Documents/docs/...-plan.md\n\nValidation contract:\n- ...\n\nReturn a handoff with changed files, what was implemented, what was left undone, commands run with exit codes, validation evidence, surprises/new risks, and decisions needing parent approval.",
|
|
766
|
+
acceptance: {
|
|
767
|
+
criteria: ["Implement the approved feature without widening scope"],
|
|
768
|
+
evidence: ["changed-files", "tests-added", "commands-run", "residual-risks", "no-staged-files"],
|
|
769
|
+
maxFinalizationTurns: 3
|
|
770
|
+
}
|
|
771
|
+
// Async is the default; set async: false for explicitly chosen foreground execution.
|
|
772
|
+
})
|
|
773
|
+
```
|
|
774
|
+
|
|
775
|
+
Example review pass after implementation:
|
|
776
|
+
|
|
777
|
+
```typescript
|
|
778
|
+
subagent({ agent: "reviewer", task: "Review the current diff for correctness and regressions. Inspect changed files directly; do not rely on the worker's reasoning.", context: "fresh", output: false })
|
|
779
|
+
subagent({ agent: "reviewer", task: "Review the current diff for tests and validation quality against the validation contract. Inspect changed files directly.", context: "fresh", output: false })
|
|
780
|
+
subagent({ agent: "reviewer", task: "Review the current diff for simplicity and maintainability. Inspect changed files directly.", context: "fresh", output: false })
|
|
781
|
+
// Each completion wakes the parent. Continue useful work or end the turn and wait; do not poll.
|
|
782
|
+
```
|
|
783
|
+
|
|
784
|
+
Example fix worker after parallel reviews:
|
|
785
|
+
|
|
786
|
+
```typescript
|
|
787
|
+
subagent({
|
|
788
|
+
agent: "worker",
|
|
789
|
+
task: "Apply the synthesized reviewer feedback below. Only apply fixes worth doing now; preserve user-approved scope; make ordinary reversible choices; escalate only concrete decisions outside the assigned authority. Run focused validation and summarize what changed.\n\nReviewer synthesis:\n..."
|
|
790
|
+
// Async is the default; set async: false for explicitly chosen foreground execution.
|
|
791
|
+
})
|
|
792
|
+
```
|
|
793
|
+
|
|
794
|
+
### Review loop
|
|
795
|
+
|
|
796
|
+
Do not treat review as the final step for implementation work. Run reviewers and validators, synthesize their findings against user scope and the validation contract, then launch one `worker` for accepted fixes when implementation is authorized.
|
|
797
|
+
|
|
798
|
+
When an async implementation worker completes, treat the worker handoff as an intermediate state. The next parent action is separate async review runs, then synthesis, then an async fix worker if reviewers found fixes worth doing now. Keep these as parent-launched follow-up runs so each reviewer completion wakes the parent; do not put the review panel inside one async chain.
|
|
799
|
+
|
|
800
|
+
For explicit review-loop requests, repeat worker → fresh-reviewer → synthesized-fix-worker cycles until reviewers find no blockers or fixes worth doing now, remaining feedback is optional or intentionally deferred, a concrete decision outside existing authority needs the user, or the max review-round cap is reached. Default to 3 review rounds unless the user sets a different cap. For complex work, many changed lines, or any fix pass that materially changes the diff, run another focused review round before the parent’s final look; otherwise stop instead of chasing optional polish.
|
|
801
|
+
|
|
802
|
+
### Parallel non-conflicting analysis
|
|
803
|
+
|
|
804
|
+
```typescript
|
|
805
|
+
subagent({
|
|
806
|
+
tasks: [
|
|
807
|
+
{ agent: "scout", task: "Audit frontend auth flow" },
|
|
808
|
+
{ agent: "researcher", task: "Research current retry/backoff best practices" }
|
|
809
|
+
]
|
|
810
|
+
})
|
|
811
|
+
```
|
|
812
|
+
|
|
813
|
+
### Saved chain
|
|
814
|
+
|
|
815
|
+
```text
|
|
816
|
+
/run-chain review-chain -- review this branch
|
|
817
|
+
```
|
|
818
|
+
|
|
819
|
+
Use saved `.chain.md` or `.chain.json` workflows when the user wants a repeatable multi-agent flow without rewriting the chain each time. Prefer `.chain.json` for dynamic fanout or inline `outputSchema` objects; `.chain.md` remains the simple sequential/static authoring format.
|
|
820
|
+
|
|
821
|
+
## Error Handling
|
|
822
|
+
|
|
823
|
+
**"Unknown agent"**
|
|
824
|
+
```typescript
|
|
825
|
+
subagent({ action: "list" })
|
|
826
|
+
// Check available agents and chains, then confirm scope/precedence.
|
|
827
|
+
```
|
|
828
|
+
|
|
829
|
+
**Setup, discovery, or intercom confusion**
|
|
830
|
+
```typescript
|
|
831
|
+
subagent({ action: "doctor" })
|
|
832
|
+
// Check runtime paths, async support, discovery counts, current session, and intercom bridge state.
|
|
833
|
+
```
|
|
834
|
+
|
|
835
|
+
**"Max subagent depth exceeded"**
|
|
836
|
+
```typescript
|
|
837
|
+
// Flatten the workflow or raise maxSubagentDepth in config.
|
|
838
|
+
```
|
|
839
|
+
|
|
840
|
+
**"Session manager did not return a session file"**
|
|
841
|
+
```typescript
|
|
842
|
+
// Persist the current session before using context: "fork".
|
|
843
|
+
```
|
|
844
|
+
|
|
845
|
+
**Intercom "Already waiting for a reply"**
|
|
846
|
+
```typescript
|
|
847
|
+
// Resolve the current outbound ask before starting another one.
|
|
848
|
+
```
|
|
849
|
+
|
|
850
|
+
**Parallel output-path conflict**
|
|
851
|
+
```typescript
|
|
852
|
+
// Give each parallel task a distinct output path, or disable output for tasks that do not need it.
|
|
853
|
+
```
|
|
854
|
+
|
|
855
|
+
**Worktree launch fails**
|
|
856
|
+
```typescript
|
|
857
|
+
// Ensure the git working tree is clean and task cwd overrides match the shared cwd.
|
|
858
|
+
```
|
|
859
|
+
|
|
860
|
+
**Child fails before starting**
|
|
861
|
+
```typescript
|
|
862
|
+
// Inspect `subagent({ action: "status", id: "..." })`, artifact metadata/output logs, and run doctor. Extension loader errors usually appear in child output logs.
|
|
863
|
+
```
|