repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

extensions/ultra/README.md

Raw

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

Workflows

Use ultra for fan-out, multi-phase orchestration, or a single agent that specifically needs isolation, background execution, an alternate model, resumability, or strict structured output. For an ordinary one-agent task, 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

— 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

The bundled authoring-workflows skill walks through co-designing and saving a workflow (phases, the read-only fan-out rule, schemas + join-keys, interpolation, where to save). It is model-invocable — ask to "create / author / save a workflow" and it activates.

Where workflows live

Discovery merges three locations, lowest-to-highest precedence (a later source overrides a bundled name):

  1. bundled — extensions/ultra/workflows/*.json (ships with ultra)
  2. global — ~/.pi/agent/workflows/*.json
  3. project — <cwd>/.pi/workflows/*.json

The shipped review workflow reviews the diff across dimensions, then adversarially verifies each finding — run it with /ultra 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 → implement → security/quality review — run it with /ultra feature <describe the task> (the whole trailing text is the task). Only its implement phase writes; every other phase is read-only.

Results

The workflow tool accepts background: true to start a run and return immediately. When the detached run finishes, ultra sends its result back into the conversation. /ultra-runs opens a saved-run picker for inspecting, resuming, stopping, or deleting runs. Run records live under ~/.pi/agent/ultra-runs/.

Workflow runs write an incomplete-run resume journal under ~/.pi/agent/ultra-journals/. If a run is aborted, the next run of the same workflow name, cwd, and args reuses completed matching steps and runs the missing/changed steps. A completed run marks its journal complete, so later runs start fresh.

Expanded workflow tool output renders each sub-agent as a multiline block: identity/status, resolved model metadata, elapsed time and reported tokens, then latest action. Configured tiers are shown as tier → provider/model; collapsed output remains summary-only.

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.

Settings

Read from the ultra block of agent settings, <cwd>/.pi/settings.json, and <cwd>/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.concurrency 5 Max concurrent sub-agents in a fanout phase.
ultra.maxRetries 2 Schema-validation retries per step.
ultra.defaultTimeoutMs 180000 Per-step timeout when a step omits timeoutMs.
ultra.subagentExtensions "all" Load host extensions into sub-agents, or not.
ultra.modelTiers {} Optional small / medium / big model aliases.

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), used when the step omits thinkingLevel.

{
  "ultra": {
    "modelTiers": {
      "small": "openai/gpt-5-mini:low",
      "medium": "anthropic/claude-sonnet-4:medium",
      "big": "openai/gpt-5.1:xhigh"
    }
  }
}

ultra.subagentExtensions ("all" | "none", default "all") controls whether workflow sub-agents load the host's extensions. With "all", a step can grant any tool an installed extension provides (e.g. web_search); with "none", sub-agents are isolated to the core tools (bash, find, grep, ls, read, ripgrep). Either way the step's tools allowlist is the only gate on what's active, and ultra's own workflow tool is never grantable to a sub-agent. Workflows should name tools, never extensions — a workflow that lists a tool no installed extension provides simply runs without it.

Install / load

This extension is loaded through the root pi-ext package. See ../../README.md.

Markdown source
File outline
# 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 <name> [args]`** — interactive command. Runs a saved workflow behind a
  live overlay: a per-agent board, `Tab`/`↑↓` to focus an agent and drill into its
  streaming transcript, steer a running sub-agent, and `Esc` to abort. UI only —
  headless callers use the tool.
- **`workflow` tool** — model-callable, mid-turn. 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 for fan-out, multi-phase orchestration, or a single agent that specifically needs isolation, background execution, an alternate model, resumability, or strict structured output.
For an ordinary one-agent task, 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

- [`skills/authoring-workflows/references/spec-format.md`](skills/authoring-workflows/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

The bundled **`authoring-workflows`** skill walks through co-designing and saving a
workflow (phases, the read-only fan-out rule, schemas + join-keys, interpolation,
where to save). It is model-invocable — ask to "create / author / save a workflow"
and it activates.

### Where workflows live

Discovery merges three locations, lowest-to-highest precedence (a later source
overrides a bundled name):

1. **bundled** — `extensions/ultra/workflows/*.json` (ships with ultra)
2. **global** — `~/.pi/agent/workflows/*.json`
3. **project** — `<cwd>/.pi/workflows/*.json`

The shipped `review` workflow reviews the diff across dimensions, then
adversarially verifies each finding — run it with `/ultra 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 → implement → security/quality review —
run it with `/ultra feature <describe the task>` (the whole trailing text is the
task). Only its `implement` phase writes; every other phase is read-only.

## Results

The `workflow` tool accepts `background: true` to start a run and return immediately.
When the detached run finishes, ultra sends its result back into the conversation.
`/ultra-runs` opens a saved-run picker for inspecting, resuming, stopping, or deleting runs.
Run records live under `~/.pi/agent/ultra-runs/`.

Workflow runs write an incomplete-run resume journal under `~/.pi/agent/ultra-journals/`.
If a run is aborted, the next run of the same workflow name, cwd, and args reuses completed matching steps and runs the missing/changed steps.
A completed run marks its journal complete, so later runs start fresh.

Expanded workflow tool output renders each sub-agent as a multiline block: identity/status, resolved model metadata, elapsed time and reported tokens, then latest action.
Configured tiers are shown as `tier → provider/model`; collapsed output remains summary-only.

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`.

## Settings

Read from the `ultra` block of agent settings, `<cwd>/.pi/settings.json`, and
`<cwd>/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.concurrency`        | `5`      | Max concurrent sub-agents in a `fanout` phase.     |
| `ultra.maxRetries`         | `2`      | Schema-validation retries per step.                |
| `ultra.defaultTimeoutMs`   | `180000` | Per-step timeout when a step omits `timeoutMs`.    |
| `ultra.subagentExtensions` | `"all"`  | Load host extensions into sub-agents, or not.      |
| `ultra.modelTiers`         | `{}`     | Optional `small` / `medium` / `big` model aliases. |

`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`), used when the step omits `thinkingLevel`.

```json
{
  "ultra": {
    "modelTiers": {
      "small": "openai/gpt-5-mini:low",
      "medium": "anthropic/claude-sonnet-4:medium",
      "big": "openai/gpt-5.1:xhigh"
    }
  }
}
```

`ultra.subagentExtensions` (`"all"` | `"none"`, default `"all"`) controls whether
workflow sub-agents load the host's extensions. With `"all"`, a step can grant any
tool an installed extension provides (e.g. `web_search`); with `"none"`, sub-agents
are isolated to the core tools (`bash`, `find`, `grep`, `ls`, `read`, `ripgrep`).
Either way the step's `tools` allowlist is the only gate on what's active, and
ultra's own `workflow` tool is never grantable to a sub-agent. Workflows should
name **tools**, never extensions — a workflow that lists a tool no installed
extension provides simply runs without it.

## Install / load

This extension is loaded through the root pi-ext package.
See [../../README.md](../../README.md).