# ultra Multi-agent workflow orchestration for Pi. A declarative JSON spec fans sub-agents out across phases under a concurrency cap, validates their structured output, and aggregates the results — with live progress on both an interactive overlay and a model-callable tool surface. ## Two surfaces - **`/ultra`**: enables the hidden `run_workflow` tool for later agent turns, confirms activation, and does not start a turn. - **`/ultra exec `**: enables the tool, sends the complete orchestration prompt as a visible user message, and starts an agent turn to choose, design, or run a workflow. - **`/ultra run [args]`**: runs a saved workflow behind a phase-first live overlay with keyboard phase toggling, agent focus, streaming transcripts, steering, targeted abort, and confirmed whole-run abort. - **`run_workflow` tool**: model-callable after `/ultra` enables it. Pass a saved workflow `name` (+ optional `args`), or an inline `spec` object for a one-off run. Returns the aggregated JSON; progress streams to a collapsible result surface. ## Workflows Use ultra only when independent parallel work, staged agent handoffs, or isolated specialist contexts materially improve the result. Otherwise perform the task directly instead of wrapping it in ultra. A workflow is a single JSON object — phases (`single` / `fanout`), per-step prompts/tools/schemas, and a closed interpolation grammar that pipes one phase's results into the next. The authoritative format reference is - [`prompts/references/spec-format.md`](prompts/references/spec-format.md) — the single source of truth, kept in lockstep with the runtime validator by a test. Don't reconstruct the format from memory; read it. ### Authoring Run `/ultra exec ` to send the complete orchestration prompt as a visible user message and enable the `run_workflow` tool for the next agent turn. The agent chooses an ephemeral one-off or persisted workflow when confidence is high, and asks one focused question when it is not. Persisted authoring covers phases, fan-out mutation ownership, dynamic-extension delegation, schemas plus join-keys, interpolation, and where to save. ### Where workflows live Discovery merges three locations, lowest-to-highest precedence (a later source overrides a bundled name). Workflow files are rescanned on every completion or invocation, so newly saved JSON works immediately without `/reload`. 1. **bundled** — `extensions/ultra/workflows/*.json` (ships with ultra) 2. **global** — `~/.pi/agent/workflows/*.json` 3. **project** — `/.pi/workflows/*.json` The shipped `review` workflow reviews the diff across dimensions, adversarially verifies each finding, then synthesizes a concise analysis with concrete next steps. Run it with `/ultra run review [base-ref]` (no base ref reviews the working tree; a base ref reviews everything since it). The shipped `feature` workflow drives a small feature end to end — research → plan → adversarial critique → strengthened plan → implement → conditional security/quality review — run it with `/ultra run feature ` (the whole trailing text is the task). A dedicated read-only phase rewrites the plan to resolve critique blockers before implementation. Only its `implement` phase writes; every other phase is read-only. The shipped `bug` workflow drives investigate → regression test → conditional fix → adversarial verification. Run it with `/ultra run bug `. The fix runs only after the regression phase proves the expected failure; verification runs only after a fix. The shipped `research` workflow drives question planning → parallel multi-source evidence gathering → gap and contradiction audit → targeted adversarial verification → cited synthesis. Run it with `/ultra run research `. Loaded research extensions may activate their own tools for its agents. ## Results Completed review runs show synthesized analysis, verified and refuted findings, drops, and concrete recommended next steps. Expand the result only when raw JSON is needed. Workflow runs append incomplete-run checkpoints to the current Pi session as custom entries that never enter LLM context. Each launched step also gets a named persistent child session linked to the parent session and resumable after interruption. The parent journal stores child identity before prompting; the next matching run continues unchanged incomplete steps and reruns changed work in clean children. Completed runs start fresh but retain their named child sessions for `/resume` inspection. No-session parents and `ultra.subagentSessionRetention = "none"` keep children entirely in memory. Both progress surfaces use the same phase-first hierarchy, authored step summaries, status language, icons, elapsed time, counts, checkpoint state, token usage, and cost. Active and dropped agents use task-first two-line rows; completed and queued agents compact to one line. The overlay also shows each exact resolved sub-agent prompt as the first user message in its transcript. Sub-agent tool calls keep one native Pi tool row from invocation through result and follow Pi's global expand state. Collapsed workflow tool output remains counts-only with Pi's standard expand hint. Expanded tool output summarizes every phase, automatically opens the active and failed phases, shows their agents, and ends with the human-readable workflow outcome. The command overlay uses the same board, automatically collapses completed phases, and adds keyboard interaction. Use `↑`/`↓` to focus visible phase or agent rows, `Enter` to toggle a phase, and `Tab` to cycle visible agents. Use `Alt+↑`/`Alt+↓` to scroll the focused transcript, `s` to steer, and `x` to abort the focused agent. Aborting the whole run requires two `Esc` presses within 1.5 seconds. Known agents appear queued before launch; dynamic fan-outs show `agents not planned yet`; conditional phases show `conditional` until their selectors resolve. Rows transition through queued, running, done, dropped, or skipped without disappearing from their phase summary. Configured tiers are shown as `tier → provider/model`. Workflow results include aggregate token and cost usage from completed sub-agent turns when the provider reports it. The final JSON contains `tokenUsage` with `input`, `output`, `total`, `cacheRead`, `cacheWrite`, and `cost`. Totals count every assistant response from launched steps exactly once, including result-submission reminders and failed or aborted attempts; reused checkpoints add no new usage. Every dropped step produces a typed diagnostic in `phaseFailures` with its code, message, retryability, attempt count, model, thinking level, original item, accumulated usage, and a bounded final transcript tail when available. Expanded boards show compact failure and retry metadata; the final JSON retains every diagnostic field. A later phase may consume `{PHASE.failures}` through `when`, `over`, prompts, or `return` to perform one explicit linear recovery pass. Ultra never drops work because of elapsed time and never creates automatic recovery loops. ## Settings Read from the `ultra` block of agent settings, `/.pi/settings.json`, and `/settings.json` (later overriding earlier), with the runtime settings manager on top. | Key | Default | Meaning | | ----------------------------- | ------- | ---------------------------------------------------------- | | `ultra.enabled` | `true` | When false, the tool + command refuse to run. | | `ultra.auto_enable` | `false` | Enable `run_workflow` when each session starts. | | `ultra.concurrency` | `5` | Max concurrent sub-agents in a `fanout` phase. | | `ultra.maxRetries` | `2` | Result-submission reminders after a missing output. | | `ultra.subagentExtensions` | `"all"` | Load all, none, or a static extension-name list. | | `ultra.subagentSkills` | `"all"` | Load host skills into sub-agents, or not. | | `ultra.subagentSessionRetention` | `"all"` | Retain parent-linked child sessions; `"none"` is stateless. | | `ultra.modelTiers` | `{}` | Optional `small` / `medium` / `big` model aliases. | | `ultra.actionSummarizerModel` | `null` | Fast model for concise tool-action phrases; off when null. | `ultra.actionSummarizerModel` accepts a concrete `provider/model` ref. Ultra immediately renders a terse tool-aware action such as `Reading settings.ts`, then replaces it with the best-effort LLM phrase when available. Collapsed transcripts hide redundant tool previews; expand tools to inspect their complete native Pi arguments and results. Requests use bounded input, 40 output tokens, no retries, no prompt caching, and a two-second timeout. Rapid actions coalesce independently per agent, only one request runs at once, and an agent's final pending action flushes when it finishes. Workflow completion cancels leftover requests. Failures keep the deterministic fallback and never affect workflow execution. Unknown tool arguments and results use bounded top-level JSON summaries instead of raw JSON dumps. Tool arguments are sent to the configured model without secret redaction. `ultra.modelTiers` maps workflow step `model` values of `small`, `medium`, or `big` to concrete model refs. Unset tiers fall back to the session model. A tier value may end with a thinking suffix (`:off`, `:minimal`, `:low`, `:medium`, `:high`, `:xhigh`, `:max`), used when the step omits `thinkingLevel`; `max` is the highest opt-in budget and requires model support. Bundled workflows explicitly assign tiers by phase role and thinking levels by relative complexity. ```json { "ultra": { "actionSummarizerModel": "openai/gpt-5-mini", "modelTiers": { "small": "openai/gpt-5-mini:low", "medium": "anthropic/claude-sonnet-4:medium", "big": "openai/gpt-5.1:xhigh" } } } ``` `ultra.subagentExtensions` accepts `"all"` (default), `"none"`, or a static array of sibling pi-ext extension names. An array loads every named extension into every child; Ultra performs no per-model or per-tool selection. An empty array is equivalent to `"none"`. Unknown names fail workflow startup. A step's `tools` array selects its initial active tools; loaded extensions may register and activate additional tools through their hooks. Extension selection is therefore the trust boundary, including for fanout mutation safety. Ultra strips its own `run_workflow` tool from the initial set to prevent ordinary recursive orchestration. Steps may additionally name validated catalog identities through `dynamicExtensions`; those load after normal extensions from exact run-local hash snapshots. Builder steps select all four dynamic-extension tools and receive the complete authoring contract, while consumers receive none of it. Ultra refuses to start a workflow when a listed tool is unavailable to its selected extensions. `ultra.subagentSkills` (`"all"` | `"none"`, default `"all"`) controls skill discovery for workflow sub-agents. Skills use Pi's normal global, project, package, and settings discovery, plus resources from every loaded extension. `"all"` also grants the built-in `read` tool so the agent can load selected `SKILL.md` files; every other tool remains workflow-gated. `"none"` omits all skills. ## Install / load This extension is loaded through the root pi-ext package. See [../../README.md](../../README.md).