Repository navigation
feat(pi_agent): plain_system_prompt, and a configurable MCP discovery deadline - #5545
d-molinari wants to merge 2 commits into
Conversation
…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]>
9e10005 to
71470fd
Compare
|
/ok to test 71470fd |
|
/review |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
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|$)/; |
There was a problem hiding this comment.
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.
|
Folded into #6972. |
What does this PR do?
Two
pi_agentoptions, both keeping today's behavior by default.plain_system_prompt, default off. When on, Pi's system prompt leaves out two parts:docsandexamplesby 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.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.
plain-prompt.mjs, edits the prompt in itsbefore_agent_starthook.runtime-guards.mjsappends its sandbox note the same way: Pi 0.80.2 chains its extensions' prompt edits in load order.With
system_prompt_mode(#5144).replaceswaps Pi's whole default prompt for the configured one, tools list and guidelines included, and Pi still adds the date.plain_system_promptkeeps the default prompt and removes only those two parts.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'ssandbox_mcp_timeout_seconds. Until now it was a hard-coded 30 s.gym_mcp.mjsin each grant's MCP configuration asdiscovery_timeout.Validation
tests/test_plain_prompt.pyruns the extension under Node and checks the whole edited prompt:tests/test_sandbox.py::test_sandbox_plain_system_prompt_loads_its_extension_only_when_onfails on main for both values and passes here.test_opensandbox_sdk_is_available_in_agent_environment. It needs thesandboxextra, which that venv lacks, and it fails the same way on main there.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 honoursdiscovery_timeout(a 300 msinitializetimes 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 carriesdiscovery_timeout, and the setting stays within Node's timer range and defaults to 30 s. These 6 cases fail without the change.pre-commitanddetect-secretspass on the changed lines (detect-secrets flags one line oftest_sandbox.pythat is already on main).Rollouts
N/A: both options keep today's behavior by default.
plain_system_promptchanges only the system prompt's text, whichtest_plain_prompt.pychecks; a longer discovery deadline only lets setup wait longer for a busy server.Compatibility and benchmark impact
None at the defaults:
plain_system_promptis off, and discovery keeps its 30 s.Checklist
responses_api_agents/pi_agent/README.md).git commit -s).🤖 Generated with Claude Code