Skip to content

feat: images in tool replies, a lent-sandbox helper and OpenCode session limits for multi-harness training - #5719

Merged
yfw merged 23 commits into
mainfrom
yifuw/multi-harness-core
Nov 10, 2026
Merged

yfw merged 23 commits into
mainfrom
yifuw/multi-harness-core

Conversation

@yfw

@yfw yfw commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Core pieces that let one environment run with several agent harnesses (simple_agent, OpenCode, or the environment's own agent) through agent sessions, for eval and RL training. They came from moving Agentic-MME onto the Environment Server (#5720, stacked on this PR).

  1. Images in tool replies (nemo_gym.core.tool_output_images). A resources-server tool can return images under tool_output_images. The MCP layer sends them as MCP image content, and simple_agent shows them to the model in a user message after the tool outputs. A result with images carries no structuredContent unless the tool declares an output schema, because OpenCode replaces the content with structuredContent and would drop the images. Each image is checked as prompt images are (MediaFile): valid base64 of a PNG, JPEG, GIF or WebP image.
  2. LentSandboxes (nemo_gym.server_runtime.sandbox_lending). A helper for a resources server that lends a per-episode sandbox to the harness: start it at seed (with optional files), describe it as SandboxAccess, stop it at close and at shutdown. A seed cancelled during file delivery still stops its sandbox, and a failed seed whose stop fails is kept so that close or shutdown can stop it. network_access gives the lent sandbox the same egress rules an agent-owned sandbox gets: "model_only" denies all but the model server, and "model_and_tools" also allows the servers in tool_servers, such as the resources server that serves the harness its tools over MCP. restricted_network_policy moves to nemo_gym.utils.network_policy; nemo_gym.agents still exports it.
  3. OpenCode session settings (opencode_agent).

Stack. #4917 and #4922 are merged; this PR is based on main. #5833 is independent. #5716 changes the same OpenCode settings with a different interface; only one of the two should land.

Compatibility

  • Tool replies and MCP results without images are unchanged.
  • Existing opencode_agent configs behave as before, except one default: close returns OpenCode's own turns (return_session_trajectory: false restores the old behavior; training data does not change).
  • Codex sends MCP tool images as input_image parts of the tool output; vllm_model needs inline_tool_output_images: true to accept them.

Validation

  • New unit tests cover each change: tool images (core, MCP, simple_agent), LentSandboxes (including the model-only network), and the OpenCode session settings and defaults. On feat(opencode): attach prompt images in agent sessions #4922's head 49324d1 (the same tree as main after feat(opencode): attach prompt images in agent sessions #4922 merged), the opencode_agent, simple_agent, server runtime, sandbox, core and session contract tests pass (4,850 passed, 31 skipped), and pre-commit passes on the changed files.
  • Eval on Agentic-MME (418 tasks × 2): simple_agent with the server's image tools 36.1% (the environment's own agent 34.9%), OpenCode with the same tools over MCP 36.5%.
  • An earlier version of these changes ran NeMo-RL GRPO through the Environment Server with OpenCode and the fix(token_capture): keep capture chains through OpenCode's step-limit note and tool-name repair #5833 fixes, for 22 and 30 steps, with reward close to the environment's own agent. BabyVision on a model-only lent sandbox: eval 6/6; from inside the sandbox an internet host did not resolve and the model server answered.
  • A 10-row Agentic-MME retest after model_and_tools was added (before the latest feat(opencode): attach prompt images in agent sessions #4922 rebase): both OpenCode configurations completed 10/10 with none masked, in line with the earlier rates. From inside the sandbox, model_and_tools reached the resources server's MCP route, and neither setting reached the internet.

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 (opencode_agent README, the harness guide, the MCP Resources Server page).
  • Pre-commit checks pass locally (pre-commit run --all-files).
  • New source files include the required Apache-2.0 SPDX header.
  • All commits have DCO sign-off (git commit -s).

🤖 Generated with Claude Code

@copy-pr-bot

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

@yfw yfw added area:agent Agent harnesses and Responses API agent behavior area:core Shared APIs, servers, telemetry, health, and registries feature New capabilities, enhancements, or enablement work labels Nov 6, 2026
@yfw

yfw commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test f22f699

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

@yfw

yfw commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test dda0bb5

yfw added a commit that referenced this pull request Nov 7, 2026
This branch carried copies of the #5719 commits, so GitHub saw the opencode_agent README
change twice and marked the PR as conflicting with its base, and no checks ran. Merging the
base makes those commits ancestors. The README keeps this branch's text, which already has
both the prompt-image paragraph and the max_output_tokens rule.

Tests on the merged tree: opencode_agent and simple_agent 984 passed, agentic_mme 119
passed, agentic_mme_agent 85 passed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
@yfw

yfw commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test af3c63b

@yfw

yfw commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 1132d70

@yfw

yfw commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 5e12790

yfw and others added 4 commits November 9, 2026 17:25
…, and drop agentic_if's copy of the default

The opencode_agent config's comment now says what false costs: one turn per captured call, so evidence checks report
every call as unmatched, and compaction summaries count as steps. agentic_if set the same value as the new default,
so its line goes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
…imit, as OpenCode does

reached_step_limit() took the last user message as the prompt and counted the assistant messages after it. An
automatic compaction adds user messages (the compaction marker, then a synthetic "Continue" text or a replay of the
prompt), so the count restarted after a compaction, and a prompt that reached the limit was not marked.

OpenCode 1.17.11's session loop (session/prompt.ts) counts passes: each build call, each compaction summary call,
and a pass that only starts a compaction after a finished call overflowed (session/compaction.ts saves its marker
without an overflow field). The counter is not reset by compaction. The check now skips the user messages that
compaction adds when it finds the prompt, and counts those passes.

Tests: five exports in OpenCode's message shapes, the overflow-pass and in-call compaction paths, a compaction with
no continuing message, and a new prompt after a compacted one. Four fail on the old count. The README says how the
limit is counted and when token capture allows it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
…livery, and keep a failed seed's stop for retry

Two cleanup gaps in LentSandboxes.lend():

- A seed cancelled while the new sandbox received its files left the sandbox running. AsyncSandbox.start() stops
  the sandbox when an upload fails, but that stop is not shielded, so it is cancelled with the request. lend() now
  runs start() inside its own failure path, whose shielded, bounded _stop() finishes the stop; after a stop that
  did finish, _stop() does nothing.
- When a failed seed's stop failed or timed out, the sandbox was dropped, so no close or shutdown could stop it.
  It is now kept apart from the lent sandboxes: get() never returns it, release() and release_all() retry its stop,
  and the session's next lend stops it before it starts another sandbox (a failed stop there fails the lend).

Tests: a seed cancelled during upload_file() with the real AsyncSandbox.start() and a provider close that crosses an
AnyIO checkpoint; a failed seed whose first stop fails or hangs, stopped later by release() or release_all(); a
repeated seed that stops the earlier sandbox first, and one that fails while that stop still fails. The seven new
tests fail without the fix. test_sandbox_lending.py and tests/unit_tests/sandbox: 2028 passed, 8 skipped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
…nd when token capture allows the step limit

The harness guide's OpenCode row now matches the README: a session's opencode_config also accepts attachment (from
#4922), and agent.build.steps works with token capture once the harness notes know OpenCode's step-limit message.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
@yfw

yfw commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 0447cf5

@yfw

yfw commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. Done, and one step further now that #4922 has merged: #5719 is rebased onto main (0447cf5) and shows only its own 22 commits.

@yfw

yfw commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

/review

@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

One prior RISK remains: OpenCode accepts a response token budget but enforces only a per-call limit.

I verified three earlier findings are fixed in the current source:

This was a static follow-up of the prior findings and identifiable corrections, not a fresh whole-PR review. I didn't run tests. The previously reviewed tree isn't mounted, so I couldn't independently compare the inter-review source delta or establish additional introduced regressions.

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

…h model call, not the session's sum

Gym agents read a request's max_output_tokens as the limit for each model call (simple_agent copies it into every
call), and NeMo RL sets it on every row as its generation limit. The README and the code comment now say so, and that
nothing limits the sum over a session's calls, as in simple_agent. No behavior changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
@yfw

yfw commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 90534f7

@yfw

yfw commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

/review

@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

One prior RISK remains: OpenCode accepts a response token budget but enforces only a per-call limit. The revised documentation describes that behavior; it doesn't resolve the earlier counterexample.

I confirmed that the previously acknowledged fixes remain in the current source:

This was a static follow-up of the latest bot review, the documentation/comment changes since its mounted baseline, and their directly affected contracts—not a fresh whole-PR review. I didn't execute tests or independently verify the reported rollout results.

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

@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/42761551132

@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/42763299259

@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/42768126306

@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/42771357435

This branch was previously deployed

1 inactive deployment
public — 90534f7d Deployed Nov 10, 2026 by copy-pr-bot[bot] via release / finalize / notify #11276
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 area:core Shared APIs, servers, telemetry, health, and registries feature New capabilities, enhancements, or enablement work ready-to-merge PR is approved, current, and waiting for final CI or merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants