Repository navigation
feat(env): grant MCP tools of extra tool servers to session agents - #5551
Conversation
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]>
|
/ok to test bce30e6 |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. Withoutmcp, the agent's MCP tools act on a second session that/verifynever 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"
)There was a problem hiding this comment.
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. | |||
There was a problem hiding this comment.
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:
| `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.
There was a problem hiding this comment.
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.
yaoyu-33
left a comment
There was a problem hiding this comment.
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_failedand 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.pyor 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: |
There was a problem hiding this comment.
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:
partner_if_dispatcher/tests/test_app.py:96:test_routes_the_complete_episode_without_rewriting_native_fields[text]and[tools](ConfigKeyError: Missing key agent-text)nooa_agent/tests/test_recipe.py:47:test_swe_shared_preparation_preserves_grading_metadata_through_legacy_adapter(Mock object has no attribute 'global_config_dict')
Could you pass tool_servers=[] in those two constructors, as you did in single_agent_turn_legacy/tests/test_app.py:202?
There was a problem hiding this comment.
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]>
|
Thanks for the review. Fixes are in 3ccc6c4. On the fork question: I checked, and the only commit on that fork that touches Local checks at 3ccc6c4: |
|
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, Slurm 8604094: 5/5 completed and healthy, failures sidecar empty, observations on every rollout. The Environment Server took the agent's |
|
/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]>
|
/ok to test 6206266 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42396365864 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42427175160 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42427686205 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42448712725 |
…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]>
What does this PR do?
single_agent_turngainstool_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 requiredMCPToolAccess, next to the episode Resources Server's own grants, and closes the session at cleanup.tool_servers, now declared on the base agent config with an empty default. A pairing moved off thelegacy_agentrelay therefore keeps the tool servers its/runseeded, and a harness config can add search without naming generated environment instances.single_agent_turnREADME 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_agentandopencode_sandboxed_agenta Tavily server throughtool_serverson their own/run. The Environment Server had no equivalent, so HLE with search had no session path, aspi_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_failureanddependency_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'sapp.py.pytest environment_servers/single_agent_turn_legacy/tests: 43 passed.pytest tests/unit_tests/agents: 266 passed. 3 tests intest_outcome_policy.pyimportcloudpickle, 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_serversunset and agents declaring none (the default), episodes seed and grant exactly what they did before. The deprecated sandboxed agents keep seeding their owntool_serverson/run. They have no session path, so their tool servers are not seeded twice.Checklist
single_agent_turnREADME and the Add or Update a Harness page describetool_servers.pre-commit run --all-files).git commit -s).