Skip to content

feat(stirrup_agent,pi_agent): Stirrup's view_image and strip_unparsed_tool_blocks, Pi's plain prompt and MCP discovery deadline - #6972

Open
d-molinari wants to merge 7 commits into
mainfrom
dmolinari/stirrup-pi-agent-options
Open

d-molinari wants to merge 7 commits into
mainfrom
dmolinari/stirrup-pi-agent-options

Conversation

@d-molinari

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

Copy link
Copy Markdown
Contributor

What does this PR do?

Agent options that keep today's behaviour by default, from the drafts #5806, #5835 and #5545, rebased onto main. context_summarization_cutoff, which this PR carried before, landed with #6672, so this PR keeps main's.

Stirrup

  • view_image (off): the model gets Stirrup's view_image tool on the working directory. Stirrup sends the image after the tool's text answer, as a PNG of at most one megapixel, and image_token_estimate counts it.
  • The trajectory export keeps images, as input_image parts holding the data URL the model was sent, and main's reasoning items. User messages that Stirrup adds during a run become output items, in order. A compaction's task and summary stay input items, as on main.
  • strip_unparsed_tool_blocks (true): off, an assistant turn with no parsed tool call goes back to the model as written, so a run that trains on recorded tokens keeps that turn too. The README names it beside the rewrites that stay under "Keeping the recorded history" (feat(stirrup_agent): stop runs once the task has ended and add an option to keep the recorded history #6672's section).

Pi

  • plain_system_prompt (off) leaves out the part of Pi's prompt that names Pi's documentation by path, in the runtime's folder. On Pi 1.5.2, the pin, that is the <docs> section; on Pi 0.80 it is the documentation block and the date line. feat(pi_agent): plain_system_prompt, and a configurable MCP discovery deadline #5545's version matched only Pi 0.80's layout. A replaced prompt goes to the model as Pi builds it.
  • sandbox_mcp_discovery_timeout_seconds (default 30, at most a tool call's timeout) bounds each request that sets up a sandbox session's MCP tools. At the hard-coded 30 s, a busy resources server lost 27 of 781 Pi episodes.

Validation

At this head, on main 64d738eca2, Linux:

  • responses_api_agents/stirrup_agent: 255 passed.
  • responses_api_agents/pi_agent, with Node 22.19 and the pinned Pi 1.5.2 CLI on the path: 478 passed, 2 skipped.
  • Core tests that name either agent (146 files): 8908 passed, 93 skipped. None of the rest is this change's: two tests fail the same way on main on this host (a 64 KiB-page config test, and a CI-script test whose host lacks a command), and two files need mlflow, which this venv lacks.
  • A pinned-Pi test runs Pi against a loopback model. The request's system prompt names Pi's documentation only with the option off, and it keeps Pi's preamble, its tools and the appended prompt. With feat(pi_agent): plain_system_prompt, and a configurable MCP discovery deadline #5545's extension, that test and test_plain_prompt.py fail.
  • Pre-commit passes on the 16 changed files. No lock changes.
  • CI's non-blocking Environment Server compliance check flags Pi's run(), which pi_agent defines on main too.

Rollouts

All three ran before the rebase onto this main:

Compatibility and benchmark impact

  • Every default keeps today's behaviour.
  • The export changes for every Stirrup run: user messages added during a run move to the output items, images stay images, and text-only list content is newline-joined. A run whose contents are plain strings, with every user message before the model's first turn, exports as before.
  • feat(opencode_agent,officeenv_sandbox): stop Codex's, OpenCode's and Terminus 2's runs once their task has ended #6974 (open) adds a sentence to resources_servers/officeenv_sandbox/README.md saying Gym's Stirrup gives the model no tool that shows it an image. Whichever of the two PRs merges second updates it.

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, or N/A for docs-only / non-code changes (so CI unit/server checks pass when applicable).
  • Documentation added or updated, or N/A with justification.
  • Pre-commit checks pass locally (run on the changed files).
  • New source files include the required Apache-2.0 SPDX header.
  • All commits have DCO sign-off (git commit -s) (so the DCO check passes).

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Nov 30, 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

Copy link
Copy Markdown
Contributor Author

/ok to test d0bef56

@svcnvidia-nemo-ci svcnvidia-nemo-ci added risk:high Autobot PR risk: high feature New capabilities, enhancements, or enablement work area:agent Agent harnesses and Responses API agent behavior labels Nov 30, 2026
@d-molinari
d-molinari force-pushed the dmolinari/stirrup-pi-agent-options branch from d0bef56 to 868ea86 Compare December 2, 2026 06:15
@d-molinari d-molinari changed the title feat(stirrup_agent,pi_agent): Stirrup's view_image and history options, Pi's plain prompt and MCP discovery deadline feat(stirrup_agent,pi_agent): Stirrup's view_image and strip_unparsed_tool_blocks, Pi's plain prompt and MCP discovery deadline Dec 2, 2026
@d-molinari

Copy link
Copy Markdown
Contributor Author

/ok to test 868ea86

@d-molinari
d-molinari force-pushed the dmolinari/stirrup-pi-agent-options branch from 868ea86 to 2eba6bd Compare December 2, 2026 22:17
@d-molinari
d-molinari marked this pull request as ready for review December 2, 2026 22:18
@d-molinari

Copy link
Copy Markdown
Contributor Author

/ok to test 2eba6bd

@nemo-pr-automation
nemo-pr-automation Bot requested a review from a team December 2, 2026 22:25
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Dec 2, 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 three correctness risks in the opt-in paths, one required rollout-evidence gap and one documentation note. I reviewed all 16 changed files and traced their callers and downstream consumers.

RISK: Validate recorded-history mode with a real rollout

Could you add a representative real-model smoke rollout with strip_unparsed_tool_blocks: false? The PR description explicitly says that mode has not run yet. AGENTS.md requires representative rollouts for behavior-changing agent work. The earlier capture results do not exercise this option.

Record the task, model and effective recovery/compaction settings, then inspect the agent behavior, capture acceptance and verifier result. Include a turn with an unparsed tool block so the run exercises the new behavior. My loopback probes confirm exact text replay when stripping is disabled; they do not establish that the advertised training configuration works end to end.

Validation

  • I relied on the observed successful CI results for Lint check, Unit tests / Changed server tests, Unit tests / Sandbox tests, Unit tests / Server suite and both harness conformance probes. Four core-test shards were still running in the last successful status read. The non-blocking Environment Server compliance check reports Pi's existing run() method. Later status and job-log reads failed with HTTP 503, so I cannot claim all CI is green or provide CI test counts.
  • I ran focused CPU probes in gym:main-offline, the default branch's CI image, with Python 3.13.14, Node 24.19.0 and Stirrup 0.1.12. MCP discovery deadlines, clamping and pagination behaved as intended. Stirrup probes confirmed exact unstripped text replay, image ordering and compaction handling. They also reproduced the inline findings.
  • I did not rerun passing CI suites or run real-model rollouts. Dependency setup completed after resolving missing packages in the review environment; these probes are not a reproduction of the locked CI environment.

Inline comments (escaped v1):

  • responses_api_agents/pi_agent/plain-prompt.mjs line 18: RISK: Preserve dates supplied by the task. Could date removal target only Pi 0.80's generated footer? DATE currently runs over the complete prompt, including appended and replaced instructions. The pinned Pi 1.5.2 adds no machine date, so plain_system_prompt: true deletes a task-owned line such as Current date: 2020-01-01 instead. I reproduced this with the published Pi 1.5.2 prompt builder in both append and replace modes. A task that supplies its own clock loses it.

    The adapter combines configured and request system instructions before loading this extension. Please preserve those instructions and limit deletion to positively identified harness-generated sections. Check that task dates survive append and replace modes on Pi 1.5.2, and that a legacy prompt containing both a task date and a generated date loses only the latter. Update the existing custom-prompt test, which currently expects its date to disappear.

  • responses_api_agents/stirrup_agent/sandbox_runner.py line 214: RISK: Return recoverable file errors as failed image-tool calls. This exposes LocalShell.view_image, but Stirrup's helper catches only FileNotFoundError and ValueError. A directory raises IsADirectoryError; a file with a valid PNG signature but corrupt contents raises Pillow's UnidentifiedImageError. Both escape the helper.

    I reproduced both through the runner. The corrupt-image entrypoint probe ended after one model call with STATUS=failed and HAS_TRAJECTORY=False; sandbox execution then raises for that error. An ordinary mistaken path or malformed screenshot therefore aborts an opt-in episode instead of letting the model recover.

    Could the adapter translate expected path/read/decode failures into success=False with useful text and no image, while keeping cancellation and unrelated failures propagating? Add runner cases for a directory and a recognized-but-corrupt PNG. Both should permit a subsequent finish call; missing-file and valid-image behavior should stay intact.

  • nemo_gym/trajectory/atif_export.py line 1162: RISK: Image-bearing Stirrup trajectories cannot reach Harbor grading. The new _image_parts export keeps real input_image parts, but this downstream converter rejects them. Harbor exports before invoking its verifier and converts AtifExportError into a masked harbor:trajectory_export_failed result. Thus an otherwise successful Harbor episode using view_image skips grading. The reward-hacking judge also masks this conversion failure.

    A base-versus-head probe exported the same raw history successfully on base and raised AtifExportError: only text content parts are supported on head. Response-schema and observation validation both passed beforehand.

    Could this PR handle image parts at the ATIF boundary for supported pairings, or reject an unsupported pairing explicitly before activation rather than mask completed work? Keep the full image data in the Responses trajectory. Add a regression that takes an image-bearing Stirrup response through Harbor's export path and verifies that grading runs, covering initial and post-tool images.

  • responses_api_agents/stirrup_agent/app.py line 306: NOTE, documentation suggestion: Could you document view_image in the Stirrup README's tool/configuration sections and the published harness guide? The new user-facing option is described in this field and the PR, but the README still lists only shell and request tools and has no view_image entry.

    A minimal view_image: true example should state its false default, the vision-model requirement, path handling and that it works with code_exec: false. Document supported environment/export pairings after resolving the ATIF compatibility finding. This will make the feature usable without reading the implementation.

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

@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Dec 4, 2026
d-molinari and others added 7 commits December 3, 2026 23:13
…tory

The runner never offered the model a way to look at an image file: LocalShell.view_image existed, but no
tool used it. With view_image: true the model gets Stirrup's view_image tool on the working directory. Stirrup sends
the image in a user message after the tool's text answer (text_only_tool_responses), re-encoded as a PNG of at most
one megapixel.

The trajectory export turned an image block into its Python repr: a tool result's list content became str(list), a
user message's image part str(ImageContentBlock), and user messages added during the run went to input_items, out of
order. Images are now input_image parts holding the data URL the model was sent, and user messages after the model's
first turn are output items in their place. Each message list of the history counts on its own: a compaction starts
a new one, whose leading user messages (the task and the summary) stay input items, so a summary is never output.

Contract tests: an initial image, an image after a tool call, two ordered images (two turns and one turn), a missing
file and a file that is no image, a large image downscaled, the option off, and a trajectory with images validating as
a response and an observation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
…rn back as the model wrote it

Training on recorded tokens (token capture) needs each model call of an episode to continue the previous one as the
model wrote it. context_summarization_cutoff (#6672) keeps the history from being summarized; one rewrite still had
no switch: the adapter strips a tool-call block the provider's parser left in an assistant turn's text from the
history sent back (stirrup_utils._strip_unparsed_tool_blocks), so the next call matches no recorded call.

strip_unparsed_tool_blocks (default true, as today) is now an option of the agent server. The server passes it in the
runner payload's client settings, and the model client passes it to the history serializer. The README lists it with
the client options and names it beside the rewrites that stay.

Tests: the payload carries the switch, and an assistant turn with an unparsed block goes back to the model as written
only when stripping is off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
… 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). Pi 0.80 also ends the prompt 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: the <docs> section of Pi 1.5.2's structured prompt (the default pin), or Pi 0.80's
documentation block and date line. The rest of the prompt (tools, rules, the appended system prompt, the working
directory) is unchanged. A prompt with neither, as under system_prompt_mode replace on Pi 1.5.2, is left to Pi:
the hook returns nothing, since a returned prompt replaces Pi's structured one for the run. Sandbox sessions
upload the extension with the others; local runs load it from the package.

Tests: under Node, the extension's edit of Pi 1.5.2's and Pi 0.80.2's prompt layouts, a replaced prompt left
alone, and a custom prompt losing only its date line. With the pinned Pi CLI and a loopback model, the request's
system prompt keeps Pi's preamble, its tools and the appended prompt, and names the documentation only with the
option off. A sandbox session loads the extension 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]>
plain-prompt.mjs removed the first `Current date: YYYY-MM-DD` line anywhere in the system prompt. Pi 1.5.2 adds no
date, so the line it removed was the task's own: a task whose appended or replacing system prompt sets its time lost
it. On Pi 0.80.2 the task's line comes before Pi's, so the task's date went and the machine's stayed.

Pi 0.80 ends the prompt it builds with its date line and then `Current working directory: <cwd>`. The extension now
removes a date line only there: right before the working directory line, with the session's working directory from
the event's systemPromptOptions, that ends the prompt. A sandbox session loads the extension before the runtime
guards, which append to the prompt, so the prompt it gets ends as Pi built it.

Tests that fail on the parent: under Node, on the layouts of Pi 1.5.2 and Pi 0.80.2, the task's date line stays in
append and replace mode while Pi 0.80.2's own date goes, and a date line elsewhere, under another working directory
or with none reported stays; with the pinned Pi 1.5.2 CLI, the task's system prompt reaches the model whole, its date
line included, in both modes; a sandbox session loads plain-prompt.mjs before runtime-guards.mjs. Run over the prompts
the real Pi 1.5.2 and 0.80.2 builders make, in both modes, the extension gives the same results.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
…ailed call

Stirrup's view_image helper turns only a missing file and a file of an unsupported type into a failed call. Other
errors left the tool and ended the run after that call: a directory (IsADirectoryError), a path through a file
(NotADirectoryError), an unreadable file, or a file with a PNG signature that Pillow cannot read
(UnidentifiedImageError, or SyntaxError for a damaged PNG). An image whose header and checksums pass Pillow's check but
whose pixel data does not decode passed the call and failed in the next model request, where Stirrup encodes it,
which ended the run too. A text file was a failed call whose message held the file's whole content.

WorkspaceImages now runs its own view_image executor on LocalShell.view_image. The file system's errors, Stirrup's
type check and Pillow's decoding errors (OSError, SyntaxError, ValueError, DecompressionBombError) are a failed call
with a one-sentence answer and no image. The call encodes the image once, as each request does, so data that does not
decode fails the call. A missing file keeps Stirrup's answer, and a viewed image is answered as Stirrup's tool
answers it. Other errors, and a cancellation, still end the run.

Tests that fail on the parent: through the runner, a directory, a path through a file, a file with only a PNG
signature and a PNG whose pixel data does not decode are failed calls, after which the model's finish ends the run as
completed; an 80 KB text file is answered in a sentence. A missing file keeps its answer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
…no images

The README listed only the shell and the request's tools, and view_image had no entry. It now has a configuration
row and a "Viewing images" section: off by default and for vision models; a file named by its path in the working
directory or its absolute path, with or without code_exec; what the model gets; how a file that cannot be shown is
answered; and what the trajectory keeps.

Gym's ATIF converter takes text content only. The section says where that stops grading: the harbor environment
server masks a turn whose transcript holds an image (harbor:trajectory_export_failed) instead of running the task's
verifier, the reward-hacking judge masks its verdict, and `gym eval export atif` fails on the rollout. view_image is
for environments whose resources server grades the response or the sandbox. The view_image field's description says
the same.

Tests for what the section states: view_image with code_exec off, by a relative and by an absolute path; a Stirrup
transcript without an image converts to ATIF as Harbor exports a turn, and one with an image is refused.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
@d-molinari
d-molinari force-pushed the dmolinari/stirrup-pi-agent-options branch from 2eba6bd to 8b57ec8 Compare December 4, 2026 07:13
@d-molinari

Copy link
Copy Markdown
Contributor Author

/ok to test 8b57ec8

@d-molinari

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Addressed in 8b57ec88e9 (rebased on main 98458af5c9):

  1. Task dates survive plain_system_prompt (6f5b73e0e1): plain-prompt.mjs now removes a date line only where Pi 0.80 writes it, directly before the Current working directory: <cwd> line that ends Pi's own prompt (the sandbox loads it ahead of runtime-guards.mjs, so that holds). A task's own Current date: line survives append and replace mode on Pi 1.5.2, and only the generated date goes on Pi 0.80.2. Node tests, the pinned-Pi CLI test in both modes and a load-order test cover it; they fail on the previous head.
  2. view_image answers a file it cannot show with a failed call (173bfa9256): file-system, type-check and Pillow decode errors give success=False, a one-sentence message and no image. The image is encoded once inside the call, so undecodable pixels can no longer break the next model request. Cancellation and other errors still propagate. New cases: a directory, a path through a file, a PNG signature only, a checksum-valid PNG with undecodable pixels, and an 80 KB text file (previously echoed back in full).
  3. ATIF export of image-bearing trajectories: left as a documented limitation. ATIF v1.7 carries images only as file paths, so exporting them needs the core converter to write image files and Harbor to upload them, which is outside this adapter PR. The README and the view_image field now say that Harbor masks such a turn, the reward-hacking judge masks its verdict and gym eval export atif fails; a test pins that a Stirrup transcript converts without an image and is refused with one. view_image stays off by default.
  4. Docs: view_image is in the README's tool list and configuration table, with a "Viewing images" section (default, vision-model requirement, paths, code_exec: false, failure answers, what the trajectory keeps, which pairings grade it).
  5. A real rollout with strip_unparsed_tool_blocks: false: gpt-5.5 on five OfficeEnv sandbox tasks, with context_summarization_cutoff: null and both recoveries off. All five completed with reward 1.0, and in all 55 consecutive model-call pairs the next request carried the earlier messages unchanged plus the reply exactly as written. Even when prompted for one, gpt-5.5 never wrote a tool-call block in a turn without a parsed call (117 of 117 replies across 10 episodes had one), so the stripping branch itself is covered by the stub-model runner test only. Token-capture acceptance needs a vLLM policy run, which a hosted model can't show.

Tests at the head before the final no-conflict rebase: stirrup_agent 262 passed; pi_agent 484 passed, 2 skipped (Node 22.19.0, pinned Pi 1.5.2); the 147 core test files that name either agent give the same results as main (2 failed and 2 collection errors on both); pre-commit clean on the 16 changed files.

This branch has not been deployed

No deployments
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 risk:high Autobot PR risk: high 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.

2 participants