Skip to content

feat(env): grant MCP tools of extra tool servers to session agents - #5551

Merged
gwarmstrong merged 3 commits into
NVIDIA-NeMo:mainfrom
gwarmstrong:georgea/env-tool-servers
Nov 8, 2026
Merged

gwarmstrong merged 3 commits into
NVIDIA-NeMo:mainfrom
gwarmstrong:georgea/env-tool-servers

Conversation

@gwarmstrong

@gwarmstrong gwarmstrong commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

  • single_agent_turn gains tool_servers: list[ResourcesServerRef] | None. For each listed Resources server, every episode seeds its own session (/seed_session, with the episode's task data). It grants that server's MCP tools to the agent as a required MCPToolAccess, next to the episode Resources Server's own grants, and closes the session at cleanup.
  • Unset, the setting falls back to the bound agent's tool_servers, now declared on the base agent config with an empty default. A pairing moved off the legacy_agent relay therefore keeps the tool servers its /run seeded, and a harness config can add search without naming generated environment instances.
  • Startup fails if a listed tool server is not configured.
  • As with the Resources Server's own MCP grant, an episode that grants tool-server tools restarts from its input after a crash, because its MCP token names the attempt.
  • Docs: the single_agent_turn README and the "Add or Update a Harness" page.

Why. A session agent got tool grants only from its episode's own Resources Server. The HLE search presets give pi_sandboxed_agent and opencode_sandboxed_agent a Tavily server through tool_servers on their own /run. The Environment Server had no equivalent, so HLE with search had no session path, as pi_sandboxed_agent's deprecation notice from #5222 says. This adds that path. A follow-up updates that notice once the session harnesses can also limit a sandbox's egress to the model and tool servers.

Rebased onto #5142 (seed observations) and #5072 (cross-boundary failures): tool-server seeding uses raise_boundary_failure and dependency_failure(stage="seed"), as the Resources seed does.

Part of #5552. The #5222 deprecation notice records the gap.

Validation

  • pytest environment_servers/single_agent_turn/tests: 182 passed. The six new tool-server tests fail against main's app.py.
  • pytest environment_servers/single_agent_turn_legacy/tests: 43 passed.
  • pytest tests/unit_tests/agents: 266 passed. 3 tests in test_outcome_policy.py import cloudpickle, which this environment lacks; they fail the same way on main.
  • pre-commit run --all-files: clean.

Rollouts

Internal HLE search runs through this path: Nemotron 3.5 Super on vLLM, 5 text tasks each, Gym's Tavily Resources Server as the tool server, on a Gym fork that also carries the egress follow-ups. All 5/5 rollouts completed, graded and healthy for Pi, Codex, OpenClaw and Hermes. The agents called the granted Tavily tools (web_search, find_in_page, scroll_page): Codex in 3 of 5 rollouts, OpenClaw in 3 of 5, Hermes in 4 of 5, and Pi in its run as well.

Compatibility and benchmark impact

Additive. With tool_servers unset and agents declaring none (the default), episodes seed and grant exactly what they did before. The deprecated sandboxed agents keep seeding their own tool_servers on /run. They have no session path, so their tool servers are not seeded twice.

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.
  • Documentation added or updated, or N/A with justification. The single_agent_turn README and the Add or Update a Harness page describe tool_servers.
  • Pre-commit checks pass locally (pre-commit run --all-files).
  • New source files include the required Apache-2.0 SPDX header. N/A: no new source files.
  • All commits have DCO sign-off (git commit -s).

A session agent got tool grants only from its episode's own Resources
server, so the HLE search presets, which add a Tavily server through
tool_servers, had no session path and stayed on the deprecated sandboxed
agents.

single_agent_turn now takes tool_servers: each episode seeds its own
session on every listed Resources server, with the episode's task data,
grants that server's MCP tools as a required MCPToolAccess, and closes
the session at cleanup. Unset, it falls back to the bound agent's
tool_servers, declared on the base agent config, so a pairing moved off
the legacy_agent relay keeps the tool servers its /run seeded, and a
harness overlay can add search without naming generated instances. As
with the Resources server's own MCP grant, an episode that grants one
restarts from its input after a crash.

Signed-off-by: gwarmstrong <[email protected]>
@copy-pr-bot

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

@yaoyu-33

yaoyu-33 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

/ok to test bce30e6

@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 RISK: startup validation accepts tool references that name a different server type. One documentation NOTE clarifies how to disable grants.

I inspected all six changed files and traced the affected configuration, MCP grant, cleanup, and checkpoint paths. I didn't execute tests.

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

# Fail at startup, not on the first episode, when there is no resources server to bind.
self.resources_server_name
for name in self.tool_server_names:
if name not in self.server_client.global_config_dict:

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.

RISK — Validate the referenced server's type at startup

Failure: Configure tool_servers: [{type: resources_servers, name: policy_model}] when policy_model names a Model Server. This membership check passes, so the environment starts and sends /seed_session to the wrong server when episodes run. It should reject this configuration before admitting episodes. The global reference validator checks direct field values, not references inside lists, and URL resolution resolves by name without checking the type. This affects mistyped configurations, not valid search pairings.

Correction: In model_post_init, require every selected name to identify a Resources Server block. Add DictConfig to the OmegaConf import, then replace the loop's membership condition with:

instance = self.server_client.global_config_dict.get(name)
if not isinstance(instance, (dict, DictConfig)) or "resources_servers" not in instance:

Keep the existing ValueError beneath it, preserving the current unknown-name diagnostic. The invariant is that every selected tool server is a configured Resources Server before episodes begin. This suggested code hasn't been executed; please verify it before adopting it.

Preservation and acceptance: Add proposed startup cases for both the explicit environment list and the agent fallback: a name bound to responses_api_models or responses_api_agents must raise ValueError, while a configured Tavily Resources Server must still start. Retain the unknown-name test, the explicit [] override's no-search-call and empty-grant assertions, and the fallback test's successful reward and tavily grant assertions.

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.

Agreed that startup should check this. Two more cases are worth rejecting in the same loop:

  • The episode's own Resources server listed as a tool server, directly or through the agent's list. With resources_tool_transports: [mcp], every episode fails at agent seed on duplicate grant names. Without mcp, the agent's MCP tools act on a second session that /verify never reads.
  • A Resources server without expose_tools_over_mcp: true, which defaults to false. Today every episode then fails with "did not return requested MCP metadata", and that message does not name the flag.

The first case, for example:

if name == self.resources_server_name:
    raise ValueError(
        f"Environment Server {self.config.name!r} lists its Resources server {name!r} as a tool server; "
        "grant its tools with resources_tool_transports: [mcp] instead"
    )

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3ccc6c4. model_post_init now rejects, for both the Environment Server's list and the agent fallback: a name that is not a Resources server (a Model Server or an Agent Server), the episode's own Resources server (pointing to resources_tool_transports: [mcp]), and a Resources server without expose_tools_over_mcp: true, naming the flag. The unknown-name error is unchanged. test_a_server_that_grants_tools_no_resources_server_serves_does_not_start covers the four cases for both sources (8 cases, all fail with the previous check), and test_a_server_that_grants_an_mcp_resources_servers_tools_starts checks that a Tavily server with the flag still starts from either source. The [] override and fallback tests are unchanged. Every shipped tool_servers target (the HLE and HLE Diamond search presets) already sets the flag.

@@ -32,6 +32,16 @@ environment_servers:

`direct_http` grants the Agent Server scoped HTTP access to the Resources Server. `mcp` requires the Resources seed response to provide HTTP MCP connection metadata. Selecting neither transport sends `tool_accesses=[]` when the agent session is seeded.

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.

NOTE — Suggest distinguishing Resources transports from additional tool-server grants

With resources_tool_transports: [] and a configured tool_servers entry, this paragraph promises tool_accesses=[], but _seed_agent intentionally includes the additional server's required MCP grant. Users following this statement to disable grants would leave those grants enabled.

Replace the paragraph with:

Suggested change
`direct_http` grants the Agent Server scoped HTTP access to the Resources Server. `mcp` requires the Resources seed response to provide HTTP MCP connection metadata. Selecting neither transport sends `tool_accesses=[]` when the agent session is seeded.
`direct_http` grants the Agent Server scoped HTTP access to the Resources Server. `mcp` requires the Resources seed response to provide HTTP MCP connection metadata. Selecting neither transport grants no tools from the episode's Resources Server; `tool_servers` can still add MCP grants. When neither source adds a grant, the Environment Server sends `tool_accesses=[]` when the agent session is seeded.

This is documentation-only; preserve both independent grant sources. Acceptance is a static comparison with _seed_agent: empty transports plus a configured search server still produce its MCP grant, while empty transports with no tool servers produce []. Retain the existing fallback test's single-grant and access.name == "tavily" assertions.

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.

+1. Lines 4 and 14 also still say the server seeds and closes "both sessions". They could mention the tool-server sessions too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3ccc6c4: took the suggested paragraph, and lines 4 and 14 now say the server seeds the Resources and agent sessions plus one per tool server, and closes every session it seeded. The tool_servers paragraph also lists the new startup checks.

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

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

Thanks for this. It gives HLE with search a session path, and the default path is unchanged: with no tool_servers on the Environment Server or the agent, episodes seed, grant and close as they do on main.

Verdict: SHIP WITH CARE. There is one RISK, inline: three tests in other servers' suites now fail. We also added to the two existing threads on the startup check and on the README.

What we checked in the areas this feature touches:

  • Grant and teardown. Every session ID is assigned, and its close registered, before any seed. A partial seed therefore still closes every session. Cleanup runs agent, then tool sessions, then the Resources session. A failed tool-session close is reported as session_release_failed and leaves the result unchanged.
  • Tool server down. A connection error or a 503 at seed is a retryable stage="seed" failure; a 422 is terminal. Either way the agent is never seeded. This matches a down Resources Server on main.
  • Name collisions. Each grant is named after its server's instance name, so two different servers cannot collide. The one collision case is listing the episode's own Resources server (see the startup-check thread).
  • Cookies. Each tool session keeps its own seed cookies for its close. The agent reaches the tool server with the MCP token header, as it does for the Resources Server's own MCP grant.

PR hygiene

  • The rollouts ran on a fork that also carries the egress follow-ups. None of them used OpenCode, which replaces the deprecated agent in three of the five HLE search presets. Could you confirm that the fork's extra commits do not touch single_agent_turn/app.py or how the grants are built? An OpenCode HLE-search smoke run on this head would also answer it.

super().model_post_init(context)
# Fail at startup, not on the first episode, when there is no resources server to bind.
self.resources_server_name
for name in self.tool_server_names:

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.

environment_servers/single_agent_turn/app.py:148

RISK. model_post_init now reads the bound agent's config through tool_server_names, even when resources_server is set. Three tests that build this server from a bare client now fail; they pass on the merge base, and because this PR touches nemo_gym/, CI runs the full server suite:

Could you pass tool_servers=[] in those two constructors, as you did in single_agent_turn_legacy/tests/test_app.py:202?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching these. Both constructors now pass tool_servers=[] in 3ccc6c4. partner_if_dispatcher/tests/test_app.py passes (20), and so does test_swe_shared_preparation_preserves_grading_metadata_through_legacy_adapter. The other test in nooa_agent/tests/test_recipe.py needs the nooa package, which my local venv does not have, so CI will be the check for that one.

Startup now also rejects a tool server that is not a Resources server, the
episode's own Resources server, and a Resources server without
expose_tools_over_mcp, each of which otherwise failed every episode.

The partner_if_dispatcher and nooa_agent tests build this server from a bare
client, so they now pass tool_servers=[] instead of reading their agent's.
The README separates the Resources transports from tool-server grants and
says every seeded session is closed.

Signed-off-by: gwarmstrong <[email protected]>
@gwarmstrong

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Fixes are in 3ccc6c4.

On the fork question: I checked, and the only commit on that fork that touches single_agent_turn/, single_agent_turn_legacy/, base_responses_api_agent.py or nemo_gym/environment/ is this PR's own commit, from before the rebase onto #5072 (which only swapped in raise_boundary_failure and dependency_failure(stage="seed")). The egress and OpenCode commits there do not touch the grant path. I will also run an OpenCode HLE-search smoke on this head and post the result here.

Local checks at 3ccc6c4: single_agent_turn 192 passed, single_agent_turn_legacy 43 passed, partner_if_dispatcher 20 passed, pre-commit on the changed files passes.

@gwarmstrong

Copy link
Copy Markdown
Contributor Author

OpenCode HLE-with-search smoke, as promised. This PR alone has no session-harness profile, so it ran on a2b3513, a merge of this head (3ccc6c4) and #5550's head (c394bcb) with no other changes: 5 HLE tasks, Nemotron 3.5 Super on vLLM, OpenSandbox, opencode_agent with tool_servers: [tavily] on the agent and none on the Environment Server.

Slurm 8604094: 5/5 completed and healthy, failures sidecar empty, observations on every rollout. The Environment Server took the agent's tool_servers through the fallback, and every episode was seeded with the Tavily MCP grant. Episodes used the granted tools (47 tavily_web_search calls, 1 tavily_find_in_page), with no errors in the Tavily server's log and no cleanup errors in any server log.

@gwarmstrong

Copy link
Copy Markdown
Contributor Author

/ok to test 3ccc6c4

NVIDIA-NeMo#5108 made the Environment Server's resources_server required again and
dropped the fallback to the agent's. The startup check for tool servers
now compares against the configured resources_server; the agent fallback
for tool_servers stays.

Signed-off-by: gwarmstrong <[email protected]>
@gwarmstrong

Copy link
Copy Markdown
Contributor Author

/ok to test 6206266

@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Nov 5, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 6, 2026 22:06
@svcnvidia-nemo-ci svcnvidia-nemo-ci added feature New capabilities, enhancements, or enablement work area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers needs-review PR is ready for code review and waiting on a reviewer labels Nov 7, 2026
@gwarmstrong
gwarmstrong added this pull request to the merge queue Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

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

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 7, 2026
@gwarmstrong
gwarmstrong added this pull request to the merge queue Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

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

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 8, 2026
@gwarmstrong
gwarmstrong added this pull request to the merge queue Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

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

Merged via the queue into NVIDIA-NeMo:main with commit 7a2b745 Nov 8, 2026
65 of 68 checks passed
@gwarmstrong
gwarmstrong deleted the georgea/env-tool-servers branch November 8, 2026 05:10
rimashahbazyan added a commit that referenced this pull request Nov 9, 2026
…ools

Brings in 42 commits from main (bd6f5f0..363af5e), including #5709
(centralized resources lifecycle and verification ownership), #5551 (MCP
tools of extra tool servers granted to session agents), #5763 (HLE agent
loop bounded with max_steps 1) and #5446 (gym list environments).

Only README.md overlapped textually; the environment table was
regenerated with scripts/update_env_list.py and the Hle Web Tools row is
preserved.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>

This branch was previously deployed

1 inactive deployment
public — 6206266d Deployed Nov 4, 2026 by copy-pr-bot[bot] via release / finalize / notify #10060
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer 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.

3 participants