Document the ultra layer
This commit is contained in:
1 parent
2c1dbb6344
commit
8a4c225386
4 files changed
+91
-4
No files matched your search
@@ -1,11 +1,11 @@
|
||||
---
|
||||
name: workflow-authoring
|
||||
description: Author and start pi-subagent workflow files — markdown plans whose YAML step list runs as a DAG of agents, including each-step fan-out over a prior step's lines. Use when writing or fixing a file under .pi/workflows/ or the user workflows directory, when a delegation needs fan-out/fan-in over several named results, or when a repeatable multi-step plan should live in a file instead of the parent's context.
|
||||
description: Author and start pi-subagent workflow files — markdown plans whose YAML step list runs as a DAG of agents, including each-step fan-out over a prior step's lines. Use when writing or fixing a file under .pi/workflows/ or the user workflows directory, when authoring a one-off inline plan for the `ultra` tool, when a delegation needs fan-out/fan-in over several named results, or when a repeatable multi-step plan should live in a file instead of the parent's context.
|
||||
---
|
||||
|
||||
# Workflow authoring
|
||||
|
||||
A **workflow** is a markdown plan that the subagent extension executes as a DAG of agent steps. Authoring one is editing a frontmatter file; starting one is the `workflow` tool or the `/workflow` command. The plan lives in a file — reviewable in a diff, rerunnable, and never derived inside the parent's context.
|
||||
A **workflow** is a markdown plan that the subagent extension executes as a DAG of agent steps. Authoring one is editing a frontmatter file; starting one is the `workflow` tool or the `/workflow` command, or passing the same document inline to the `ultra` tool. The plan lives in a file — reviewable in a diff, rerunnable, and never derived inside the parent's context — unless it is a one-off inline plan (see [Inline plans (ultra)](#inline-plans-ultra)).
|
||||
|
||||
The loader is strict: unknown frontmatter and step fields are rejected, and every validation failure happens before a child spawns. When a start fails, fix the message's cause rather than retrying.
|
||||
|
||||
@@ -144,6 +144,31 @@ A run is an ordinary job:
|
||||
- `subagent_jobs { action: "cancel", jobId }`, `/subagents <jobId>`, and `/subagents cancel <jobId>` for the human-facing views.
|
||||
- One **journal** entry per run is recorded when it reaches a terminal state: plan, per-step and per-item records, bounded outputs, usage. A run interrupted by reload, quit, `/new`, resume, or fork restores as `interrupted` and never resumes.
|
||||
|
||||
## Inline plans (ultra)
|
||||
|
||||
The `ultra` tool runs the same plan document inline, passed as a `plan` string with optional `args` and `cwd`. Parse, validation, caps, agent resolution, and the trust gate are the file path's — see [File shape](#file-shape), [Frontmatter fields](#frontmatter-fields), and [Caps and bounds](#caps-and-bounds) above — so field names, placeholders, and failure messages transfer unchanged. The body is still ignored.
|
||||
|
||||
Author an inline plan for a one-off: a plan derived for this task that will not run again. Save a file under `.pi/workflows/` when the plan is worth rerunning — a diff to review, a name to start, and a copy outside the session. There is no save action. The run's journal (plan source `"inline"`) is the inline plan's only persisted copy, so a plan that proved useful has to be re-authored as a file to outlive the session.
|
||||
|
||||
Every inline start is validated before any child spawns, and each fan-out is re-checked against the caps before its item children spawn. With a UI and ultra mode off, a review card shows the plan, the child-count estimate against the caps, and every named agent with its source before the run starts; declining spawns nothing. Mode on is the consent: no card. Print/JSON sessions start directly. Project agents named by the plan still pass the project-agent confirmation.
|
||||
|
||||
### Patterns and their declarative shapes
|
||||
|
||||
The reason to plan is structural: one context plans, separate contexts work. Six shapes cover most plans: four have a declarative shape (tournament only by pre-expanding the bracket), and two do not.
|
||||
|
||||
| Pattern | Declarative shape |
|
||||
|---|---|
|
||||
| Fan-out and synthesize | An each-step over the items, then a fan-in step that needs it. |
|
||||
| Adversarial verification | A verify step that needs the producer step, so the verifier reads `{steps.<producer>.output}`. |
|
||||
| Generate and filter | Parallel producer steps, then a filter step that needs them and picks the survivors. |
|
||||
| Tournament | Pre-expanded competitor steps and judge fan-ins; no in-plan loop, so write the bracket out. |
|
||||
| Classify and act | Not expressible: routing is a conditional. Run one plan per class from the parent. |
|
||||
| Loop until done | Not expressible: plans have no loops. Chain runs from the parent instead. |
|
||||
|
||||
The substitute for the two inexpressible shapes is chaining runs, not compressing them into one plan: one run to understand, one to change, one to verify, started as the parent's judgment dictates. Wait for each run before deciding the next; the run's final step output is the consolidated answer.
|
||||
|
||||
For cost, run a small slice first: a narrow glob, one representative item, or one competitor. If the shape holds, widen the plan; if it does not, the failure cost a slice, not the run.
|
||||
|
||||
## Example: a linear audit chain
|
||||
|
||||
Two steps: a scan, then a fan-in that consumes its output. No `each` — the merge step sees the whole scan output at once.
|
||||
|
||||
@@ -6,6 +6,14 @@
|
||||
- Replace TUI `/subagents` notifications with a live, keyboard-driven dashboard for job navigation, per-task activity, output, usage, filtering, expansion, and confirmed cancellation. RPC retains text output.
|
||||
- Surface bounded live activity for async tasks without persisting every message, and make synchronous subagent output compact by default with full details available through expansion.
|
||||
|
||||
Ultra layer (spec #14): policy and authoring surfaces over the workflow engine.
|
||||
|
||||
- `ultra` tool: inline plans in the workflow schema, parsed and validated before any child spawns, with one review card per start while ultra mode is off; the journal (`source: "inline"`) is the plan's only persisted copy (ADR 0005).
|
||||
- Ultra mode: `/ultra [on|off]` in memory per session (`PI_SUBAGENT_ULTRACODE`, default off); while on, cache-diffed prompt guidance carries the decision heuristics, the pattern menu with declarative shapes, and the size guideline.
|
||||
- `ultracode` keyword: interactive-only, case-sensitive, word-bounded; stripped from the prompt, it forces plan-first handling for the next run (`PI_SUBAGENT_ULTRA_KEYWORD`, default on).
|
||||
- Completion notices: terminal ultra runs deliver status plus the bounded consolidated answer as a message that may start a turn; `subagent_async` and workflow runs stay pull-based (`PI_SUBAGENT_ULTRA_NOTIFY`, default on; ADR 0006).
|
||||
- Switches and bounds: `PI_SUBAGENT_ULTRA` master kill switch (default on), `PI_SUBAGENT_ULTRA_GUIDELINE` small/medium/large/unrestricted (default medium, advice only); invalid values warn and fall back. Caps and child exclusion reuse the workflow engine's — ≤ 64 steps, ≤ 32 items per each-step, ≤ 256 children per run; `--exclude-tools` gains `ultra`.
|
||||
|
||||
## [0.2.0] - 2026-11-26
|
||||
|
||||
Declarative workflow layer (spec #4, feature #3).
|
||||
|
||||
+14
@@ -66,3 +66,17 @@ _Avoid_: log, history
|
||||
|
||||
**Expanded plan**:
|
||||
The run's steps after item fan-out is resolved, as returned at start.
|
||||
|
||||
### Ultra
|
||||
|
||||
**Ultra mode**:
|
||||
The per-session policy that injects planning guidance and acts as consent for inline plans; in memory, toggled with `/ultra`, defaulted by `PI_SUBAGENT_ULTRACODE`.
|
||||
_Avoid_: ultracode mode
|
||||
|
||||
**Inline plan**:
|
||||
A model-authored plan passed at start time in the same schema as a workflow file, run through the same validation.
|
||||
_Avoid_: script, dynamic workflow
|
||||
|
||||
**Size guideline**:
|
||||
Advisory child-count target — small, medium, large, or unrestricted — injected into planning guidance and shown at start; never enforced. Caps remain separate and hard.
|
||||
_Avoid_: limit, cap (both reserved for enforced bounds)
|
||||
@@ -54,7 +54,7 @@ Accepts the same invocation fields as `subagent`, validates the complete invocat
|
||||
{ "tasks": [{ "agent": "scout", "task": "Research storage" }] }
|
||||
```
|
||||
|
||||
Async jobs survive the current tool call and model turn. Completion does **not** inject a message or start a model turn automatically.
|
||||
Async jobs survive the current tool call and model turn. Results are pull-based: completion does **not** inject a message or start a model turn automatically. The one scoped exception is a run started by `ultra`, which delivers its status and consolidated answer as a message when it finishes (see [Ultra](#ultra)); `subagent_async` and `workflow` runs stay pull-based.
|
||||
|
||||
### `subagent_jobs` — inspect and control
|
||||
|
||||
@@ -108,6 +108,46 @@ Bounds: 64 steps per workflow; 32 items per each-step (`PI_SUBAGENT_WORKFLOW_MAX
|
||||
|
||||
Workflow authoring is documented in the `workflow-authoring` skill at `.agents/skills/workflow-authoring/SKILL.md` (load it as `/skill:workflow-authoring` before writing or editing a workflow file).
|
||||
|
||||
## Ultra
|
||||
|
||||
Ultra is a policy layer over the workflow engine for plans that are one-off. It adds an inline-plan tool, a per-session mode with injected planning guidance, a keyword trigger for a single prompt, and completion notices for the runs it starts. Parsing, validation, caps, the scheduler, the journal, and run management stay the workflow engine’s.
|
||||
|
||||
### `ultra` — inline plans
|
||||
|
||||
The `ultra` tool takes `{ plan, args?, cwd? }`. `plan` is the same markdown document a workflow file is — YAML frontmatter with `name`, `description`, optional `args`, and `steps`; the body is ignored — parsed by the file parser and validated by the file validator. Structural validation, step-output references, declared arguments, the 64-step cap, and every step agent and `cwd` happen before any child spawns; the item count is only known when an each-step’s source output exists, so the ≤ 32-items-per-step and ≤ 256-children-per-run caps are re-checked as each fan-out resolves, before any item child spawns. Project agents named by an inline plan still hit the existing project-agent confirmation.
|
||||
|
||||
Author inline for a one-off plan, and save it under `.pi/workflows/` when it is worth rerunning. There is no `save` action: the run’s journal records the plan with source `"inline"`, and that entry is the plan’s only persisted copy.
|
||||
|
||||
The start call returns the run id, the expanded plan, the size guideline, and the retrieval hint; the run is an ordinary async job, managed with `subagent_jobs` and `/subagents` like any other.
|
||||
|
||||
**Review card.** With a UI and ultra mode off, every `ultra` start shows one review card after validation and before the run: the plan, each step with its `needs` and fan-out source, the child-count estimate against the caps, and every named agent with its user or project source. Declining spawns nothing. With ultra mode on, the mode is the consent and no card appears, though the start result still shows the plan. Print/JSON sessions have no UI and never prompt; they start directly. The review policy lives in the extension — there is no tool parameter for it.
|
||||
|
||||
### `/ultra` mode
|
||||
|
||||
`/ultra` or `/ultra status` reports the mode; `/ultra on` and `/ultra off` set it, and anything else prints usage. The setting is in memory for the session, and the next session starts from `PI_SUBAGENT_ULTRACODE` (default off). While the mode is on, `before_agent_start` adds an `ultracode` system-prompt section — cache-diffed by Pi, never a per-run message — with the decision heuristics (a task larger than one agent can hold in context; the same step across many items; findings that should be cross-checked before the user sees them), the pattern menu and its declarative mapping (fan-out and synthesize → each-step plus fan-in; adversarial verification → a verify step that needs the producer; generate and filter; tournament via pre-expanded brackets; classify-and-act and loop-until-done not expressible in one plan), the current size guideline, and the wait-before-continuing instruction. Turning the mode off removes the section.
|
||||
|
||||
### The `ultracode` keyword
|
||||
|
||||
Typed interactive input containing the lowercase, word-bounded `ultracode` has the word stripped and arms a one-shot flag. The next run receives an instruction to author an inline plan for the task and start it before doing the work. Matching is case-sensitive (`Ultracode` does not trigger) and word-bounded (`ultracodes` and `myultracode` do not). Only input whose source is interactive arms it; RPC or extension text cannot. The flag is consumed by the next run whether or not that run starts a plan, and it is independent of ultra mode. `PI_SUBAGENT_ULTRA_KEYWORD=off` disables the trigger.
|
||||
|
||||
### Completion notices
|
||||
|
||||
When a run started by `ultra` reaches a terminal state, the extension sends a `pi-subagent-ultra-done` message with the run’s status and the bounded consolidated answer — the journal output of the last succeeded step, within its 50 KiB output budget — as a message that may start a model turn. A run with no succeeded step reports its status and error instead of partial output. This is the scoped exception to pull-based results: `subagent_async` and `workflow` starts still never start an automatic model turn. `PI_SUBAGENT_ULTRA_NOTIFY=off` restores pure pull for ultra runs; `PI_SUBAGENT_ULTRA=off` removes notices with the rest of the layer.
|
||||
|
||||
### Switches
|
||||
|
||||
All five variables are read when the extension loads; an invalid value falls back to its default and the session shows a warning at start.
|
||||
|
||||
- `PI_SUBAGENT_ULTRA=on|off` (default on): `off` removes the whole layer — the `ultra` tool, `/ultra`, guidance injection, the keyword trigger, and completion notices.
|
||||
- `PI_SUBAGENT_ULTRACODE=on|off` (default off): the session’s starting ultra mode; `/ultra on|off` overrides it.
|
||||
- `PI_SUBAGENT_ULTRA_GUIDELINE=small|medium|large|unrestricted` (default medium): advice only — aim for fewer than 5 / 10 / 50 children, or no child-count advice. Injected into the guidance and shown at start, never enforced.
|
||||
- `PI_SUBAGENT_ULTRA_KEYWORD=on|off` (default on): the `ultracode` trigger.
|
||||
- `PI_SUBAGENT_ULTRA_NOTIFY=on|off` (default on): completion notices for ultra runs.
|
||||
|
||||
### Bounds
|
||||
|
||||
The hard caps are the workflow engine’s and unchanged: 64 steps per plan, 32 items per each-step (`PI_SUBAGENT_WORKFLOW_MAX_ITEMS`, valid 1–256), 256 expanded children per run, and at most `min(PI_SUBAGENT_MAX_WORKERS − 1, 4)` concurrent children of a run. The size guideline is advice, not a cap. Children of an ultra run — like every child — are started with `--exclude-tools subagent*,workflow,ultra`, so they cannot dispatch further agents, workflows, or ultra runs.
|
||||
|
||||
## Human inspection
|
||||
|
||||
```text
|
||||
@@ -175,7 +215,7 @@ Child token/cost usage is aggregated in snapshots for inspection. It is not auto
|
||||
|
||||
Each task remains a real `pi --mode json -p --no-session` process and inherits the existing model, thinking, tool, context-file, skill, extension, and MCP behavior. Agent markdown bodies are passed as appended system prompts.
|
||||
|
||||
Children always receive `--exclude-tools subagent*`, preventing recursive dispatch and worker-pool deadlocks. Other startup isolation is unchanged.
|
||||
Children always receive `--exclude-tools subagent*,workflow,ultra`, preventing recursive dispatch and worker-pool deadlocks. Other startup isolation is unchanged.
|
||||
|
||||
## Development
|
||||
|
||||
|
||||
Reference in new issue
Block a user