Skip to content

feat(pi): attach prompt images in agent sessions - #4923

Merged
yaoyu-33 merged 5 commits into
mainfrom
ananthsub/pi-session-images
Nov 10, 2026
Merged

yaoyu-33 merged 5 commits into
mainfrom
ananthsub/pi-session-images

Conversation

@ananthsub

@ananthsub ananthsub commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Where this sits

The base branch is main, which now has #4917 (sandbox bytes, media decoding in nemo_gym.core, and content-named media staging in nemo_gym.sandbox), #4934 (sandbox transfer telemetry) and #5862 (activation staging inside the close fence).

flowchart BT
  main["main, with 4917 media staging,<br/>4934 telemetry, 5862 close-fence staging"]
  p4922["4922: OpenCode session images"]
  p4923["4923: Pi session images"]
  p5719["5719, yfw: images in tool replies,<br/>lent sandboxes, OpenCode settings"]
  p4922 --> main
  p4923 --> main
  p5719 --> p4922
  classDef current stroke:#d97706,stroke-width:3px
  class p4923 current
Loading

Each arrow points from a PR to its base. #4922 and #4923 can merge in either order.

What changed

pi_agent sandbox sessions now pass prompt images to Pi, and Pi now passes images it reads in the sandbox to the model.

flowchart TD
  req["Activation request"] --> val["Validate: images only in the user message<br/>decode once"]
  val -->|"image outside the user message, non-data URI,<br/>bytes that are not a supported image"| r422["422 naming the problem"]
  val --> cfg["models.json declares image input<br/>for prompt images or image_input"]
  cfg --> path["Content-hash path per image<br/>/tmp/nemo-gym-media/sha256.ext"]
  path --> stage["stage_media in the activation staging, uploads each distinct image once<br/>deadline starts when the activation holds a concurrency slot<br/>close cancels staging before releasing the sandbox"]
  stage --> run["pi with an @path argument per image<br/>prompt text on stdin, runs for the rest of the timeout"]
  run --> att["Pi checks each file's leading bytes<br/>and attaches it to the prompt"]
  att --> model["Model request with image parts<br/>same prompt for every rollout of a task"]
Loading
  • A session accepts base64 data-URI input_image parts in the user prompt. The adapter stages each image at /tmp/nemo-gym-media/<sha256>.<extension> with nemo_gym.sandbox.stage_media and passes that path to Pi as an @<path> argument, which Pi attaches to the prompt it reads from stdin. The path depends only on the image, so every rollout of a task gives Pi the same prompt.
  • Staging runs in the session's activation staging, inside the shared session execute. Closing the session cancels staging before it releases the sandbox. A Pi session has one activation, and it now has a deadline: it starts once the activation holds a concurrency slot, staging spends it, and Pi runs for what remains of the agent timeout.
  • A staging failure fails the activation with the sandbox error from feat: binary sandbox files and shared media helpers #4917: SandboxUnavailableError when the provider cannot run a staging command, including when that command times out, and SandboxTransferError when the command fails inside the sandbox. Only the activation's own deadline reports as a TimeoutError.
  • The session's models.json declares the Gym model with input: ["text", "image"] when the prompt has images or the new image_input setting is on, and keeps input: ["text"] otherwise. With input: ["text"], Pi replaces every image with the note "Current model does not support images. The image will be omitted from this request.", including images its read tool returns, so a text-only deployment keeps working. Set image_input: true for a vision model whose tasks keep their images in the sandbox, such as Harbor tasks, where the prompt has none. This follows the rule proposed on feat: images in tool replies, a lent-sandbox helper and OpenCode session limits for multi-harness training #5719, and feat(opencode): attach prompt images in agent sessions #4922 uses the same setting name, default and rule for OpenCode.
  • Sessions set images.autoResize to false in Pi's settings.json. Pi otherwise resizes images larger than 2000 by 2000 pixels or 4.5 MB once base64-encoded, both prompt images and images its read tool returns, so the same task reached the model with different pixels under Pi and OpenCode. Images now reach the model as the environment sent them.
  • The request is validated and its images decoded only for a new activation. A retry is compared with the stored request without decoding, as in feat(opencode): attach prompt images in agent sessions #4922; a changed retry gets a 409.
  • Images in the system message, image URLs that are not data URIs, bytes that are not a supported image, and other unsupported content get a 422 with a message naming the problem.
  • Decoding uses nemo_gym.core.split_text_and_media and staging uses nemo_gym.sandbox.stage_media, both from feat: binary sandbox files and shared media helpers #4917.
  • The README describes how Pi sends attached files to the model, and notes that saved trajectories keep the prompt's text but not its images.

The local /run path and pi_sandboxed_agent are unchanged.

Why

Multimodal tasks put images in the prompt as input_image parts, and the session path rejected them outright. The text-only declaration also meant Pi never sent an image to the model, even when the task asked it to open one.

No issue: this is one harness's part of multimodal support, and the change is self-contained.

Compatibility

A text-only prompt keeps input: ["text"] unless image_input is set, so text-only deployments behave as before. With image_input: true, or with images in the prompt, a text-only deployment rejects a request that carries an image, for example after the agent reads a PNG in a SWE repository.

Staged images stay at their content-named paths in a borrowed sandbox after the session ends; the number of distinct images bounds them. Pi's run time now excludes the time spent staging images, which is zero for a prompt without images.

Images larger than Pi's resizing limits now reach the model at full size in sessions, where Pi used to shrink them. A deployment with a smaller image size or context limit can reject or truncate such a request.

Validation

  • pytest -n 16 responses_api_agents/pi_agent/tests: the only failures are tests that run Pi's pinned runtime, which needs a newer Node than this environment has, and the OpenSandbox dependency check. They fail the same way on the base branch.
  • Tests drive the HTTP session flow and check that prompt images are staged byte for byte at their content-named paths and passed in order as @file arguments, including after a system message, and that models.json declares image input for image and text prompts alike. The rejection cases (an image URL, an unsupported media type, an image in a system message) check the adapter's 422 message and that Pi never launches. The test image is a valid PNG that Pi recognizes as an image.
  • Staging tests check that closing the session during staging stops the upload before the sandbox is released, leaves no partial file, and never launches Pi, and that staging slower than the agent timeout fails fast without launching Pi. A provider timeout or a failed command while staging fails the activation with the sandbox error rather than a timeout, never launches Pi and leaves no partial file.
  • A test checks that a text prompt declares image input only when image_input is set, and the image tests check that a prompt with images declares it either way.
  • A test checks that the session's settings.json turns off image resizing, and another that a retried image activation decodes its images once and launches Pi once.
  • Each of those checks fails when the code it covers is removed or changed, including staging outside the activation, a missing deadline and missing partial-file cleanup.
  • Rebased onto main after feat: binary sandbox files and shared media helpers #4917 merged. Pi's activation stages fix(agents): stage activation files inside the close fence #5862's configuration and extension files, then the prompt images, then prompt.txt, all inside the session's execute, so close cancels each upload and the activation deadline bounds them. The Pi tests, including fix(agents): stage activation files inside the close fence #5862's close tests, pass apart from the failures above.
  • pre-commit run --files <changed files> passed.

Rollout evidence

Local runs of 30f62b35ea, whose Pi code and the shared code it uses are identical to this head after the rebase onto main, with Qwen3-VL-30B-A3B-Instruct on vLLM 0.29.0 (default sampling), Pi 0.80.2 (the configured version) in Docker sandboxes, driven through single_agent_turn_legacy so each row runs as an agent session, and graded by mcqa (ten options, so a model that cannot see the image scores about 10% by guessing). Each dataset has five image questions (color, shape, number, dot count and word) plus a text-only control.

  • Prompt images, staged at content-named paths, with the default setting: 6 of 6 correct.
  • Images Pi opened with its read tool from files in the sandbox, with image_input: true: 6 of 6 correct, with read called for every image. This dataset has no prompt images, so staging does not touch it.
  • The same sandbox-image tasks with the default setting: Pi returned the "omitted" note for every image it read, and only the text control was correct, as intended for a text-only prompt.
  • The test images are 768 by 768 pixels, below Pi's resizing limits, so these runs do not exercise turning resizing off.
  • Earlier runs of 0f0c6c09f1 and 9d33b8bfe9 scored 5 of 6 and 4 of 6 on the sandbox-image tasks, missing a dot count and once reading "210" as "200". A capture of the model requests for those two rows showed each image, byte-identical to its file, in a user message right after the read result, so those were misreadings.
  • The previous head, which uploaded images into the session directory before the activation, scored 6 of 6 and 5 of 6 on the same datasets, with the same dot miscount.
  • An earlier run of the sandbox-image tasks through pi_sandboxed_agent with input: ["text"]: Pi returned the "omitted" note for every image, and only the text control and one guess were correct.

@ananthsub ananthsub added feature New capabilities, enhancements, or enablement work area:agent Agent harnesses and Responses API agent behavior labels Oct 22, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team October 22, 2026 14:15
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Oct 22, 2026
@ananthsub
ananthsub force-pushed the ananthsub/opencode-session-images branch from ee4fdd0 to bc4afe4 Compare October 22, 2026 14:33
@ananthsub
ananthsub force-pushed the ananthsub/pi-session-images branch from 9e494d7 to 4531aff Compare October 22, 2026 14:34
@ananthsub
ananthsub changed the base branch from ananthsub/opencode-session-images to ananthsub/sandbox-spec-file-bytes October 22, 2026 14:34
@ananthsub
ananthsub requested a review from yaoyu-33 October 22, 2026 15:57
@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Oct 23, 2026
@ananthsub
ananthsub force-pushed the ananthsub/sandbox-spec-file-bytes branch from a2aaa80 to ee03142 Compare November 9, 2026 03:33
@ananthsub
ananthsub force-pushed the ananthsub/pi-session-images branch from 4531aff to 39d73d2 Compare November 9, 2026 03:43
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 9, 2026 03:44

@yaoyu-33 yaoyu-33 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.

Reviewed 87ef85d alongside #4922, mainly for consistency between the two adapters' image contracts (the harness guide in #5868 now documents both).

What matches #4922, and looks right:

  • Decoding with split_text_and_media(), and a 422 for images outside the user message.
  • Content-named stage_media() paths: Pi puts each path in a <file name=...> tag, so a stable path keeps the prompt identical across rollouts.
  • Staging inside the activation, so close cancels it.
  • The sandbox error types.

The rollout evidence, with byte-identical images in the captured calls for the read-tool case, is convincing.

Two differences from OpenCode, inline. One general point: both adapters now always declare image input. That behaves the same way in both, but on a text-only deployment a task whose repository holds an image can now fail where the model used to get Pi's "omitted" note. I raised this on #5719; whatever the decision (always, or a configuration switch), it should apply to both adapters together.

