Contract between the flow orchestrator (/flow:run) and its stage subagents - which named agent runs each stage, the pipeline lines they end with, worktree and port isolation, model policy and where automation stops. Use in /flow:issue, /flow:feature and /flow:implement when the arguments contain --agent (they hand off to /flow:run), and whenever a stage needs to know what its caller expects.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Agent Pipeline?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/eusilvio-agent-pipeline)
---
name: agent-pipeline
description: "Contract between the flow orchestrator (/flow:run) and its stage subagents - which named agent runs each stage, the pipeline lines they end with, worktree and port isolation, model policy and where automation stops. Use in /flow:issue, /flow:feature and /flow:implement when the arguments contain --agent (they hand off to /flow:run), and whenever a stage needs to know what its caller expects."
user-invocable: false
---
# Agent pipeline
`--agent` means "let the orchestrator drive the rest". There is exactly one
orchestrator: the `run` skill, pinned to Opus in its frontmatter.
`/flow:issue --agent` and `/flow:feature --agent` open the issue and then
invoke it through the `Skill` tool (`flow:run`, args `#<n>`);
`/flow:implement N --agent` does the same with `#N`. Always through the
`Skill` tool, never by reading the file: only the tool applies the model. Nobody else spawns stages, so the loop logic, the round cap
and the state live in one place.
The point is not parallelism between stages - for one issue they are
strictly sequential. The point is that each stage grades or implements
without the previous stage's context in its head, which is what makes a QA
verdict worth anything. Parallelism is between issues, and `run` owns it.
## Rule 0 - stages run headless
No user watches a subagent. Every stage runs with autonomous-mode semantics
(`--auto`): never ask, always end with its pipeline line. A stage that would
need to ask stops and reports instead.
## Rule 1 - isolation per issue
- **Worktree:** `wt.sh add <N>` creates `<parent>/<repo>-wt/<N>`, detached at
`origin/<base>`, with the git-ignored `.env*` copied and node dependencies
installed. Every stage gets `WT=<path>` and works only there. The main
checkout never moves. A diff in `services/*` (Python) needs
`wt.sh python <N>` before pytest. `/flow:merge` removes the worktree.
- **Ports and scratch:** `flowctl.py env <N>` gives `FLOW_PORT_API`,
`FLOW_PORT_WEB` and `FLOW_TMP`, unique per active issue. Never a fixed port
or a fixed `/tmp/<name>`.
- **Shared database:** test runs, migrations and seeds against a shared
database go through `FLOW_ISSUE=<N> flowctl.py locked testdb -- <cmd>`.
Issues queue on the database; everything else stays parallel.
- **Files:** `run` does not start two issues that cite the same file
(`flowctl.py overlap`).
## Where the contract lives
Each item's contract is a GitHub issue (default) or, in **local mode**, a
local spec `.flow/specs/<n>.md` in the main checkout - not versioned (`spec
init` lists it in `.git/info/exclude`), read from there even inside a
worktree. Local mode is on when `flowctl.py spec mode` prints `local` (the
directory exists) or the run got `--local`. The number of a local spec
(from 7001 up) is used wherever an issue number would be: flowctl state,
worktree `<repo>-wt/<n>`, branch `feat/<n>-...`, pipeline lines.
Every stage reads and writes the contract through `flowctl.py spec`, never
through `gh issue` directly, so the same steps serve both modes:
| Need | Command |
|---|---|
| body / whole record | `spec body <n>` / `spec view <n> --json` |
| last QA report / round count | `spec qa <n>` / `spec qa <n> --count` |
| comment (decisions, QA report) | `spec comment <n>` (stdin or `--body-file`) |
| rewrite the body (gate answers) | `spec edit <n> --body-file <f>` |
| PR body line / PR search term | `spec ref <n>` / `spec ref <n> --search` |
| close (merge only, never a subagent) | `spec close <n> <note>` |
## The named agents
| Stage | `subagent_type` | Model | Prompt starts with | Ends with |
|---|---|---|---|---|
| orchestrator | - (skill `flow:run`, main session) | opus | - | board / final report |
| spec | `flow:spec` | opus | `Arguments for the issue skill:` / `feature skill:` | `ISSUE:<n>` |
| implement | `flow:implementer` | sonnet | `Arguments for the implement skill:` | `PR: <url>` |
| QA | `flow:qa` | opus | `Arguments for the verify skill:` | `VERIFY:PASS` / `FAIL` / `BLOCKED` |
The prompt prefix matters: the `verdict-guard` hook uses it to recognize the
stage when the agent type is not available.
Helpers any stage may call for cheap, checkable work (both read-only, haiku):
| Helper | Use it for |
|---|---|
| `flow:explorer` | broad "where is / who consumes" sweeps during investigation |
| `flow:log-reader` | a red check whose log is longer than ~200 lines |
## Pipeline lines
| Line | Meaning |
|---|---|
| `ISSUE:<n>` | issue opened (or local spec created, in local mode) |
| `PR: <url>` | PR opened, ready for QA |
| `VERIFY:PASS` | QA green - ready to merge |
| `VERIFY:FAIL` | QA red - fix round |
| `VERIFY:BLOCKED <reason>` | QA could not grade - human decides |
| `PIPELINE:SKIPPED <reason>` | stage refused to run (open decisions, spec mismatch) |
| `PIPELINE:FAILED <reason>` | a check went red, or no verdict |
| `WAIT: <peer> <what>` | live mode only: the stage messaged its pair directly and ends its turn waiting for the answer |
| `QAPART:<PASS\|FAIL\|BLOCKED> <id> <sha>` | live mode: end of a pair, also sent to `main` by `SendMessage` |
Only the last line counts. A `SubagentStop` hook sends a stage back to work
when its line is missing. `SKIPPED` and `BLOCKED` are terminal: a human has
to decide something.
## Model policy
Edits and judgment stay on the stage's own model; reading, searching and log
triage go to the haiku helpers. The pipeline never escalates on its own: no
`model` override, no effort bump between rounds, no switch to a bigger model.
A loop that does not converge stops (round cap or spec-suspect, see `run`)
and goes back to the human.
## Keep it flat
Only the orchestrator spawns stages. A stage never spawns another stage
(the implementer is called with `--auto`, never `--agent`): a QA nested inside
an implementer sits at a depth where the orchestrator can no longer
`SendMessage` it. If the Agent tool is unavailable (nesting depth), follow the
target skill inline and say in the report that the stage ran without
isolation.
## Agent lifetime - nobody dies before the merge, and cold agents are replaced
Every implementer and QA agent of an item (parts included) lives until
`/flow:merge` closes that item. Nothing in the pipeline stops, kills or
replaces them: no `TaskStop`, and no fresh `Agent()` while the old one still
answers. An agent that delivered its last line is idle, not gone - it costs
nothing while idle and keeps the code (implementer) or the evidence (QA) in
its head while it is warm. Every agent id goes to `flowctl` the moment `Agent()` returns
(`impl_agent`, `qa_agent`, `slice ... agent=`, `qapart ... agent=`);
`flowctl.py agents <n>` lists them.
Later rounds, interactive or headless, and the merge gate continue the same
agents with `SendMessage` while they are warm. Idle is not free forever: a
subagent's prompt cache lasts about 5 minutes, and resuming after that rereads
its whole history at full price. Before resuming, run `flowctl.py idle <n>`:
`WARM` -> `SendMessage` to the same agent; `COLD` -> a fresh agent of the same
role with the issue's last QA report (and the `## Reply to QA`, for a QA
round) as its starting context, which usually costs less than rereading a long
history. Record the new id in `flowctl` as always. A fresh agent also replaces
one when `SendMessage` fails because the id is gone (the session that spawned it ended: a resumed
`run` or a merge in another session); that agent then rebuilds its context
from the issue's QA reports, so nothing is lost but warmth. Agents exist only
inside the session that spawned them - say so when the user plans to merge
from somewhere else.
## The bridge - each implementer talks to its own QA
Each implementer is paired with its QA: `impl <-> qa` for a single item. In
a split item, `qa:q<k>` asks `impl:p<k>` (it wrote that code) and `qa:int`
asks the integrator (`impl`); fixes always go to the integrator, which may in
turn ask a part implementer. They never message each other
directly - an idle agent does not listen, and a stage that waits for an
answer in the middle of its work would hang. The orchestrator carries every
message **verbatim**, both ways, and logs it:
`flowctl.py talk <n> <from> <to> <ask|answer|reply> "<text>"`.
| Line (last line of a stage) | Means | The orchestrator |
|---|---|---|
| `ASK: <question>` | the stage needs a fact only its pair has; the body above says why | `talk ... ask`; exit 3 (`ASK-LIMIT`, 2 asks per stage per round) -> reply "no answer: proceed, record it as an assumption"; else SendMessage the question verbatim to the pair, prefixed `Question from your <QA/implementer> on #<n>:` |
| `ANSWER: <one-line summary>` | reply to a question; the body above is the answer | `talk ... answer`; SendMessage the whole body verbatim to the asker, prefixed `Answer from your <pair>:`, and the asker resumes where it stopped |
`ASK:` is not a verdict: the asker resumes after the answer and still ends
with its real line. Use it for facts, not opinions: "is the 20s fixture
change intentional, it is not committed?", "the exact curl and body for
criterion 3", "which seed did you use?". Never to negotiate a verdict.
The **fix reply** is the other half of the conversation. The implementer
ends a fix round with a `## Reply to QA` block above its `PR:` line - one
row per FAIL row and defect: `fixed in <sha>` / `disputed: <reproduction>` /
`not reproducible: <what I ran>`. The orchestrator logs it (`talk ... reply`)
and pastes it verbatim into the QA's re-verify message; QA answers every
`disputed` row with fresh evidence in its next report.
## Live pairs (`/flow:run --live`, or `--realtime`)
In live mode the bridge is replaced by direct pairs: every sliced part has
`impl:p<k>` <-> `qa:q<k>` and the integrator `impl` <-> `qa:int`; an unsliced
item is one pair. The orchestrator introduces the two (each gets the other's
agentId) and from then on they `SendMessage(to: <agentId>)` each other:
- QA FAIL -> QA sends its FAIL rows **verbatim** to the implementer that wrote
the code; it fixes on the part branch, pushes and answers with `## Reply
to QA` + sha; QA re-verifies. 3 rounds per pair, then `blocked` with the
reason. The orchestrator never relays FAIL rows and never fixes.
- Both log every message with `flowctl.py talk <n> <from> <to>
<fail|fixed|ask|answer|pass> "<text>"` (speech bubbles in the office) and
keep `slice`/`qapart state`, `pair=` and `busy` current
(`flowctl.py busy <n> add|rm <role>`; sub-agents with `flowctl.py agent <n>
start|stop <explorer|log-reader>`).
- A resumed agent's completion is delivered to whoever resumed it, **not** to
the orchestrator. So the end of a pair is always reported explicitly: QA
`SendMessage(to: "main")` with `QAPART:<X> <id> <sha>` and writes the state in
flowctl. Between messages an agent's last line is `WAIT: <peer> <what>`.
- Needs outside a part's paths/regions are an `ASK:` to the orchestrator (the
one relayed case): it goes to the contract owner, who adds it to the contract
branch; parts rebase.
- Self-sufficient parts: the contract (p0) installs all dependencies, creates
per-part stubs and root barrels, and splits unsplittable shared files into
`@flow-part <id> begin/end` regions with 3+ lines between them;
`flowctl.py slice <n> regions <id>` checks that a part only touched its
paths and regions.
- Load: heavy commands run through `flowctl.py heavy -- <cmd>` (semaphore,
`FLOW_HEAVY_SLOTS`, default nproc/4); `--agents K` (default 6) caps agents
working at once, resting ones do not count.
- Models are not reported by agents: `flowctl.py models` reads them from the
`model:` frontmatter of `agents/*.md` (orchestrator: its own session model,
`live.py start --model`), and the office labels each figure with it.
## Workflow runtime (the default)
`/flow:run`, and every command that hands off to it (`--agent` on issue,
feature, implement), runs the chain as Workflows: `workflows/flow-specs.js`
for descriptions and one `workflows/flow-item.js` per issue (implement -> QA
-> fix, cap 3 rounds, stop on spec-suspect). The stage contracts do not
change - same agents (`agentType: flow:implementer`, `flow:qa`, `flow:spec`),
same prompt prefixes, same last lines - and each stage also returns a
structured result (JSON schema in the script). Differences from the classic
runtime (`--classic`, background agents):
- **Questions go to the user, not to the pair.** A stage never ends with
`ASK:`/`ANSWER:`. A technical doubt becomes a recorded assumption. A fact
only the user has (product behavior, a business rule) ends the run with
`NEEDS-USER <question>`; the orchestrator asks the user and starts the item
again from that stage with the answer. The fix round's `## Reply to QA`
still reaches the next QA verbatim (the script carries it).
- **No agent lifetime.** Every round is a fresh agent and nothing lives after
the run: the documented fallback (rebuild context from the issue's QA
reports) is the normal path. `/flow:merge` uses fresh agents too.
- **Board by the stages.** Each stage runs `flowctl.py set <n> stage=...
round=...` first, and the QA boots the shared environment itself
(`flowctl.py qa-env <n> up|rebuild`) when the repo has a recipe.
Only in the classic runtime: slicing, live pairs (`--live`), the bridge, and
`--headless` (a Workflow's completion notification may never arrive in
`claude -p`, so headless runs the classic runtime in waves).
## Where the automation ends - not negotiable
The chain stops at `VERIFY:PASS`. It does not merge, does not push to the
default branch and does not close issues; a PreToolUse hook enforces all
three for subagents (and `flowctl.py merge`). Merging is the one
irreversible step and belongs to a human: `/flow:merge`, or `/flow:run
--merge` when the user put that flag in the command - then the orchestrator,
never a stage, merges only items that pass every gate (`run` step 5.5).