Plan: the general-purpose helper returns a validated result

Closes: #895. Relates to: #884 (the audit), #736, #472, #896. Branches: test/battery-coder-helper, then feat/helper-validated-result. Status: Done (2026-11-27) — the helper returns a checked result; on the coder arm all four gates held (30/30 solved both arms, 30/30 yields, cost ×1.08, no false check)

Context

Ruled by the operator (2026-11-22): a validated result, with a size bound, measured on the battery’s coder task before merging. The contract and the measurement were agreed in conversation (2026-11-27). What the tree says today, by reading:

  • packages/pi-agents/agents/general-purpose.md declares no output_schema and lists no yield tool; its helper answers in prose. Explore.md and Research.md declare both.

  • The machinery is in pi-modes and needs no change. yield (packages/pi-modes/yield-tool.ts, decideYield) checks the payload against the agent file’s schema inside the helper and tells it every problem at once. MAX_SCHEMA_RETRIES is 3: the first two failing submissions are refused, and the third is accepted marked schemaOverridden. The lead reads "returned a checked result" with the payload (subagent-wiring.ts, yieldText); a contracted helper that ends in prose is reminded once (remindToYield); the delegation gate lets yield through in every mode (NON_CAPABILITY_TOOLS in subagent-gate.ts).

  • On luchs the session files record 161 yields: 160 validated, 1 reported failure, none waived.

  • Only auto, manual and yolo may spawn the helper (canSpawn in packages/pi-modes/modes.json; plan lists Explore and Research), and all three run Opus 5.5; the helper runs on the session’s model.

  • The battery’s coder task (tools/model-battery/tasks/coder.json) runs pi’s default prompt, not the helper. pi-subagents builds an append agent’s prompt as the parent’s prompt, a header, and the body inside <agent_instructions> (@gotgenes/pi-subagents, src/session/prompts.ts). The battery’s runner sends an agent’s body with --system-prompt, which replaces pi’s prompt, and has no way to append.

Design

The contract

