workflow-authoring
Design, write, review, and debug Pi JavaScript workflows that coordinate multiple subagents. Use when a request needs named dependencies, bounded fan-out, per-item pipelines, quality gates, saved or nested workflows, pause/resume, or workflow progress; do not use it merely to run an existing named workflow.
- License 许可
- MIT
- 最近更新
- 2026-11-08
- Stars
- ★ 4
- Forks
- 6
01 前言 Front Matter
- name
- workflow-authoring
- metadata
- { "version": "1.12.1" }
- description
- Design, write, review, and debug Pi JavaScript workflows that coordinate multiple subagents. Use when a request needs named dependencies, bounded fan-out, per-item pipelines, quality gates, saved or nested workflows, pause/resume, or workflow progress; do not use it merely to run an existing named workflow.
02 资源文件 28
- 脚本examples/adversarial-verification.js2.2 KB
- 脚本examples/bounded-semantic-retry.js1.9 KB
- 脚本examples/classify-and-act.js2.4 KB
- 脚本examples/defensive-json-parsing.js2.6 KB
- 脚本examples/fan-out-and-synthesize.js1.7 KB
- 脚本examples/generate-and-filter.js2.5 KB
- 脚本examples/loop-until-done.js2.0 KB
- 脚本examples/named-task-graph.js1010 B
- 脚本examples/phased-budgets.js2.6 KB
- 脚本examples/saved-nested-workflows.js1.9 KB
- 脚本examples/structured-output.js1.3 KB
- 脚本examples/tournament.js2.9 KB
- 脚本examples/validated-gate.js2.0 KB
- 参考文档references/capabilities.md5.2 KB
- 参考文档references/capability-details.md13.5 KB
- 参考文档references/common-helpers.md160 B
- 参考文档references/debugging.md3.1 KB
- 参考文档references/focused-recipes.md1.9 KB
- 参考文档references/helpers.md577 B
- 参考文档references/lifecycle.md7.2 KB
- 参考文档references/pattern-selection.md2.0 KB
- 参考文档references/quality-helpers.md871 B
- 参考文档references/registry-ownership.md2.6 KB
- 参考文档references/retry-helper.md614 B
- 参考文档references/review.md3.7 KB
- 参考文档references/runtime.md5.6 KB
- 参考文档references/specialized-helpers.md1.8 KB
- 参考文档references/versions.md1.3 KB
03 SKILL.md 正文
Workflow authoring
A workflow is a small program that coordinates subagents; it is not a long prompt that asks one agent to do every step. Keep semantic work in agents and keep identity, ordering, bounds, failure handling, and aggregation deterministic in JavaScript.
Operating contract
- Use a workflow only when the task benefits from multiple agents, explicit stages, independent coverage, or a quality/recovery loop. One or two simple delegations should use the ordinary agent surface.
- Start every script with literal
export const meta = { name, description, phases? }. Return plain JSON data explicitly. - Use
orchestrate()for named dependencies,parallel()for a small independent barrier, andpipeline()for independent items that each need a sequential stage chain. Do not encode a dependency graph only in comments. - Give every work unit a stable ID and every agent call a short unique label.
Keep IDs beside results before filtering;
nullis missing coverage, not a successful finding. - Bound the algorithm inside the script: graph tasks, fan-out items, loop
rounds, semantic retries, and evidence size. The invocation-level limits
(
maxAgents,concurrency,agentRetries,tokenBudget,agentTimeoutMs) are tuned defaults rather than the place to express a bound; each one stops or fails a run that outgrows it, so a precautionary value cuts the coverage and not the cost. Set one only when the user asked for that limit. - Size the fan-out to the evidence the task actually has: one agent per
independent question, ten to thirty for an ordinary review or audit. The gain
is coverage — one agent asked one question reads further into it than one
agent asked four. Speed is a separate matter and not yours to decide: how many
of those agents run at once is the host's
maxConcurrentpool, so a wide fan-out on a narrow pool still finishes in waves. Split for what gets looked at, not for wall-clock. - Route an agent call with
strength: "low" | "medium" | "high"— this package's own word for how much effort a step deserves, and the only routing word a workflow has. It is not an agent-tier key: astrengthstable alone binds a strength to a tier — the user's, or the shipped default on a host that configured none — and a strength no table defines dispatches with no tier and takes the agent's own default. So name the effort the step deserves and never reach for a catalogue name; a word outside the three is rejected before dispatch, as istier:itself. There is no default: omittingstrengthdispatches with no tier and lets the agent type's own tier stand, so label the calls whose cost you mean to steer and leave the rest alone. There is no per-callmodel/thinking/tier, and none may appear in workflow meta or phase profiles.agent()andcheckpoint()reject any option name they do not read rather than ignoring it, so pass only the documented keys. Never guess an agent-type name—use names supplied by the current environment and follow registry ownership. - Pick that word by what a wrong answer costs, not by how important the step
feels.
lowis retrieval, navigation, and read-heavy breadth.mediumis the ordinary working rung and where a labelled step belongs unless you can say why not.highis for a step whose error is expensive to reverse — an architecture decision, a destructive migration, a security boundary — and a fan-out normally names it zero times, at most once on a closing step that actually decides something. It is not a reward for the hardest-sounding task: routing a whole fan-out tohighprices every branch at the cost of the one that mattered, and buys depth where the run needed coverage. - Workflows have no imports, filesystem/network APIs, timers, or unrestricted
Node APIs. Pass timestamps, randomness, and external decisions through
args.
The authoring pass
- Classify the topology. Decide whether the work is direct, a named DAG, homogeneous fan-out, a per-item pipeline, iterative discovery, or a quality gate. Read pattern selection only for the chosen shape.
- Declare inputs and bounds. Read
argsonce, normalize the input, reject or cap untrusted cardinality, and decide what incomplete coverage means. - Write the envelope. Declare only phases that are actually entered. Use
phase(title, { budget })for a soft token sub-budget, not as a scheduler. - Build the smallest work ledger. Store
{ id, status, result, error }(or an equivalent object) for each intended unit. Do not lose identity when applying.filter(Boolean). - Dispatch with the right primitive. Await every batch. For a dependent prompt, include both the dependency ID and its actual result; do not assume the child can see the parent conversation.
- Add quality only where it changes a decision. Use a schema before reading
structured fields, then use
verify,judgePanel,gate, orcompletenessCheckwith explicit bounds. These dispatch on your behalf, so passstrengthwhen the default (low, ormediumforcompletenessCheck) is not the effort that gate deserves. - Aggregate and report. Return a bounded JSON result containing the answer, coverage, and important failures. If the workflow runs in the background, the run ID is the handle for later control/resume.
- Review the script. Use the review checklist, then test with deterministic fake agents when changing topology or recovery.
Topology rules
Named dependencies: orchestrate
Use a task graph when a later step consumes a named earlier step:
const graph = await orchestrate([
{ id: "scan", run: () => agent("Inspect the target", { label: "scan" }) },
{ id: "security", run: () => agent("Check security risks", { label: "security" }) },
{
id: "report",
dependsOn: ["scan", "security"],
run: ({ results, statuses }) =>
agent(
"Synthesize the named findings; mention unavailable coverage.\n\n" +
JSON.stringify({ results, statuses }),
{ label: "report" },
),
},
]);
return graph;
orchestrate() validates IDs, missing dependencies, duplicate edges, and
cycles before callbacks run. It executes ready tasks in declaration-order
layers with a barrier between layers and returns { results, tasks }. Each task
callback receives detached { id, attempt, results, statuses } snapshots.
retries retries ordinary task-callback failures up to three times. The default
onError: "skip-dependents" prevents a failed dependency from feeding a stale
prompt; use onError: "continue" only when the dependent explicitly handles
failed statuses. fail-fast stops discovery of later layers after the current
layer settles.
Independent fan-out: parallel
Pass thunks, not already-started promises. Results preserve input order and a
recoverable item failure becomes null; fatal errors surface after the whole
batch barrier settles. Keep a ledger with IDs before filtering:
const work = items.map((item) => ({ id: item.id, item }));
const outputs = await parallel(work.map(({ item }) => () =>
agent("Handle item " + item.id, { label: "item-" + item.id }),
));
const ledger = work.map(({ id }, index) => ({ id, result: outputs[index] }));
Each parallel() call accepts at most 4096 thunks. It is a barrier: do not
start synthesis until the returned array is complete.
Per-item stages: pipeline
Use pipeline(items, ...stages) when every item follows the same chain. Items
run concurrently, but stages for one item are sequential and receive
(previousValue, originalItem, index). A stage failure drops that item to
null; guard missing values before the next stage. There is no cross-item
barrier between stages, and each call accepts at most 4096 items.
Saved or nested workflows
workflow(name, childArgs) resolves a context-supplied saved workflow and runs
it inline with the parent's limiter, agent accounting, token accounting, and
store. One nested level is allowed; concurrent siblings are allowed. An
unchanged child is replayed as one parent journal call, while a changed or
interrupted child receives a generation-scoped managed identity. Do not use
nesting as an unbounded recursion mechanism.
Prompt and result discipline
Every child prompt must be self-contained: state the role, exact task, relevant
inputs, expected output shape, and what the child must not do. Prefer a small
schema for values JavaScript will inspect. When a child consumes another
child's output, include the stable ID and actual bounded data, for example:
const prompt = "Review result " + JSON.stringify({ id: "scan", result: scan });
Do not pass whole transcripts when a summary or structured fields are enough.
Use log() for progress and return a result that distinguishes completed work,
missing coverage, and failed/skipped work.
Failure, limits, and recovery
- Recoverable child failures return
nullafter agent retries. Fatal workflow errors (invalid hooks, exhausted hard limits, unsupported selectors, and schema exhaustion) throw and must not be dissolved into a normal result. - Runtime
agent({ retries })retries execution failures.orchestratetaskretriesretries the callback. Semanticretry()/gate()attempts are a third, intentional layer. Bound and ledger every layer separately. agent()schema repair includes concrete validation feedback in the next attempt. Do not read fields from an unvalidated text response.checkpoint()is headless by default for background runs. Usebackground: falseonly when a human decision must be shown.budgetand phase budgets are soft pre-call gates; concurrent work may overshoot. Do not promise an exact token ceiling unless the caller supplied and accepted that policy.
Resume and publication gate
Resume replays the longest unchanged prefix of journaled calls. Keep call order,
labels, prompts, routing options, and inputs stable. orchestrate layer order
and named dependency results make dynamic plans easier to replay, but arbitrary
branch/loop call counts can still invalidate the positional prefix. Never use
Date.now(), Math.random(), or no-argument new Date() in a script.
Before shipping a workflow change:
- read lifecycle for pause, stop, budget, and resume;
- read debugging when reproducing a failure;
- read the review checklist before accepting topology;
- read the generated capability index when a
signature, default, or support boundary is disputed; remember that a strength
is this package's own vocabulary, bound to a host tier only by the user's
strengthstable, while model/thinking resolution stays in pi-subagents; - ensure every package-relative example/reference link remains inside the publishable package.
04 同仓库更多 Skills
workflow-review
Audit an existing Pi JavaScript workflow for topology, prompt/data flow, limits, failure handling, cancellation, resume safety, and publication compatibility. Use when reviewing or debugging a workflow script or saved run; do not use to run a standard named workflow.
workflow-patterns
Choose and run one of Pi's built-in multi-agent workflows for research, adversarial review, code review, multi-perspective analysis, or codebase auditing. Use when the request matches a named pattern; use workflow-authoring instead for a new script or custom topology.
pi-ralph-wiggum
Long-running iterative development loops with pacing control and verifiable progress. Use when tasks require multiple iterations, many discrete steps, or periodic reflection with clear checkpoints; avoid for simple one-shot tasks or quick fixes.