/** * tool-description.ts — the model-facing description of the `SubagentWorkflow` tool. * * This is a deliberate port of Claude Code's `Workflow` tool description, not a * paraphrase of it. The rule the text is held to: **match Claude Code's wording * everywhere; deviate only in the specific clause where its sentence would be * false about pi, and keep that deviation minimal and in its voice.** Wording * parity is the point — a user who knows one tool should not have to relearn * the other, and the orchestration patterns below are load-bearing guidance * that gets used badly when compressed. * * Parts omitted because pi has no such feature: the `ultracode` opt-in, MCP * tools reached through `ToolSearch`, the `agent-.jsonl` resume fallback, * and the `/config` workflow-size guideline. * * Clauses that had to deviate, each because Claude Code's is untrue here: * - `schema` is pressure, not force — `toolChoice` is not plumbed through * pi's `AgentSession`, so a child can decline and the call returns null. * - `budget.total` is always null; pi has no token-target directive. * - `parallel` propagates a fatal run error instead of folding it to null. * - `effort` inherits the agent definition's level, then the parent's. * - `isolation` removes the worktree on settle (kept if cleanup fails), changes kept on a branch. * Additions with no upstream counterpart: `gate`, `resume`, `effort: "minimal"`, * the saved-workflow directories, and the reject-unknown-options guarantee. * * Kept out of index.ts purely for size. `{{placeholder}}` tokens are rendered by * the same substitution pass the Agent tool's description uses, so a * user-authored override can interpolate the live agent roster. */ /** * Rendered with `{{typeList}}` substituted. Keep the prose accurate to what the * runtime actually implements — documenting a global we do not ship is worse * than documenting nothing, because the script only fails once it is running. * `workflow-tool-description.test.ts` pins the parts that can drift: the * `agent()` option set, the `resume` exclusions, the effort levels, the caps, * and that every example here uses options the runtime actually accepts. */ export const fullWorkflowToolDescription = `Execute a workflow script that orchestrates multiple subagents deterministically. Workflows run in the background — this tool returns immediately with a task ID, and you are notified when the workflow completes. Use /agents → Workflows to watch live progress. A workflow structures work across many agents — to be comprehensive (decompose and cover in parallel), to be confident (independent perspectives and adversarial checks before committing), or to take on scale one context can't hold (migrations, audits, broad sweeps). The script is where you encode that structure: what fans out, what verifies, what synthesizes. ONLY call this tool when the user has explicitly opted into multi-agent orchestration. Workflows can spawn dozens of agents and consume a large amount of tokens; the user must request that scale, not have it inferred. Explicit opt-in means one of: - The user directly asked you to run a workflow or use multi-agent orchestration in their own words ("use a workflow", "run a workflow", "fan out agents", "orchestrate this with subagents"). The ask must be in the user's words — a task that would merely benefit from a workflow does not count. - The user invoked a skill or slash command whose instructions tell you to call SubagentWorkflow. - The user asked you to run a specific named or saved workflow. For any other task — even one that would clearly benefit from parallelism — do NOT call this tool. Use the Agent tool for individual subagents, or briefly describe what a multi-agent workflow could do and how much it would roughly cost, and ask the user whether to run it. Mention they can ask for one with "use a workflow" in a future message to skip the ask. When you do call it, the right move is often **hybrid**: scout inline first (list the files, find the channels, scope the diff) to discover the work-list, then call SubagentWorkflow to pipeline over it. You don't need to know the shape before the *task* — only before the *orchestration step*. Common single-phase workflows you can chain across turns: - **Understand** — parallel readers over relevant subsystems → structured map - **Design** — judge panel of N independent approaches → scored synthesis - **Review** — dimensions → find → adversarially verify (example below) - **Research** — multi-modal sweep → deep-read → synthesize - **Migrate** — discover sites → transform each (worktree isolation) → verify For larger work, run several in sequence — read each result before deciding the next phase. You stay in the loop; each workflow is one well-scoped fan-out. Pass the script inline via \`script\` — do not Write it to a file first. Every invocation automatically persists its script to a file under the session directory and returns the path in the tool result. To iterate on a workflow, edit that file with Write/Edit and re-invoke SubagentWorkflow with \`{scriptPath: ""}\` instead of resending the full script. A script you will run more than once belongs in \`.pi/workflows/.js\` (or \`.agents/workflows/\`, or \`/workflows/\` for one that follows the user everywhere); call it with \`name: ""\` instead of re-sending the source. Every script must begin with \`export const meta = {...}\`: export const meta = { name: 'find-flaky-tests', description: 'Find flaky tests and propose fixes', // one-line, shown in permission dialog phases: [ // one entry per phase() call { title: 'Scan', detail: 'grep test logs for retries' }, { title: 'Fix', detail: 'one agent per flaky test' }, ], } // script body starts here — use agent()/parallel()/pipeline()/phase()/log() phase('Scan') const flaky = await agent('grep CI logs for retry markers', {schema: FLAKY_SCHEMA}) ... The \`meta\` object must be a PURE LITERAL — no variables, function calls, spreads, or template interpolation. Required fields: \`name\`, \`description\`. Optional: \`whenToUse\` (shown in the workflow list), \`phases\`. Use the SAME phase titles in meta.phases as in phase() calls — titles are matched exactly; a phase() call with no matching meta entry just gets its own progress group. Add \`model\` to a phase entry when that phase uses a specific model override. Script body hooks: - agent(prompt: string, opts?: {label?: string, phase?: string, schema?: object, model?: string, effort?: string, isolation?: 'worktree', agentType?: string, gate?: string, resume?: string}): Promise — spawn a subagent. Without schema, returns its final text as a string. With schema (a JSON Schema), the subagent is given a StructuredOutput tool built from it and agent() returns the validated object — no parsing needed. A payload that does not match is rejected back to the child, which corrects it; a child that never answers through the tool gets one more prompt and then fails, so the call returns null — filter after every schema stage. Returns null if the user skips the agent mid-run or the subagent dies on a terminal API error after retries (filter with .filter(Boolean)). opts.label overrides the display label. opts.phase explicitly assigns this agent to a progress group (use this inside pipeline()/parallel() stages to avoid races on the global phase() state — same phase string → same group box). opts.model overrides the model for this agent call. Default to omitting it so the configured selection policy applies: agentModels for the type, then agentModels["*"], then the agent definition, then the parent model. Only set it when you're highly confident a different tier fits the task; when unsure, omit. opts.effort overrides the reasoning effort for this agent call ('minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max') — omit to inherit the agent definition's own level, then the parent's; use 'low' for cheap mechanical stages and higher tiers only for the hardest verify/judge stages. opts.isolation: 'worktree' runs the agent in a fresh git worktree — EXPENSIVE (setup time + disk per agent), use ONLY when agents mutate files in parallel and would otherwise conflict; the worktree is removed when the agent settles, its changes preserved on a branch; if cleanup fails the worktree is kept and the agent errors. opts.gate: '' runs a shell command after the agent finishes and requires it to pass — a non-zero exit marks the agent failed, returns null to the script, and records the command output on the workflow agent error; prefer gate: 'npm test' over asking another agent whether the code looks right. opts.resume: '