Repository navigation
Conversation
A subagent policy only works where the model reads it. Upstream ships the delegation advice as the `Agent` tool's `promptGuidelines`, and pi flattens those into the one flat `<rules>` list that every tool and pi's own "be concise" share, so the policy arrives as generic advice next to advice about file paths. Nothing told the model that `explore` is for questions about existing code, that `plan` is for a multi-file change, or that delegating is cheaper than doing the work inline: that lived only in the tool's description and in the profile list. - The policy now ends every run's prompt as a `<delegation>` block, built from the enabled profiles: `explore` and `plan` get a rule of their own, the other enabled subagents are listed by name. - The block rides on the text of the prompt, through a `before_agent_start` handler that returns `systemPrompt` (the shape `createExactSystemPromptExtension()` already uses), so a prompt another extension forced earlier is carried along rather than overwritten. - The `Agent` tool's prompt snippet says to delegate whenever possible and points at the delegation section. - The three `promptGuidelines` are gone: the block says the same things in the place the model reads, and keeping both would say each of them twice.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What it does
The delegation policy — when to delegate, and which subagent to pick — now reaches the model in a form it reads.
lib/subagent-extension.tsgainssubagentDelegationBlock(profiles): a<delegation>block, one rule per line, built from the enabled profiles. An intro line (Agentruns a whole task in a fresh session and returns only the result, so this conversation stays small), a rule forexplore(any question about existing code: where a symbol lives, how a flow works, which files touch a feature), a rule forplan(before an edit that spans several files or steps: steps, files, risks, verification), the shared rules, and any other enabled profile listed by name.withSubagentDelegationPrompt(prompt, profiles)appends that block to the prompt text.before_agent_starthandler returns{ systemPrompt: withSubagentDelegationPrompt(event.systemPrompt, profiles) }, so the block rides on every run's prompt, and a prompt another extension forced earlier is carried along rather than overwritten (event.systemPromptis rendered when it is read).Agenttool'spromptSnippetnow says to delegate whenever possible and points at the<delegation>section of the system prompt.The three existing
promptGuidelineson theAgenttool are removed. Reason: the block says the same three things, in the place the model actually reads; keeping both would state each of them twice, and the guidelines' version is the one the model tends to skip. Nothing is lost — the three upstream rules are covered one-for-one by the block:promptGuidelinesAgentcalls in one response for independent parallel work; their scopes may overlap, and an isolated run can use a worktree."One consequence, for the record: the Tool Definitions panel shows a tool's
promptGuidelines(it hides the section when there are none), so theAgententry no longer lists a "Guidelines" section. The policy is in the run's prompt instead.Deliberately not part of this change: the fork's rewording of the built-in
explore/planprofile descriptions inlib/subagents.ts(the block carries what each profile is for, so the descriptions need no change), and the fork'slib/rpc-manager.tschange (upstream already reports the per-run prompt).Why it matters
On
mainthe policy that says when to delegate never reaches the model in a form it reads.lib/subagent-extension.ts:183-194(onmain) registers theAgenttool with the policy as threepromptGuidelines:pi flattens a tool's
promptGuidelinesinto the one shared<rules>list (@earendil-works/pi-coding-agent/dist/core/system-prompt.js:31-64,buildRules()), so the model receives this:A subagent policy reads there as generic advice next to "be concise". Nothing tells the model that
exploreis for questions about existing code, thatplanis for a multi-file change, or that delegating is cheaper than doing the work inline: that exists only in the tool'sdescriptionstring and in the profile list. So with subagents enabled the model has no policy for delegation, and picks a profile — or does the work itself — without a reason.How to reproduce (on
main, before the fix)With the built-in subagents enabled, start a session and look at the system prompt the provider receives (the integration test below does exactly this against a real
AgentSession):On
mainthe prompt's<rules>list holds the three delegation bullets among pi's own rules, and there is no<delegation>block anywhere in it. After the fix, the prompt ends with:Testing
The new tests fail on
main(the base commite533d9b3) and pass with the fix.On the base commit, with only the new tests added:
With the fix (Node 26.7.0):
New tests:
lib/subagent-extension.test.mjs: "every run's prompt carries the delegation block, and the tool's rules do not" and "the delegation block names the enabled profiles and leaves the disabled ones out".lib/subagent-extension.integration.test.mjs: "the prompt the model receives carries the delegation block, not the flat rules list" and "a prompt another extension forced earlier is kept, and the block still rides on it" — both against a realAgentSession, reading the system message the provider receives.Provenance
Ported from the Bun-running fork https://github.com/brynne8/pi-web-bun, commit
5f2ef78e("fix(agent): carry the delegation policy in the prompt, and steer the model to it"). Ported by hand onto upstream's currentlib/subagent-extension.ts(the fork's file has been rewritten since), with upstream's structure, naming and comment style kept. The fork'slib/rpc-manager.tschange and its rewording of the built-in profile descriptions are not part of this PR.