Skip to content

feat(pi_agent): plain_system_prompt, and a configurable MCP discovery deadline - #5545

Closed
d-molinari wants to merge 2 commits into
mainfrom
dmolinari/pi-plain-system-prompt
Closed

d-molinari wants to merge 2 commits into
mainfrom
dmolinari/pi-plain-system-prompt

Conversation

@d-molinari

@d-molinari d-molinari commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Two pi_agent options, both keeping today's behavior by default.

plain_system_prompt, default off. When on, Pi's system prompt leaves out two parts:

  • The documentation block. It points the model at Pi's README, docs and examples by path, and those paths are in the adapter's runtime folder (/tmp/nemo-gym-pi-node-22.19.0-<version>/pi/node_modules/@earendil-works/pi-coding-agent/...). So a model in a sandbox session reads the adapter's folder name in every request.
  • The Current date: line. It gives the machine's date, which contradicts a task that sets its own time.

The rest of Pi's prompt is unchanged: tools, guidelines, the appended system prompt and the working directory.

How it works.

  • A Pi extension, plain-prompt.mjs, edits the prompt in its before_agent_start hook. runtime-guards.mjs appends its sandbox note the same way: Pi 0.80.2 chains its extensions' prompt edits in load order.
  • Sandbox sessions upload the extension with the others. Local runs load it from the package.

With system_prompt_mode (#5144).

  • replace swaps Pi's whole default prompt for the configured one, tools list and guidelines included, and Pi still adds the date.
  • plain_system_prompt keeps the default prompt and removes only those two parts.
  • The two compose: under replace, which has no documentation block, only the date goes.

sandbox_mcp_discovery_timeout_seconds, default 30 s: how long each request that sets up a sandbox session's MCP tools (initialize, tools/list) may wait, never more than a tool call's sandbox_mcp_timeout_seconds. Until now it was a hard-coded 30 s.

  • A required grant that is not set up stops Pi before its first model call, so the episode is lost. In a training run with a few hundred episodes on one resources server, 27 of 781 Pi episodes (3.5%) were lost there while the server was busy.
  • The adapter passes it to gym_mcp.mjs in each grant's MCP configuration as discovery_timeout.

Validation

  • tests/test_plain_prompt.py runs the extension under Node and checks the whole edited prompt:
    • on Pi 0.80.2's layout, the documentation block and the date go and everything else stays;
    • on a custom prompt, only the date goes.
    • It passes, and is skipped without Node, like the adapter's other extension tests.
  • tests/test_sandbox.py::test_sandbox_plain_system_prompt_loads_its_extension_only_when_on fails on main for both values and passes here.
  • Pi's tests (Linux aarch64, Python 3.13, no Node): 337 passed and 31 skipped (the Node-based ones).
    • One failed: test_opensandbox_sdk_is_available_in_agent_environment. It needs the sandbox extra, which that venv lacks, and it fails the same way on main there.
  • Gym's core suite (pytest -m "not sandbox"): every failure also fails on main in the same environment. They are environment-bound: Harbor's compose overlay and run summary, the benchmark listing, and the OpenSandbox scripts' help.
  • tests/test_gym_mcp.mjs: a discovery request honours discovery_timeout (a 300 ms initialize times out at 100 ms and passes at 1 s) and stays capped by the call timeout. It fails without the change and passes here (18 of 18 under Node 26).
  • tests/test_sandbox.py: the MCP configuration carries discovery_timeout, and the setting stays within Node's timer range and defaults to 30 s. These 6 cases fail without the change.
  • pre-commit and detect-secrets pass on the changed lines (detect-secrets flags one line of test_sandbox.py that is already on main).

Rollouts

N/A: both options keep today's behavior by default. plain_system_prompt changes only the system prompt's text, which test_plain_prompt.py checks; a longer discovery deadline only lets setup wait longer for a busy server.

Compatibility and benchmark impact

None at the defaults: plain_system_prompt is off, and discovery keeps its 30 s.

Checklist

  • I have read the contributing guidelines.
  • The change is focused; unrelated "drive-by" edits are tracked as separate issues/PRs.
  • Tests added or updated and pass locally.
  • Documentation added or updated (both options are listed in responses_api_agents/pi_agent/README.md).
  • Pre-commit checks pass locally.
  • New source files include the required Apache-2.0 SPDX header.
  • All commits have DCO sign-off (git commit -s).

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Nov 3, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@d-molinari d-molinari changed the title feat(pi_agent): plain_system_prompt leaves Pi's documentation block and the date out of its prompt feat(pi_agent): plain_system_prompt, and a configurable MCP discovery deadline Nov 4, 2026
@d-molinari
d-molinari marked this pull request as ready for review November 5, 2026 00:46
d-molinari and others added 2 commits November 4, 2026 16:49
…nd the machine's date out of its prompt

Pi's default system prompt points at Pi's own documentation by path, in the runtime's folder:
/tmp/nemo-gym-pi-node-22.19.0-<version>/pi/node_modules/@earendil-works/pi-coding-agent/README.md, docs and
examples. A model in a sandbox session reads the adapter's folder name on every call (three paths in
each request). The prompt also ends with the machine's date, which a task that sets its own time
contradicts.

With plain_system_prompt on (default off), the adapter loads plain-prompt.mjs, which removes both through Pi's
before_agent_start hook, as runtime-guards.mjs appends its sandbox note; Pi 0.80.2 chains the edits of its
extensions in load order. The rest of the prompt (tools, guidelines, the appended system prompt, the working
directory) is unchanged. Under system_prompt_mode replace, whose prompt has no documentation block, only the
date goes. Sandbox sessions upload the extension with the others; local runs load it from the
package.

Tests: the extension's edit of Pi 0.80.2's prompt layout under Node, a custom prompt losing only the date; a
sandbox session loads it only when the option is on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
Pi's MCP discovery (initialize, tools/list) gave up after a hard-coded 30 s, at most the tool-call timeout. A
resources server busy with many other sessions can take longer to answer: in a training run with a few hundred
episodes on one server, 27 of 781 Pi episodes (3.5%) failed there while the server built worlds and collected garbage
on its event loop. A required grant that is not set up stops Pi before its first model call, so each such episode was
lost.

sandbox_mcp_discovery_timeout_seconds (default 30, as before) sets the deadline. gym_mcp.mjs reads it from the MCP
configuration as discovery_timeout, and a discovery request still never waits longer than a tool call.

Tests that fail on the parent: a discovery request honours discovery_timeout (a 300 ms initialize times out at
100 ms, passes at 1 s, and stays capped by the call timeout); the MCP configuration carries it; the setting stays
within Node's timer range and defaults to 30 s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
@d-molinari
d-molinari force-pushed the dmolinari/pi-plain-system-prompt branch from 9e10005 to 71470fd Compare November 5, 2026 01:06
@d-molinari
d-molinari requested review from Kipok, RyaliNvidia and yaoyu-33 and removed request for RyaliNvidia and yaoyu-33 November 5, 2026 23:11
@d-molinari

Copy link
Copy Markdown
Contributor Author

/ok to test 71470fd

@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 5, 2026 23:19
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 6, 2026 22:05
@kajalj22
kajalj22 removed the request for review from a team November 6, 2026 22:50
@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Nov 6, 2026
@cmunley1

cmunley1 commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

/review

@svcnvidia-nemo-ci svcnvidia-nemo-ci added feature New capabilities, enhancements, or enablement work area:agent Agent harnesses and Responses API agent behavior needs-review PR is ready for code review and waiting on a reviewer labels Nov 7, 2026

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHIP WITH CARE

I found one prompt-correctness RISK, detailed inline, and one validation RISK.

RISK — Provide the required real smoke-rollout evidence

