Helpers: results, the delegation gate and worktrees
Part of the Workflow Modes reference.
How subagents return structured results: yield
A subagent finishes by calling yield with a result matching the contract
in its profile. yield is declared only to helper sessions (carrying
pi-subagents' <active_agent> tag), never to top-level sessions (#1043).
-
A payload that does not match is refused with every problem at once, and the child retries in the same turn. After three failed attempts the harness waives the schema and accepts the payload as submitted, marked
schemaOverridden. Each packaged agent’s body shows the exactdataobject its schema declares, field names included, so the ladder is a safety net rather than the plan (a test in@gadhs/pi-agentsfails if a body stops naming a schema field). -
An accepted payload (no size threshold) is written to a sidecar beside the child’s session record, collected by the parent — foreground or background — and placed in the result the parent reads: appended to the subagent tool’s result, or to the
get_subagent_resultreport, as “returned a checked result”, and traced for the human. The tool’s own structured content stays on the result beside it (#399). A parent with no session file (pi --no-session) is collected from too: its helpers' records are in pi-subagents' temp directory, and the search covers it (#860). This matters becauseyieldends the child’s turn: the prose the tool returns is what the child said before yielding, and the checked data is not in it. That prose is usually empty, and pi-subagents' placeholder for an empty body, a “No output.” paragraph, is dropped when the payload is placed, since above a checked result it read as a failure (#466). A fetched report’s status and the child’s transcript, which decide whether the run is done and which sidecar is its own, are read from thedetailspi-subagents 25.x types them in (status,transcriptPath), never from the report’s rendered text (#534). An older pi-subagents sends text only; it is read then, and the diagnostics stream recordssubagent_report.from_text. -
A background helper’s completion notice is pi-subagents' message, and its
<result>previews the same pre-yield prose. Where the helper yielded, the parent model reads a line in its place: the helper returned a checked result, andget_subagent_result("<id>")collects it (#479). The sidecar is only read for this, so that call still delivers the payload. The rewrite is pi’scontextevent, decided once per notice, so the conversation the model sees does not change under it. The transcript’s own copy of the notice is unchanged. Earlier versions of pi-subagents (⇐ 25.0.5) held a completion notice while the parent’s run was active and formatted it when the run settled from the live record, so a helper resumed in between was announced asDonewithNo output.while it was still running. pi-subagents26.0.2fixes that at the source (gotgenes/pi-packages#1058, #664, #635) by dropping withheld completion notices whose run was replaced by a resume. For historical transcripts recorded under older versions, the notice’s owndetailscarry the status it was formatted from: when that isrunningorqueued, the parent reads that the helper is running again, with no result yet, and that its own notice follows (#480). This comes before the yield rewrite, because a sidecar beside such a notice is from the earlier run. -
A child whose session has no file is told its result was accepted but not delivered, and keeps its turn to restate it in prose.
-
A child that ends its turn without yielding, answering in prose instead, is reminded once in its own session (#472). The reminder tells it to call
yieldwith the result it just gave, orerror, and gives it one more model turn. pi’sagent_before_settleboundary runs inside the child’s prompt, so the result the parent collects already carries the yield. The work is usually done in this case; only the delivery was missed (#449).-
A child is reminded at most once per run. The next prompt (a resumed helper) starts a new run, with its own reminder.
-
There is no reminder for a run that errored or was stopped, including at its turn ceiling, nor for a child that yielded (even an
error, or a result it could not deliver). -
There is none for an agent without a contract, nor for one whose tools do not include
yield: such an agent returns prose by design. -
The reminder stays in the child’s transcript, and its turn counts in the helper’s spend.
-
The general-purpose helper’s result (#895). Every packaged helper has a contract. The general-purpose helper, which does most delegated work, returns four fields:
| Field | What it holds | Bound |
|---|---|---|
|
what it changed, or the answer when it changed nothing |
4,000 characters |
|
the paths it created, changed or deleted |
40 paths, 200 characters each |
|
each command it ran, with |
20 checks |
|
what was asked and is not done, and why |
10 items, 300 characters each |
The lists may be empty, and no other field is accepted. A result over a
bound is refused like any other mismatch, and the helper shortens it:
longer material goes in a file under .pi/scratch/ that files names.
Its body tells it never to report a check result it did not see in that
run. Measured before it shipped on the battery’s coder-helper arm: the
coder task run by this helper, with and without the contract.
Whose sidecar. A fetched background report names the child’s transcript (“Full transcript available at: …”); the sidecar beside that file is the child’s and no other’s, so five children of one agent type each get their own, and a child that did not yield yields nothing — never a sibling’s. A result that names no transcript (the foreground result, or an older pi-subagents) falls back to agent name and "written after this spawn started", newest first; foreground spawns do not overlap, so it holds there.
While a backgrounded child runs, its trace line says “is running in the
background — id …”; “finished” comes with its fetched report. A
fetched report whose status is anything but completed is not a result:
its contract is not judged and no “finished” comes with it. A run you
stopped is one; since pi-subagents 23 so is aborted, which now means a
helper still calling tools when it reached its max_turns ceiling (at
least 2). No helper runs uncapped (#372, #376): the packaged helpers
name their own (Explore 300, general-purpose 200, Research 100), a spawn whose
caller, agent file and pi-subagents' defaultMaxTurns all set none gets
200 from the package, and each is tunable
(Change a helper’s turn cap). The
caps sit above the longest healthy runs seen, so they stop a loop, not
good work. pi-subagents warns a helper two turns before its
ceiling, and the packaged helpers are told to yield at that warning
with what they have, the rest under uncertain, so a run that hits
its budget returns a checked partial result rather than nothing. The
cap exists because a helper with none ends when its parent does: one
re-issued a single count call 2,029 times over five hours.
The early signal comes before the cap (#373). In every session, helpers
and the parent alike, when the same call with the same arguments (in any
key order) gets the same result three times in a row, the model gets one
line as a steer: change the call, or yield what it has (a helper) or stop
and say what it was trying to do (the parent). The line is pi’s own
message (gadhs-repeat-warning) and opens by saying so: repeat warning ·
pi’s own notice, not the human’s instruction. It is never sent as a user
message, which is the human’s voice to the model, in the session file, in
the terminal and on a paired phone (#1001). Once per streak, and
nothing is refused: a poll that keeps getting “running” is legitimate,
and stopping a run is the cap’s job. The polling tools
(get_subagent_result, steer_subagent) and yield are exempt. A
streak of turns with no text and no reasoning is deliberately not a
signal: the incident’s healthy helpers had none either.
yield confers no capability — it is a child’s exit door, not a power — so parents
are never granted it.
The delegation gate
canSpawn lists which helper agents a mode may launch (plan mode, for
example, may launch read-only explorers but nothing that writes). Auto,
manual and yolo ship [""]: any agent with a declared profile, Plan and
general-purpose included (#400). There the list narrowed nothing - those
modes hold every tool, and what a helper does is judged by your rules
either way - and naming four agents only refused a fifth. The gate
is deterministic: the agent must be on the mode’s list (or admitted by
"“), must have a declared
tool profile, and that profile must not include tools the mode itself lacks
— and an unrecognisable spawn request is refused outright. Every refusal
is the gate’s and says so: "`decided by the gadhs delegation gate, not the
human”, traced as `delegation BLOCKED (#392; a refusal by the mode’s
list was labelled the judge’s before). (Set
subagentPolicy.enforce: false to turn the gate off entirely.) Anything a
helper then tries to do is checked by your session’s rules, in your
current mode — a helper never gets looser permissions than you have. Its
own prompt names the mode its own pi-modes started in, not yours. So
when a mode rule denies a helper’s step, the denial says it is the parent
session’s current mode, which the parent may have entered after the helper
started, and tells the helper to report it rather than retry (#648).
Each helper runs on its own model, independent of the session’s: Explore
on Gemini 4 Hydrogen and Research on Sonnet 5.5, as shipped
in @gadhs/pi-agents and argued on the Model battery: every shipped model, per role, as permutations page;
tuning shows the
per-user override. A helper’s model is a routing choice, not a permission
one — the gate above applies whatever it runs on.
Verify, a helper that ran one check and reported the result, was dropped on
2026-11-24 (#898): the job tool with a match pattern does that job and
keeps the long output out of the lead’s context. A managed Verify.md left
in a box’s agents directory is removed at the next session start, which
says so; one you own (its gadhs_managed line deleted) is left alone. An
entry for it in gadhs-pi-agents.json is ignored with a notice, and the
rest of that file still applies.
Explore is the cheap lookup helper: where code is, what it does, how it works, and counts. It is not a judge of whether a change is safe, small or done (#707). A verdict like that comes with what it did not check (the tests, generated files, hashes, lints and criteria that pin what the change touches), and the parent checks it. It also keeps an issue’s or a plan’s word apart from the code’s: such a claim is checked in the code or marked unverified. A fact from outside the repository, such as a release version, is fetched in the run or marked uncertain.
Every helper is told its tools (#708). A new spawn of an agent whose
definition this session read gets that definition’s tool list after the
brief, as pi-subagents grants it: the list as written, the seven built-ins
when the file names none, nothing for none. It is told that what it can
call is what it has. A brief once told Explore it had no network while it
had the web tools, so it never used them. A resume is not noted again, and
an agent with no definition here (pi-subagents' built-ins) gets no list.
Explore and Research lock their model (locked: in the agent
file’s frontmatter), so a spawn’s model argument cannot move them.
pi-subagents would run such a spawn anyway on the agent’s model and say so
in the result. pi-modes refuses it instead, before the helper starts
(#666), naming the lock and the model it would have run on. A spawn that
asks for the agent’s own model, or names none, runs as before. When the
model matters, as for a judge or a panel, use an agent that does not lock
it, such as general-purpose. The lock is read by pi-subagents' rule: a
locked: list naming model, or locked: true in a file that sets a
model. The last definition read decides, project over global.
What a helper cost. A helper is its own session, and pi’s footer prices
only the main one. So each finished helper’s trace line carries its cost —
Explore finished — 31.8s · 30,683 tok · $0.0359 (gemini-4-hydrogen) — and
the status line keeps a running total, helpers $0.419 (3).
-
The spend is also in pi’s own figure: on pi 1.8.0+ it is recorded directly via
pi.appendUsage()as atype: "usage"session entry (kind: "subagent", #1033); on older pi it rides on thesubagent(orget_subagent_result) tool result stampeddetails.gadhsHelper. Both paths feed pi’s footer,/session,spendCapUsd, and RPC totals and rebuild the status line’s breakdown on resume without double-counting. -
The lead agent reads it too (#470): the same result ends with one line,
Helper spend (Explore): 30,683 tok · $0.0359 (gemini-4-hydrogen); 20,000 in, 683 out, 10,000 cache read, after any checked payload, with a floor marked as one. pi-subagents' own text already gives the tokens and the duration; the dollars were the part a lead budgeting helpers could not see. -
The result’s last line says until when the helper can be resumed (#478): “Resumable until 14:32 (consumedSessionRetentionMinutes 10); after that its session is released and resume refuses.” It is read from pi-subagents' settings (Keep a finished helper resumable longer).
-
Exact (no tilde): this extension runs inside every helper session too and ledgers the usage pi-ai priced on each message, cache reads included. When a spawn ends, the parent claims the child session that started after the launch and has ended; attribution is by start time, so two helpers launched in the same second could swap figures, the total unchanged.
-
A floor (
~$): pi-subagents' own token record at the catalog rate, which omits cache reads — used only when the ledger has nothing to claim; the status total carries the tilde once any such figure is in it. -
A helper that could not be matched is traced without a figure, never with a guess.
What the safety gate cost. Every ask that reaches the judge is a model
call pi’s footer did not include either. Each call’s usage and price go
to the permission system’s review log as a gadhs_mode_judge.call event,
and the status line keeps judge $0.012 (7) - the spend and the number
of calls, with the last long pause beside them (judge $0.012 (7, last
12.4s)) in place of the separate "last safety check" note. On pi 1.8.0+ each
call is recorded immediately via pi.appendUsage() (kind: "mode_judge",
#1033) — including warm-ups, monitor/job judgeCommand calls, and
denied calls — and on older pi it rides on the next tool result stamped
details.gadhsJudge, so it is in pi’s total and the breakdown survives a
restart. A call the provider did not price counts but adds nothing.
Subagents may also declare an output_schema (JSON Schema) in their
.pi/agents/<name>.md frontmatter, written as YAML and read with pi’s own
parseFrontmatter, the parser pi-subagents runs the file with (#396). A
header that does not parse is no contract, and the parent is told the
declared schema is unusable (#134). The result is validated on completion
(skipped when the spawn itself was refused or ended in error, #1039) and
a violation is stated to the parent as fact ("treat its conclusion as
unverified"), naming the file the contract came from. One validator serves
runtime and tests.
Precedence between a global definition (~/.pi/agent/agents/<name>.md, where
@gadhs/pi-agents seeds the agency’s) and a trusted project’s
(<repo>/.pi/agents/<name>.md) follows what each line is. pi-subagents
runs the project file whole, and a project file that names no model: runs
on the parent’s model — so the project file’s model replaces the global’s,
present or absent, and pricing follows what ran. The contract is agency
policy: a project file replaces it only by declaring its own output_schema;
omission leaves the global contract in force, and a violation then says so — "the definition that ran declares no contract of its own; declare
output_schema there to replace it" — so the project’s author can see the
source of a contract their file never mentions.
A helper in its own git worktree
A commit in another repository is refused, and one in another checkout of the session’s own repository is judged in that checkout (#462, #679). A helper whose session runs in a worktree has that worktree as its own checkout. So it commits there under its own commit guard and review, reading that worktree’s index and HEAD (#477).
worktreeAgents in your modes overlay lists the agent types that get one
(the recipe). A repository’s files cannot
set it. For a listed type:
-
Before the helper runs, a worktree is created from the session’s HEAD on a branch of its own,
helper/<type>-<id8>, at$TMPDIR/gadhs-helper-<type>-<id8>. Without a checkout or a HEAD the run fails with git’s reason; it never runs unisolated. pi-subagents tells the helper its working directory and branch. -
When it ends, a worktree with no changes and no commits past where it began is removed, branch included. Anything else is kept, and the helper’s result names the branch and path, with the counts and the way on. Nothing with work in it is ever deleted for you, and a git failure keeps everything.
-
At session start, kept worktrees and unmerged
helper/*branches in the repository are named once. A remote session’s are asked of the remote host, where its helpers worked. pi-ssh publishes that workspace after this check runs, so they are named at the session’s first turn instead (#503). A local worktree is ours when its name startsgadhs-helper-and its parent is the temp directory, compared as real paths. git lists the long name and Windows'tmpdir()the 8.3 one (#583). -
Continuing after a pause. pi-subagents keeps a helper’s session and worktree only while it waits on a question it asked (
ask_parent), and a resume re-enters both. So a helper that should pause, such as one waiting for a long pre-push run to finish, ends with a question. A helper that simply finishes is one run: a new helper continues on its branch, withgit checkout <branch>first. -
One provider per process. The top-level session registers it, and a child’s instance finds that registration and leaves it. If another workspace provider is already registered (pi-subagents allows one), you get one warning and helpers run under that one.
-
In a remote session (pi over SSH, #492) the worktree is made on the remote: a directory from its
mktemp -d, on the same branch naming. The helper’s working directory is an anchor inside the parent’s (.gadhs-helpers/<id>), served by a workspace of its own over the parent’s connection. Its tools, commits and asks act in the remote worktree. pi-subagents ends a helper synchronously, before the remote can be read, so the result names the branch and worktree and says that an empty one is removed shortly after. That check then runs in the background, with the same rule: no changes and no commits, or it is kept. Its outcome goes to diagnostics.
The package never commits, stages, pushes or deletes a helper’s work.
Pins: test/helper-worktree.test.ts, and pi-workflow’s
test/worktree-session.test.ts: a real session in a worktree refuses a
commit into the main checkout, naming the worktree as its repository.