In general-purpose.md’s frontmatter, with `yield added to tools::

output_schema:
  type: object
  required: [summary, files, checks, not_done]
  additionalProperties: false
  properties:
    summary: { type: string, minLength: 1, maxLength: 4000 }
    files: { type: array, maxItems: 40, items: { type: string, maxLength: 200 } }
    checks:
      type: array
      maxItems: 20
      items:
        type: object
        required: [command, result]
        additionalProperties: false
        properties:
          command: { type: string, minLength: 1, maxLength: 200 }
          result: { enum: [passed, failed, not-run] }
          detail: { type: string, maxLength: 300 }
    not_done: { type: array, maxItems: 10, items: { type: string, maxLength: 300 } }

The worst case is about 27,000 characters as the lead reads it (4,000 + 40 x 200 + 20 x 510 + 10 x 300, plus JSON punctuation). The bound is the schema’s: the helper is refused an oversize payload and shortens it. A helper’s third failing submission is accepted flagged, as for every contracted agent; nothing cuts it. description: gains a last sentence: "Returns a checked result: a summary, the files it touched, the checks it ran, and what is not done."

The body

The first paragraph (who the helper is) and the batching paragraph stay. After the batching paragraph, and in place of the present last paragraph:

Finish by calling the `yield` tool exactly once. `result.data` is an OBJECT
of exactly this shape - the field names and sizes are validated, and prose in
place of the object is rejected:

    {"summary":  "<what you changed, or the answer when you changed nothing>",
     "files":    ["<a path you created, changed or deleted>", ...],
     "checks":   [{"command": "<what you ran>", "result": "passed", "detail": "<optional, one line>"}, ...],
     "not_done": ["<what was asked and is not done, and why>", ...]}

`summary` is at most 4,000 characters; `files` at most 40 paths, `checks` at
most 20 and `not_done` at most 10, and any of the three may be an empty
list. A check's `result` is `passed`, `failed` or `not-run`: list a check
with the result you saw in this run, and one you were asked for and did not
run as `not-run`. Never report a result you did not see. Longer material
goes in a file under `.pi/scratch/` that `files` names.

When the work could not be done at all, call `yield` with `result.error` (a
string saying why) instead of `data`. The parent reads what you yield, not
what you say — prose is not delivered. If yield reports schema problems, fix
every one it lists and call it again.

When you are told your turn budget is nearly spent, stop and call `yield`
at once with what you have: `summary` as far as you got, and every part you
did not reach under `not_done`. A partial result the parent can read is
worth more than a run that ends with nothing.

The battery arm

tools/model-battery/tasks/coder-helper.json: the coder task’s fields (path, workspace, cases, userPrompt, sandbox, thinking, scorer, timeoutMs, typicalTokens) unchanged, with "prompt": { "agent": "general-purpose" }, "tools": "agent", "experiment": "coder", and a // saying what it is. It is not in the manifest; it is run by name. Three changes let it run:

  • parseAgentFile (tools/model-battery/lib/task.mjs) also returns mode ("replace" when the frontmatter says prompt_mode: replace, else "append", pi-subagents' default) and tools (the frontmatter’s list). resolvePrompt carries both; an append prompt’s sha is sha256("append\n" + text), a replace prompt’s stays sha256(text).

  • "tools": "agent": loadTask resolves it to the agent file’s list. checkSpec accepts the string only with prompt.agent and sandbox: true (the file may list bash, and the check cannot read it).

  • The runner appends. tools/model-battery/runners/agent-loop.mjs gains an exported lanePrompt(prompt): { appendSystemPrompt: "<agent_instructions>\n" + text + "\n</agent_instructions>" } for an append prompt, else { systemPrompt: text }; laneSpec spreads it. tools/model-battery/lib/headless.mjs gains an exported headlessArgs(spec), the argument list runHeadless builds now, with two additions: --append-system-prompt and its text when the spec carries appendSystemPrompt; and -e builtin:codemode when the spec’s tools include codemode and its pi arguments include --no-extensions.

The lane’s yield and count are the battery’s own (tools/model-battery/yield-tool.mjs), checked against the agent file’s schema as for explore. codemode is the tool of pi’s built-in extension builtin:codemode: naming it in --tools turns the tool on, but the bare stack’s --no-extensions (BARE_PI_ARGS) disables built-in extensions too, and -e builtin:codemode loads one explicitly (pi’s docs/settings.md, "The built-in extensions are named", and docs/cli.md, --no-extensions, both under node_modules/@earendil-works/pi-coding-agent/). --append-system-prompt takes text or a file and appends it to the system prompt (docs/cli.md, "Prompts and process"). No battery lane has used either, which is what the smoke lane below is for.

The run, and the rule that reads it

The run is the operator’s. One subject, vertex-anthropic/claude-opus-5-5, at the task’s medium; two arms; five runs each over the six cases: 60 lanes, about $10 by the stored coder cell ($0.11 a lane). A scratch script interleaves the arms run by run, as #891 did: it writes main’s general-purpose.md (the helper as shipped) and runs battery run --task coder-helper --model vertex-anthropic/claude-opus-5-5 --runs <r> --store build/battery-895-base, restores the branch’s file and runs the same into build/battery-895-contract, for r = 1 to 5, restoring the file at exit. Before it, a dry run gives the projection, and one smoke lane (one case, the contract arm) shows codemode and yield work under the sandbox; a smoke lane that fails for the harness’s own reasons stops the run.

The decision rule, fixed here. The contract merges when, over the 30 lanes of each arm:

# Gate

a

Work: lanes solved (hidden suite all green) under the contract are at least the baseline’s count minus 1

b

Delivery: at least 29 of the 30 contract lanes end in an accepted yield whose data met the schema, with no waiver

c

Cost: the contract arm’s median cost a lane is at most 1.25 times the baseline’s

d

Truth: no contract lane reports a check as passed that its transcript shows was not run or did not pass

Gate d is read, lane by lane, from each record’s transcript.jsonl evidence: a claimed command that paraphrases one the lane ran is that command; a claim with no such call, or one whose call failed, breaks the gate. Reported beside the gates: files against the files each lane’s patch.diff changed, turns, and wall time. A prediction goes on #895 before the run. If a gate fails the result goes on #895 and the operator decides; nothing merges.

Scope

  1. MR 1 (Relates to #895), branch test/battery-coder-helper: the task file, parseAgentFile, resolvePrompt, checkSpec, loadTask, lanePrompt, headlessArgs, their tests, the CHANGELOG line. Merged on its own: #896 measures on the same arm.

  2. The contract, unmerged, branch feat/helper-validated-result: the agent file, its tests, helpers.adoc, packages.adoc, the README, the CHANGELOG entry. Validated and consumer-sim run locally; not pushed for merge.

  3. The dry run, the prediction, the operator’s go, the smoke lane, the run, and the result on #895 by the rule.

  4. MR 2 (Closes #895), only when gates a to d hold.

Tests

Category Test Pins

contract

packages/pi-agents/test/contract-drift.test.ts: every packaged agent declares a contract (replacing "every one but general-purpose"); its existing per-agent checks now read general-purpose too: the body names each top-level field quoted, says result.data is an OBJECT and "calling the yield tool exactly once", names result.error, shows each required field with its type, and the wrap-up paragraph says "stop and call `yield`"

the body states the contract the schema declares

contract

same file: the "packaged contracts …​ are exactly these (#396)" block’s expected gains general-purpose.md with the schema above, written out, so its test ("every contracted agent is listed here") holds; general-purpose’s tools: holds yield; the body carries "4,000", "40 paths", "20" and "10"

the bounds, and that prose and schema agree on them

contract

same file, with decideYield and newYieldState from packages/pi-modes/yield-tool.ts and the schema read from the packaged file by parseAgentContract: a conforming payload is accepted, with the three lists empty too; a 4,001-character summary, 41 files, a result of "ok", and an extra top-level field are each, on a fresh newYieldState(), a retry whose message names the field

the pinned TypeBox enforces maxLength, maxItems, enum and additionalProperties on a plain schema: the size bound is real

regression

same file: on one state, two oversize submissions are retries and the third is an accept marked schemaOverridden

the waiver is the only way past the bound, and it is flagged

contract

tools/model-battery/test/run.test.mjs: parseAgentFile gives mode "append" for general-purpose, "replace" for Explore, "append" for a file with no prompt_mode, and each file’s tools; loadTask("coder-helper").tools equals the agent file’s list; loadTask("explore")’s prompt `sha equals sha256 of its body