The PR marks rollouts N/A because the defaults stay unchanged, but enabling these options changes agent behavior: the prompt extension edits the model's instructions, and the discovery setting changes required-tool setup. Protected AGENTS.md requires representative real model rollouts for behavior-changing agent work. The new tests establish prompt editing, staging, and HTTP deadlines separately; they don't establish a working model/tool/verifier episode. This is an evidence gap, not a demonstrated runtime failure.

Could you replace the N/A statement with the configuration, command, artifact reference, and inspected agent/verifier outcome from a representative opt-in smoke rollout? Use plain_system_prompt: true and a real required MCP grant. To exercise the longer deadline, a discovery response delayed about 35 seconds with discovery set to 60 seconds and calls to 120 seconds should finish setup before inference, permit a granted tool call, and allow verification and confirmed session close. Inspect the captured system prompt to confirm that Pi's documentation and machine date disappear while task instructions, task dates, the working directory, and the sandbox note remain.

Preserve the default-off behavior and the append/replace and built-in-tool assertions in the existing prompt-control test. Retain the discovery-cap and tool-call cancellation checks. No implementation patch or aggregate reward profile is required for this evidence gap.

I completed the changed-file and affected-path inspection. These acceptance checks are proposed; I didn't execute tests or rollouts.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

// plain_system_prompt: Pi's default system prompt without the block that points at Pi's own documentation, whose
// paths name the runtime's folder, and without the machine's date, for tasks whose prompt sets their own time.
const DOCUMENTATION = /\n\nPi documentation \([^\n]*\):(?:\n- [^\n]*)*/;
const DATE = /\nCurrent date: \d{4}-\d{2}-\d{2}(?=\n|$)/;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RISK — Remove Pi's generated date, not the task's first date line

The first-match replacement can do the opposite of the advertised behavior. For the prompt ordering represented in the new test, pass this string to the hook:

Task context:
Current date: 2020-01-01
Use the task date.
Current date: 2026-10-31
Current working directory: /workspace

It deletes the task's 2020-01-01 line and leaves the generated 2026-10-31 line. Such task instructions are accepted through _conversation_input. This affects opt-in appended and replacement prompts that set their own date—the option's intended use case.

Could you target the final generated date/working-directory footer instead? For the inspected layout, replace DATE and plainPrompt below, keeping DOCUMENTATION unchanged:

const DATE = /\nCurrent date: \d{4}-\d{2}-\d{2}(?=\nCurrent working directory:)/g;

export default function plainPrompt(pi) {
  pi.on("before_agent_start", (event) => {
    let systemPrompt = event.systemPrompt.replace(DOCUMENTATION, "");
    const date = [...systemPrompt.matchAll(DATE)].at(-1);
    if (date) {
      systemPrompt = systemPrompt.slice(0, date.index) +
        systemPrompt.slice(date.index + date[0].length);
    }
    return { systemPrompt };
  });
}

This selects the last footer pair, preserving even an earlier pair quoted by the task. The invariant is that only Pi's generated date disappears; task dates, other instructions, documentation removal, the working directory, and the sandbox note retain their intended behavior. Please verify the suggested code against the pinned Pi runtime before adopting it.

Proposed acceptance checks: Add the example above to the hook test in both default-plus-appended and replacement layouts; assert that the task date remains and the machine date disappears. Add an earlier task-owned date/working-directory pair and assert that it remains. A prompt without a generated footer should retain its task date. Retain the existing whole-string assertions for documentation removal and preservation of task text, working directory, and sandbox note. These checks follow from source reasoning and weren't executed.

@d-molinari

Copy link
Copy Markdown
Contributor Author

Folded into #6972. plain_system_prompt now also removes the <docs> section of Pi 1.5.2, main's pin, which this PR's version left in place. Closing.

@d-molinari d-molinari closed this Nov 30, 2026

This branch was previously deployed

1 inactive deployment
public — 71470fd4 Deployed Nov 5, 2026 by copy-pr-bot[bot] via release / finalize / notify #10541
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Agent harnesses and Responses API agent behavior feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer sla:review-overdue Review response is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants