Skip to content

feat(stirrup_agent): add a view_image tool and keep images in the exported trajectory - #5806

Closed
d-molinari wants to merge 1 commit into
mainfrom
dmolinari/stirrup-view-image
Closed

d-molinari wants to merge 1 commit into
mainfrom
dmolinari/stirrup-view-image

Conversation

@d-molinari

Copy link
Copy Markdown
Contributor

What does this PR do?

Lets a Stirrup run show the model an image file from its workspace, and keeps images in the trajectory Gym exports.

view_image (new option, off by default). The in-sandbox runner never offered a tool that reads an image: LocalShell.view_image existed, but nothing used it. With view_image: true, the model gets Stirrup's own view_image tool on the working directory. Stirrup answers with 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. A missing file, or one that is not an image, is a failed call that says why, and no image reaches the model.

The trajectory export (convert_stirrup_history_to_output_items) lost images, and reordered messages:

  • A tool result with list content became str(list), so an image block turned into its Python repr.
  • A user message's parts were joined as text, so an initial input_image became str(ImageContentBlock).
  • Every user message went to the input items, so the ones Stirrup adds during a run (the image after a view_image call, a turn warning) left their place in the conversation.

Now:

  • An image is an input_image part holding the data URL the model was sent (the same to_base64_url call, so the same bytes).
  • User messages after the model's first turn are output items, in order.
  • Text-only list content is joined with newlines.

Validation

  • tests/test_images.py (9 tests) covers:
    • an image in the row, and one after a view_image call;
    • two images, over two turns and in one turn;
    • a missing file and a file that is no image;
    • a large image downscaled, and the option off;
    • a trajectory with images that validates as a response and as an observation.
  • The stub model server records each request, so the tests compare the pixels the model was sent with the file, and the trajectory's data URL with the request's. On main's Stirrup code, 8 of the 9 fail.
  • gym env test +entrypoint=responses_api_agents/stirrup_agent: 185 passed (176 before this PR, plus the 9 new).
  • pre-commit and detect-secrets pass on the changed files, and the commit is signed off.

Rollouts

One episode in a vision RL lab, with a vision-language policy served by NeMo RL's vLLM worker. Stirrup ran in a Docker sandbox, and the task needed an image the episode saved in the workspace. The model called view_image and solved the task (reward 1.0). The image's bytes matched at every hop: Stirrup's re-encode of the file, each model call after view_image, the trajectory's input_image, and the pixels in NeMo RL's training row.

Compatibility and benchmark impact

  • view_image defaults to off, so the model's tools are unchanged unless a config turns it on.
  • The export changes for every Stirrup run in three ways:
    • user messages that Stirrup adds during a run move from the input items to the output items, in order;
    • images are kept as images;
    • text-only list content becomes newline-joined text instead of a list repr.
  • A run whose message contents are plain strings, and whose user messages all come before the model's first turn, exports as before.

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, or N/A: the option's description documents it.
  • 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

…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.

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]>
@copy-pr-bot

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

Folded into #6972 with #5835 and #5545, rebased onto main; view_image and the image-keeping export are unchanged apart from keeping main's reasoning items. Closing.

@d-molinari d-molinari closed this Nov 30, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants