Repository navigation
feat(pi): attach prompt images in agent sessions - #4923
Conversation
ee4fdd0 to
bc4afe4
Compare
9e494d7 to
4531aff
Compare
a2aaa80 to
ee03142
Compare
4531aff to
39d73d2
Compare
yaoyu-33
left a comment
There was a problem hiding this comment.
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.
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]>
4c13057 to
13778ec
Compare
|
@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 Smoke runs on 30f62b3 with Qwen3-VL-30B-A3B-Instruct:
If #4922 adopts the same rule, using the setting name |
|
sg |
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]>
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42759938772 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42760638979 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42865211667 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42865618219 |
Where this sits
The base branch is
main, which now has #4917 (sandbox bytes, media decoding innemo_gym.core, and content-named media staging innemo_gym.sandbox), #4934 (sandbox transfer telemetry) and #5862 (activation staging inside the close fence).Each arrow points from a PR to its base. #4922 and #4923 can merge in either order.
What changed
pi_agentsandbox sessions now pass prompt images to Pi, and Pi now passes images it reads in the sandbox to the model.input_imageparts in the user prompt. The adapter stages each image at/tmp/nemo-gym-media/<sha256>.<extension>withnemo_gym.sandbox.stage_mediaand 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.SandboxUnavailableErrorwhen the provider cannot run a staging command, including when that command times out, andSandboxTransferErrorwhen the command fails inside the sandbox. Only the activation's own deadline reports as aTimeoutError.models.jsondeclares the Gym model withinput: ["text", "image"]when the prompt has images or the newimage_inputsetting is on, and keepsinput: ["text"]otherwise. Withinput: ["text"], Pi replaces every image with the note "Current model does not support images. The image will be omitted from this request.", including images itsreadtool returns, so a text-only deployment keeps working. Setimage_input: truefor 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.images.autoResizetofalsein Pi'ssettings.json. Pi otherwise resizes images larger than 2000 by 2000 pixels or 4.5 MB once base64-encoded, both prompt images and images itsreadtool 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.nemo_gym.core.split_text_and_mediaand staging usesnemo_gym.sandbox.stage_media, both from feat: binary sandbox files and shared media helpers #4917.The local
/runpath andpi_sandboxed_agentare unchanged.Why
Multimodal tasks put images in the prompt as
input_imageparts, 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"]unlessimage_inputis set, so text-only deployments behave as before. Withimage_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.@filearguments, including after a system message, and thatmodels.jsondeclares 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.image_inputis set, and the image tests check that a prompt with images declares it either way.settings.jsonturns off image resizing, and another that a retried image activation decodes its images once and launches Pi once.mainafter 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, thenprompt.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 ontomain, with Qwen3-VL-30B-A3B-Instruct on vLLM 0.29.0 (default sampling), Pi 0.80.2 (the configured version) in Docker sandboxes, driven throughsingle_agent_turn_legacyso each row runs as an agent session, and graded bymcqa(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.readtool from files in the sandbox, withimage_input: true: 6 of 6 correct, withreadcalled for every image. This dataset has no prompt images, so staging does not touch it.0f0c6c09f1and9d33b8bfe9scored 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 thereadresult, so those were misreadings.pi_sandboxed_agentwithinput: ["text"]: Pi returned the "omitted" note for every image, and only the text control and one guess were correct.