the arm takes the helper as its file says; no existing fingerprint moves

contract

same file: checkSpec accepts tools: "agent" with prompt.agent and sandbox: true, and refuses it without either; the packaged task list gains coder-helper; coder-helper is in no manifest permutation

the spec’s shape; a fill never runs the arm unasked

contract

tools/model-battery/test/runners.test.mjs: lanePrompt wraps an append prompt in <agent_instructions> under appendSystemPrompt and gives a replace prompt as systemPrompt; headlessArgs carries --append-system-prompt and no --system-prompt for the first, and the reverse for the second; with BARE_PI_ARGS it carries -e builtin:codemode when the tools include codemode and not otherwise, and never when the pi arguments lack --no-extensions

the helper’s body is appended to pi’s prompt, as pi-subagents appends it; a bare lane that lists codemode has the extension that provides it

Mutants, each to fail its test: maxLength dropped from summary; yield dropped from tools:; lanePrompt returning systemPrompt for an append prompt. Coverage bars hold (pi-agents 100 % lines).

Risks

Risk Mode Mitigation

The contract costs the helper its work: turns spent on the report, or a lane ending on a refused yield

loud

gates a and c; the baseline arm on the same cases and model

A helper fills checks with results it did not see

silent

the body forbids it; gate d reads every claim against the transcript before anything merges

A payload still past the bound on its third submission

silent

accepted flagged schemaOverridden, as today for every agent (0 of 161 yields on luchs); the regression test pins the flag

The pinned TypeBox ignores a bound keyword on a plain schema

fail-open

the contract test submits each violation through decideYield and requires a retry

The battery lane differs from a real helper: no parent prompt, no reminder, the battery’s own yield

silent

stated with the result; the bare lane is the stricter case for gate b, having no reminder

codemode or yield fails under the battery’s sandbox

fail-closed

the smoke lane first; the run stops on a harness fault

The swap script leaves main’s agent file in the working tree

loud

restored by the script at exit; git status is checked before any commit

Leads that parse the helper’s prose

silent

none in the tree (grep of packages/ for a reader of general-purpose’s text); the CHANGELOG names the change

Delivery

  • Canonical page: docs/modules/ROOT/pages/helpers.adoc, the yield section: the general-purpose contract, its four fields and its bounds. docs/modules/ROOT/pages/packages.adoc and packages/pi-agents/README.md: the helper’s line.

  • CHANGELOG.adoc == Unreleased: a "Repo only" line for the arm; a Changed entry for the contract.

  • This plan committed as docs/modules/ROOT/pages/plans/helper-validated-result.adoc, listed in docs/modules/ROOT/nav.adoc; Status In progress at start, Done at MR 2’s merge or at the operator’s decision.

  • Validate and consumer-sim before each push; MRs merged with squash off; #895 is closed by MR 2 with its merge SHA on the issue. pi-agents takes a minor bump at the next release.

Edit this page · latest