Comment thread responses_api_agents/pi_agent/README.md Resolved
Comment thread responses_api_agents/pi_agent/app.py Resolved
yaoyu-33 added a commit that referenced this pull request Nov 9, 2026
Pi (#4923) now takes prompt images as @path arguments, so it joins
OpenCode as a reference adapter and gets its own row in the adapter
table, with where Pi puts the images and its default resizing (which
images.autoResize turns off). From the updated #4917: who creates the
media directory, cleanup of partial files on failure, where staged files
live on providers that share the host's /tmp, and the
SandboxUnavailableError / SandboxTransferError split. Staging now has to
run under the activation's deadline, as Pi does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 9, 2026 23:04
@ananthsub
ananthsub force-pushed the ananthsub/pi-session-images branch from 4c13057 to 13778ec Compare November 9, 2026 23:13
@github-actions github-actions Bot removed the sla:review-overdue Review response is over the one-business-day SLA label Nov 9, 2026
@ananthsub
ananthsub requested a review from yaoyu-33 November 9, 2026 23:41
@ananthsub

Copy link
Copy Markdown
Contributor Author

@yaoyu-33, on the point in your review that both adapters always declare image input: 30f62b3 applies the rule you proposed on #5719. A Pi session declares image input when the prompt has images or when the new agent setting image_input is true. Otherwise it keeps input: ["text"], and Pi replaces any image its tools return with its "omitted" note, so text-only deployments behave as before. Harbor-style tasks, whose images are files in the sandbox, set image_input: true.

Smoke runs on 30f62b3 with Qwen3-VL-30B-A3B-Instruct:

  • Prompt images with the default setting: 6 of 6 correct.
  • Sandbox images with image_input: true: 6 of 6 correct.
  • Sandbox images with the default setting: Pi sent the "omitted" note for each image, and only the text control was correct.

If #4922 adopts the same rule, using the setting name image_input there too keeps the two adapters' contracts the same.

yaoyu-33 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

sg

yaoyu-33
yaoyu-33 previously approved these changes Nov 9, 2026
The pi_agent session path rejected any input_image part with a 422,
and its models.json declared the Gym model as text-only.
Pi leaves images out of model requests for a text-only model,
including images its read tool returns, which it replaces with an "omitted" note.

A session now accepts base64 data-URI input_image parts in the user prompt.
The adapter decodes them with nemo_gym.core.split_text_and_media, uploads them into the
session directory with nemo_gym.sandbox.upload_media, and passes each one to Pi as an @file argument.
The session's models.json declares image input, so images the read tool returns reach the model.
Media in the system message and image URLs are still rejected with a 422.

Signed-off-by: Ananth Subramaniam <[email protected]>
The image rejection test sent input_image parts without detail,
so the request schema returned a 422 before the adapter ran.
Removing the system-message media check or the 422 for undecodable media still passed.
The rejection cases now carry detail and assert the adapter's message,
and add an unsupported media type.

New tests cover user images after a system message, two images kept in order,
an image-only prompt, and a text prompt that still declares image input.
The test image is now a valid PNG, which Pi recognizes as an image;
the old fixture had no IHDR chunk, so Pi would have inlined it as text.

_validate_request returns the user prompt's media, so a request decodes it once.
The README describes how Pi sends attached files to the model,
and that saved trajectories keep the prompt's text but not its images.

Signed-off-by: Ananth Subramaniam <[email protected]>
…ation

The session uploaded prompt images into its own random session directory,
so Pi put a different path into the prompt on every rollout of the same task.
The upload also ran before the activation started: the agent timeout did not bound it,
and closing the session did not stop it.

Images are now staged with nemo_gym.sandbox.stage_media at /tmp/nemo-gym-media/<sha256>.<extension>,
and each @file argument names that path, so the prompt depends only on the task.
Staging runs in the session's stage_activation, inside the shared execute,
so close cancels it before launch.
The deadline starts once the activation holds the concurrency slot,
and Pi runs for what remains of the timeout after staging.

Signed-off-by: Ananth Subramaniam <[email protected]>
Pi resizes images above 2000 by 2000 pixels or 4.5 MB of base64, both
for @file arguments and for images its read tool returns. The OpenCode
adapter sends images as the environment sent them, so the same task
reached the model with different pixels under the two harnesses.
Sessions now write images.autoResize false into Pi's settings.json.

A retried activation decoded its images again before it was compared
with the stored request. Validation and decoding now run only for a new
activation, and a retry is compared with the request as received, as
the OpenCode adapter does.

Signed-off-by: Ananth Subramaniam <[email protected]>
Sessions declared image input on every model call. Pi then sends the
model any image its tools return, so on a text-only deployment a task
whose sandbox holds an image failed where the model used to get Pi's
"omitted" note.

A session now declares image input when the prompt has images or when
the new image_input setting is on. Set image_input for a vision model
whose tasks keep their images in the sandbox, such as Harbor tasks,
where the prompt has none.

Signed-off-by: Ananth Subramaniam <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42759938772

@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42760638979

@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42865211667

@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42865618219

This branch was previously deployed

1 inactive deployment
public — e1825538 Deployed Nov 10, 2026 by copy-pr-bot[bot] via release / finalize / notify #11243
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants