Skip to content

cp: feat(config): deprecate agents without an environment server and fix the migration script (3929) into r0.7.0 - #4050

Closed
ananthsub wants to merge 6 commits into
NVIDIA-NeMo:r0.7.0from
ananthsub:cherry-pick-3929-r0.7.0
Closed

ananthsub wants to merge 6 commits into
NVIDIA-NeMo:r0.7.0from
ananthsub:cherry-pick-3929-r0.7.0

Conversation

@ananthsub

@ananthsub ananthsub commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Cherry-picks #3929 into r0.7.0, together with the environment server and migration script changes from #4053.

Since #3724, which is on r0.7.0, config validation rejects any agent that no environment server names, with AgentWithoutEnvironmentServerError. Configs written before environment servers stop loading when users upgrade to this release. #3929 turns that error into a deprecation warning and adds a legacy_agent environment server in front of each such agent, so these configs keep running unchanged. It also lets scripts/add_legacy_agent_environment_servers.py migrate configs outside this repository.

Commits:

  1. The feat(config): deprecate agents without an environment server and fix the migration script #3929 cherry-pick. See feat(config): deprecate agents without an environment server and fix the migration script #3929 for the full description.
  2. to 6. The five commits of feat(config): support environment servers that front several agents #4053, applied unchanged. They make Gym recognize every agent an environment server references, including servers that front several agents such as the usersim server from feat(nemo-user-sim): add materialized-row runtime #3800, which is also going into r0.7.0. They attribute and validate rows of such servers, fix how the migration script handles those servers and agents renamed with _inherit_from, and update the ServerRefNotFoundError rename hint and the troubleshooting docs to match. feat(config): support environment servers that front several agents #4053 includes the change from feat(config): support multi-agent environment server bindings #4059, which it supersedes. See feat(config): support environment servers that front several agents #4053 for the full description.

Conflict resolution

The #3929 cherry-pick conflicted only on the imports in tests/unit_tests/test_global_config.py. On main, that file also imports hide_secrets_in_overrides, which the r0.7.0 version of the file does not use. The resolution keeps the release branch's import and adds the _environment_servers_by_agent import that the new tests need. The #4053 commits applied cleanly and match #4053.

Validation

Rollouts

N/A for the cherry-pick itself. The #3929 code is unchanged, and #3929 includes rollout evidence for example_single_tool_call with its environment server block removed. The #4053 commits leave single-agent environment servers unchanged; see #4053.

Compatibility and benchmark impact

Same as #3929 and #4053. Configs that failed with AgentWithoutEnvironmentServerError now load and log a deprecation warning. Results do not change. Setting error_on_agent_without_environment_server: true restores the error. No benchmark impact.

…the migration script (NVIDIA-NeMo#3929)

Since NVIDIA-NeMo#3724, config validation rejects any agent that no environment
server names, with `AgentWithoutEnvironmentServerError`. A config
written before environment servers therefore stops loading when Gym is
upgraded. This also affects configs in this repository:
`resources_servers/wordle/configs/wordle.yaml` and
`environments/wordle/config.yaml` fail to parse on `main`.

This PR turns that error into a deprecation, so these configs keep
running while users migrate. It also fixes the migration script so it
can update configs outside this repository.

During config parsing, Gym finds each agent that no environment server
names. For each one, it adds a `legacy_agent` environment server in
front of the agent. A `legacy_agent` server relays `/run` to its agent
unchanged, so rollouts and results are the same as before. Gym then logs
one deprecation warning:

```
DEPRECATED: agents without an environment server: `workplace_assistant_simple_agent`.
Rollout collection reaches an agent only through an environment server.
This run generated a legacy_agent environment server for each agent above.
Each one relays /run to its agent unchanged, so results are not affected.
A future release will reject these configs with AgentWithoutEnvironmentServerError.

To migrate, declare the environment servers in your config. Either:

1. Run the migration script from a NeMo Gym checkout on your config files or directories:

     python scripts/add_legacy_agent_environment_servers.py path/to/config.yaml [more paths] [--check]

   --check reports what would change without writing.

2. Or add these blocks yourself, at the same level as the agents:

     workplace_assistant_environment_server:
       environment_servers:
         legacy_agent:
           entrypoint: app.py
           agent_server:
             type: responses_api_agents
             name: workplace_assistant_simple_agent

To make this an error now, set error_on_agent_without_environment_server: true in your config.
You can also pass +error_on_agent_without_environment_server=true on the command line.
```

- The generated server is named the way the migration script names it:
the agent type is stripped from the agent name. For example,
`workplace_assistant_simple_agent` gets
`workplace_assistant_environment_server`. The block in the warning is
therefore the block the script writes. If that name is already taken,
the server is named `<agent>_environment_server` instead.
- Gym only adds a server for an agent that has none. An agent with an
existing environment server is left alone, so the new server can never
make agent routing ambiguous.
- Setting `error_on_agent_without_environment_server: true` restores the
error. It follows the existing `error_on_almost_servers` switch. The
error message now also points at the migration script.
- Renaming an agent with `_inherit_from` moves it to the new name. An
environment server that named the old agent is then left pointing at an
agent that no longer exists, and parsing fails with
`ServerRefNotFoundError`. That error now says the environment server
must be renamed with the agent, and points at the script.

The test this PR replaces explained why the error existed: without it, a
config written before environment servers "would otherwise run, silently
dispatching straight to the agent." The generated server keeps that
guarantee. Rollout collection still reaches the agent only through an
environment server, and the warning names every server Gym added.

- The script now accepts config files and directories as arguments.
Before, it could only update this repository's configs, so users had no
way to migrate their own. Run without arguments, it still updates this
repository's configs.
- The script now skips an agent that any environment server already
names. Before, it only checked whether a server with the generated name
existed. In `benchmarks/swebench/pro/hermes.yaml`, a
`single_agent_turn_legacy` server already fronts the agent under a
different name, so the script added a second server. Two servers in
front of one agent make agent routing ambiguous, and rollout collection
then fails.
- The script now handles an agent that only renames another one, such as
`renamed_agent: {_inherit_from: some_agent}`. Before, such configs were
skipped because the new instance has no agent body of its own. The
script now writes a server for the new name that inherits the original
agent's server. Because `_inherit_from` moves the original server, the
renamed agent ends up with exactly one server.
- A config that cannot be read or parsed is now reported, and the script
exits with 2. Before, such files were skipped without any message.

`test_langchain_deepagents_configs_have_environment_servers` now parses
with `error_on_agent_without_environment_server: true`. The test checks
that in-repo configs declare their environment server. A generated
server would have the same name, so without strict mode the test would
pass even when the declaration is missing.

The script's `--check` mode reports six configs on `main` that declare
no environment server: two `wordle` configs, two `swemer_oml` configs,
and two `swe_internal_v1` configs. With this PR they load with the
deprecation warning. Migrating them is left to their owners.

No issue is linked. This is a compatibility follow-up to NVIDIA-NeMo#3724.

- `pytest tests/unit_tests/test_global_config.py`, covering the
generated server, its name, the warning text, strict mode, an agent that
already has a server, a name collision, a full `parse()` of a config
without environment servers, and the rename hint on
`ServerRefNotFoundError`.
- `pytest tests/unit_tests/test_add_legacy_agent_environment_servers.py`
(new), covering configs outside the repository, `--check` not writing,
an agent that already has a server, a rename through `_inherit_from`, an
unreadable config, and that the script and Gym name servers the same
way. The behavior tests fail against the script on `main`.
- Six configs outside this repository that failed validation were
migrated with the script, covering both added agents and `_inherit_from`
renames. Each migrated config was then parsed with
`GlobalConfigDictParser` and `error_on_agent_without_environment_server:
true`. An unmigrated copy, parsed the same way, raised
`AgentWithoutEnvironmentServerError`.
- `pytest tests/unit_tests/test_rollout_collection.py
tests/unit_tests/test_environment_scaffold.py`.
- `pytest tests/unit_tests`. The tests that fail in this environment
fail identically on `main`. They need the `sandbox` extra, or `mlflow`
and `wandb`, which NVIDIA-NeMo#3547 moved into extras.
- `pre-commit run --all-files`.

`example_single_tool_call` was run with its environment server block
removed from the config, against `Qwen/Qwen3-0.6B` served by a local
vLLM with the hermes tool parser:

- `gym env start` logged the deprecation warning and started the
generated environment server alongside the agent, the resources server,
and the model server.
- `gym eval run --no-serve` completed every requested rollout without
failures. Each record has the generated server in
`_ng_environment_server` and `legacy_agent` in `_ng_result_type`.
- When the model called `get_weather`, the verifier scored the rollout
1.0. When it answered in prose without calling the tool, the verifier
scored it 0.0.

Dispatch through the generated server has not changed since that run.
Only the server's name and the warning text have.

- Configs that failed with `AgentWithoutEnvironmentServerError` now load
and log a deprecation warning. Results do not change, because
`legacy_agent` relays `/run` to the agent unchanged.
- Users who want the error back can set
`error_on_agent_without_environment_server: true`. The warning tells
users that a future release will make this the default.
- No benchmark impact.

Proposed labels: `feature`, `area:config`.

- [x] I have read the [contributing
guidelines](https://github.com/NVIDIA-NeMo/Gym/blob/main/CONTRIBUTING.md).
- [x] The change is focused; unrelated "drive-by" edits are tracked as
separate issues/PRs.
- [x] Tests added or updated and pass locally, or N/A for docs-only /
non-code changes (so CI unit/server checks pass when applicable).
- [x] Documentation added or updated, or N/A with justification.
- [x] Pre-commit checks pass locally (`pre-commit run --all-files`) (so
CI lint/format checks pass).
- [x] New source files include the required Apache-2.0 SPDX header.
- [x] All commits have DCO sign-off (`git commit -s`) (so the DCO check
passes).


---------

Signed-off-by: Ananth Subramaniam <[email protected]>
(cherry picked from commit 1f2446c)
Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub ananthsub added feature New capabilities, enhancements, or enablement work area:config Hydra configuration, schemas, composition, and compatibility labels Oct 5, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 5, 2026 13:27
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

@yaoyu-33 yaoyu-33 added complexity:medium Single-domain change with interacting parts or a moderate review surface needs-review PR is ready for code review and waiting on a reviewer labels Oct 5, 2026
@ananthsub
ananthsub requested a review from marta-sd October 5, 2026 15:51
agent_types.update(agent_types_in(document, agent_types))
servers: dict[str, str] = {}
for document in documents:
servers.update(server_names_for(document, agent_types))

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.

Could we index the actual environment-server name and type from its agent_server binding? For a renamed agent, this currently guesses a nonexistent source when the existing relay has a custom name (InheritPathNotFoundError). Even with the expected name, a single_agent_turn_legacy source gains an extra legacy_agent block and fails with AlmostServerError. Both reproduced; migration → parse tests would cover these cases.

… renamed agent

For an agent renamed with `_inherit_from`, the migration script wrote a server
that inherits from the name it would generate for the source agent, as a
`legacy_agent` relay. It ignored the server actually declared in front of the
source. Two cases then failed to parse:

- The source's server has a custom name: the inherited name does not exist,
  raising InheritPathNotFoundError.
- The source's server is `single_agent_turn_legacy`: the inherited server gains
  a second `legacy_agent` block without an entrypoint, raising AlmostServerError.

The script now indexes each declared server's name and type from its
`agent_server` binding and inherits that server, keeping its type. It falls back
to the generated name only for agents the script fronts itself. When the
renamed agent's server name equals the source's, the script points that server
at the new name instead of inheriting it.

Signed-off-by: Ananth Subramaniam <[email protected]>
…agents

The migration script assumed an environment server references one agent,
through `agent_server`. An environment server can reference several agents,
such as the user and assistant agents of a user-simulation server, through any
field whose value has `type: responses_api_agents`. The script missed those
references, so it:

- added a `legacy_agent` relay in front of agents such a server already
  fronts, making their routing ambiguous;
- wrote an agent rename into `agent_server`, a field such a server does not
  use.

The script now finds every agent reference by the same rule Gym uses, and
treats each referenced agent as fronted.

For an agent renamed with `_inherit_from`, every declared reference to the
source agent now points at the new name, on the existing server. The server
keeps its name, so `environment_server_routes` and the server's other agents
are unaffected. Renaming several agents of one server writes one block for
that server. Before, the renamed agent got a new server inheriting the source's
server, which retired the server name that routes may use.

An agent whose only server is the one the script generates keeps the previous
behavior: the renamed agent's server inherits the generated one.

A rename in the same file as a server that references its source cannot be
migrated by appending, because the server's key would repeat. The script
reports the field to update by hand and exits with 2.

Signed-off-by: Ananth Subramaniam <[email protected]>
…ent field

When an environment server references an agent that no longer exists,
ServerRefNotFoundError suggests the agent may have been renamed with
`_inherit_from`. The hint said the environment server "must be renamed with
it", but the migration script now keeps the server's name and points its
reference at the new name, so `environment_server_routes` still resolve.

The hint now says the server must reference the agent's new name, and names
the field to update instead of always `agent_server.name`. It is also shown
for any agent reference on an environment server, such as the `user_agent` of
a server that fronts several agents, not only `agent_server`.

The troubleshooting page describes the same rename behavior and the script's
exit code 2 for a rename that needs a manual update.

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

copy-pr-bot Bot commented Oct 5, 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.

ffrujeri and others added 2 commits October 5, 2026 12:05
…ervers

The previous commit makes Gym recognize every agent an environment server
references. Two places in rollout collection still read only `agent_server`:

- `_agent_name_for_row` names the agent a row's results are attributed to.
  It decides token-ID capture and labels aggregate metrics. A server that
  referenced its only agent through another field got no agent.
- `_validate_environment_servers` rejects a row whose `agent_ref` names an
  agent the server does not front. It skipped the check for any server
  without `agent_server`.

Results are now attributed to the server's `agent_server`, or to the only
agent it references. A server that fronts several agents without an
`agent_server` still has no single agent to attribute, as before. A row may
name any agent its environment server references.

`environment_server_agent_refs` takes and returns `DictConfig`, which every
caller passes, and its docstring states the rule. The
`_retarget_environment_servers` docstring no longer says only `agent_server`
follows a swap. New tests cover a composition swap on a multi-agent server,
attribution, and row validation. The migration script's multi-agent rename
test now parses in strict mode, and a test checks that the script's copy of
the rule matches Gym's.

Signed-off-by: Ananth Subramaniam <[email protected]>
ananthsub added a commit to ananthsub/Gym that referenced this pull request Oct 6, 2026
…VIDIA-NeMo#4053)

## What does this PR do?

Makes Gym and its migration tooling agree on which agents an environment
server fronts, including servers that front several agents. It combines
the runtime change from NVIDIA-NeMo#4059 with fixes to
`scripts/add_legacy_agent_environment_servers.py`, the
`ServerRefNotFoundError` rename hint, and the troubleshooting docs, so
the environment server and agent server changes land together. The same
commits are in the `r0.7.0` cherry-pick of NVIDIA-NeMo#3929 (NVIDIA-NeMo#4050).

## Where this fits

Datasets reach an environment server in one of two ways today: run
request rows route by their agent, and datasets that declare `taskset:`
are materialized during collation and route by
`environment_server_routes`. The goal is one path, where every dataset
declares a taskset and routes to an environment server:

```mermaid
flowchart LR
    P["Preparation script<br/>task rows with a stable task_id"] --> C["Collation<br/>validates, computes metrics,<br/>materializes"]
    Y["Dataset YAML<br/>file + taskset"] --> C
    S["task_data.py schemas<br/>environment server + resources server"] -.-> C
    C --> R["Rollout collection<br/>routes by taskset"]
    T["environment_server_routes"] --> R
    R --> E["Environment server<br/>single-agent, multi-agent,<br/>or legacy_agent relay"]
```

This PR is one step on the way there. Each step is additive, and
datasets without `taskset:` keep working until the last one:

```mermaid
flowchart TB
    S3818["PR 3818 (merged)<br/>collation materializes<br/>declared tasksets"]
    S4053["PR 4053<br/>tasksets route to servers<br/>with several agents"]
    S4096["PR 4096<br/>stable, unique<br/>task IDs"]
    S4097["PR 4097<br/>metrics for<br/>every row"]
    S4098["PR 4098<br/>schema per<br/>environment server"]
    S4099["PR 4099<br/>legacy_agent relays<br/>serve tasksets"]
    SNEXT["Later<br/>configs declare taskset:,<br/>then agent routing retires"]
    S3818 --> S4053 --> S4096 --> S4097 --> S4098 --> S4099 --> SNEXT
    classDef done fill:#F1EFE8,stroke:#5F5E5A,color:#444441
    classDef this fill:#EEEDFE,stroke:#534AB7,color:#26215C,stroke-width:2px
    classDef next fill:#E1F5EE,stroke:#0F6E56,color:#085041
    class S3818 done
    class S4053 this
    class S4096,S4097,S4098,S4099,SNEXT next
```

Gray: merged. Purple: this PR. Green: other steps.

### Environment servers that front several agents

An environment server can front several agents, such as the user and
assistant agents of the user-simulation server in NVIDIA-NeMo#3800. It references
them through fields such as `user_agent` and `assistant_agent`. Gym only
recognized the `agent_server` field. For such a server:

- The deprecation check from NVIDIA-NeMo#3929 treated its agents as unfronted and
generated a `legacy_agent` relay in front of each.
- Agent-routed rows could not find the server, because
`_environment_servers_by_agent` only read `agent_server`.

The first commit from NVIDIA-NeMo#4059 (authored by Felipe Vieira Frujeri) adds
`environment_server_agent_refs` to `nemo_gym/global_config.py`. Any
top-level field whose value has `type: responses_api_agents` references
an agent, and so does `agent_server`, whose type may be left out. The
deprecation check, agent routing, and `_retarget_environment_servers`
(which follows an agent swapped during composition) use it.

Two places in `nemo_gym/rollout_collection.py` still read only
`agent_server`:

- `_agent_name_for_row` names the agent a row's results are attributed
to. It decides whether token IDs are captured and labels aggregate
metrics. Results are now attributed to the server's `agent_server`, or
to the only agent it references. A server that fronts several agents
without an `agent_server` has no single agent to attribute, as before.
- `_validate_environment_servers` rejects a row whose `agent_ref` names
an agent the server does not front. It skipped the check for any server
without `agent_server`. A row may now name any agent its server
references.

### The migration script

The script assumed an environment server references one agent, through
`agent_server`. It now finds agent references with the same rule as
`environment_server_agent_refs`. The script depends only on PyYAML, so
it keeps its own copy of the rule, and a test checks that both agree.
Each referenced agent counts as fronted, so the script no longer adds
relays in front of agents a multi-agent server already fronts, such as
those in `resources_servers/usersim/configs/usersim.yaml` from NVIDIA-NeMo#3800.

For an agent renamed with `_inherit_from`, the renamed agent's server
used to inherit from the name the script would generate for the source,
always as a `legacy_agent` relay. That failed in three ways:

- The source's server has a custom name: the inherited name does not
exist, raising `InheritPathNotFoundError`.
- The source's server is `single_agent_turn_legacy`: the inherited
server gains a second `legacy_agent` block without an entrypoint,
raising `AlmostServerError`.
- Inheriting retires the source server's name, which
`environment_server_routes` may still use. For example, usersim routes
its tasksets to `usersim_environment`.

The script now handles a rename this way:

- Where a declared server references the source, the script points that
reference at the new name, on the existing server. The server keeps its
name, so routes and the server's other agents are unaffected. Renaming
several agents of one server writes one block for that server.
- Where the source has only the server the script generates, the renamed
agent's server inherits it, as before.
- A rename in the same file as a server that references its source
cannot be migrated by appending, because the server's key would repeat.
The script reports the field to update by hand and exits with 2.

### The renamed-agent hint

When an environment server references an agent that no longer exists,
`ServerRefNotFoundError` suggests the agent may have been renamed with
`_inherit_from`. The hint said the environment server "must be renamed
with it", which no longer matches the script.

- The hint now says the environment server must reference the agent's
new name, and names the field to update instead of always
`agent_server.name`.
- It is shown for any agent reference on an environment server, not only
`agent_server`.
- `fern/versions/latest/pages/troubleshooting/configuration.mdx`
describes the same rename behavior, and the script's exit code 2 for a
rename that needs a manual update.

### Declared tasksets routed to a multi-agent server

NVIDIA-NeMo#3818 added `resolve_dataset_agent`'s taskset path, used by benchmark
discovery, `gym eval prepare`, manifest validation, and collation. It
read only the routed environment server's `agent_server`, so a taskset
routed to a server that fronts several agents failed with "must bind a
valid agent_server".

A taskset routes to an environment server, not to an agent: rollout
collection sends materialized rows to the server that
`environment_server_routes` names and never uses an agent. So resolution
now checks the route instead of choosing an agent:

- Every agent the server references, through
`environment_server_agent_refs`, must exist.
- A dataset declared on an agent must be one of those agents.
- A dataset declared on a resources server must be the one the server
binds.
- A dataset with `taskset:` cannot set `agent:`. Only benchmark datasets
accept `agent:`, so requiring a pin would have left example and train
datasets for a server with several agents unable to collate, and would
have made an environment server that owns its dataset name one of its
own agents.

It returns the declaring agent, or the server's attributed agent (its
`agent_server`, or its only agent), or none when the server fronts
several agents without an `agent_server`.
`environment_server_agent_names` and
`environment_server_attributed_agent` move to `global_config.py` so
resolution and rollout attribution share that rule. Benchmarks record
the environment server, and `gym eval list` shows it when there is no
single agent. Environment manifest validation reports that a manifest,
which describes one agent, cannot describe such a taskset.
`resources-server-apis.mdx` describes the route check.

This supersedes NVIDIA-NeMo#4059. No issue is linked. It follows up NVIDIA-NeMo#3929, from
review on NVIDIA-NeMo#4050, and provides the runtime support NVIDIA-NeMo#3800 needs.

## Validation

- `tests/unit_tests/test_global_config.py`: a multi-agent server fronts
all of its agents and needs no relays, removing one agent's reference
makes that agent unfronted, and a composition swap retargets only the
swapped agent's reference. The rename hint test runs for an
`agent_server` and a `user_agent` reference.
- `tests/unit_tests/test_rollout_collection.py`: attribution to
`agent_server`, to a server's only agent, and to no agent for a server
with several, and row validation accepting any agent of the server and
rejecting others.
- `tests/unit_tests/test_add_legacy_agent_environment_servers.py`:
migrate-then-parse tests, which run the script and parse the result with
`GlobalConfigDictParser`. They cover a rename whose source server is
generated, custom-named, or `single_agent_turn_legacy`, a two-agent
server the script must leave alone, renaming both agents of that server
(parsed with `error_on_agent_without_environment_server: true`), and a
rename in the same file as the server it would update. A test checks
that the script and `environment_server_agent_refs` find the same
references.
- `tests/unit_tests/test_benchmarks.py`: a multi-agent taskset resolves
without a pin, to none or to the server's `agent_server`; any pin on a
taskset dataset is rejected; a reference to a non-agent is rejected; a
declaring participant is accepted; benchmark, example, and train
datasets collate and route end to end; the benchmark listing names the
environment server; and manifest validation reports a multi-agent
taskset. These tests fail without the change.
- `pytest tests/unit_tests/test_global_config.py
tests/unit_tests/test_add_legacy_agent_environment_servers.py
tests/unit_tests/test_rollout_collection.py
tests/unit_tests/test_environment_scaffold.py
tests/unit_tests/test_benchmarks.py
tests/unit_tests/test_task_materialization.py`: all pass.
- `pytest tests/unit_tests`: the tests that fail in this environment
fail identically on `main`. They need the `sandbox` and telemetry
extras, or Slurm.
- With NVIDIA-NeMo#3800 merged locally: the script leaves
`resources_servers/usersim/configs/usersim.yaml` unchanged. After
renaming `usersim_assistant`, the usersim config parses with
`error_on_agent_without_environment_server: true`, `usersim_environment`
fronts both agents, and both usersim routes still name an existing
server.
- `python scripts/add_legacy_agent_environment_servers.py --check` on
this repository reports the same files and blocks before and after this
change.
- `pre-commit run` on the changed files: all pass.

## Rollouts

N/A. Single-agent servers resolve, route, and attribute exactly as
before, and no configuration in this repository changes. The new
behavior applies only to servers that reference agents through fields
other than `agent_server`. None exist on `main` until NVIDIA-NeMo#3800, which
carries its own rollout evidence. The migration script runs offline.

## Compatibility and benchmark impact

- Environment servers that front several agents no longer get generated
relays, and their agents route to them.
- The error for a row that names the wrong agent for its environment
server now lists the server's agents.
- A dataset that declares `taskset:` can no longer set `agent:`. NVIDIA-NeMo#3818
accepted a pin that matched the routed agent; no configuration in this
repository declares a taskset.
- `gym eval list --json` adds an `environment_server` field, and
`agent_name` is null for a taskset routed to a server with several
agents.
- The migration script updates a declared server in place when an agent
is renamed, so server names and routes no longer change.
- No benchmark impact.

---------

Signed-off-by: Ananth Subramaniam <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>
Co-authored-by: Felipe Vieira Frujeri <[email protected]>
(cherry picked from commit 89c065b)
Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub

Copy link
Copy Markdown
Contributor Author

Closing in favor of #4107, which brings the same changes to r0.7.0 in the form they were merged to main.

This PR carries the #3929 cherry-pick and the first five commits of #4053. After those commits, #4053 gained two more that route declared tasksets to their environment server, and its final version moved the helpers from rollout_collection.py into global_config.py. Those later commits depend on #3818, which this PR does not include.

#4107 cherry-picks #3818, #4070, #3929, and the merged #4053 in their main merge order, so the release branch matches main for these changes.

@ananthsub ananthsub closed this Oct 6, 2026
ehosseiniasl pushed a commit to ehosseiniasl/Gym that referenced this pull request Oct 6, 2026
…VIDIA-NeMo#4053)

## What does this PR do?

Makes Gym and its migration tooling agree on which agents an environment
server fronts, including servers that front several agents. It combines
the runtime change from NVIDIA-NeMo#4059 with fixes to
`scripts/add_legacy_agent_environment_servers.py`, the
`ServerRefNotFoundError` rename hint, and the troubleshooting docs, so
the environment server and agent server changes land together. The same
commits are in the `r0.7.0` cherry-pick of NVIDIA-NeMo#3929 (NVIDIA-NeMo#4050).

## Where this fits

Datasets reach an environment server in one of two ways today: run
request rows route by their agent, and datasets that declare `taskset:`
are materialized during collation and route by
`environment_server_routes`. The goal is one path, where every dataset
declares a taskset and routes to an environment server:

```mermaid
flowchart LR
    P["Preparation script<br/>task rows with a stable task_id"] --> C["Collation<br/>validates, computes metrics,<br/>materializes"]
    Y["Dataset YAML<br/>file + taskset"] --> C
    S["task_data.py schemas<br/>environment server + resources server"] -.-> C
    C --> R["Rollout collection<br/>routes by taskset"]
    T["environment_server_routes"] --> R
    R --> E["Environment server<br/>single-agent, multi-agent,<br/>or legacy_agent relay"]
```

This PR is one step on the way there. Each step is additive, and
datasets without `taskset:` keep working until the last one:

```mermaid
flowchart TB
    S3818["PR 3818 (merged)<br/>collation materializes<br/>declared tasksets"]
    S4053["PR 4053<br/>tasksets route to servers<br/>with several agents"]
    S4096["PR 4096<br/>stable, unique<br/>task IDs"]
    S4097["PR 4097<br/>metrics for<br/>every row"]
    S4098["PR 4098<br/>schema per<br/>environment server"]
    S4099["PR 4099<br/>legacy_agent relays<br/>serve tasksets"]
    SNEXT["Later<br/>configs declare taskset:,<br/>then agent routing retires"]
    S3818 --> S4053 --> S4096 --> S4097 --> S4098 --> S4099 --> SNEXT
    classDef done fill:#F1EFE8,stroke:#5F5E5A,color:#444441
    classDef this fill:#EEEDFE,stroke:#534AB7,color:#26215C,stroke-width:2px
    classDef next fill:#E1F5EE,stroke:#0F6E56,color:#085041
    class S3818 done
    class S4053 this
    class S4096,S4097,S4098,S4099,SNEXT next
```

Gray: merged. Purple: this PR. Green: other steps.

### Environment servers that front several agents

An environment server can front several agents, such as the user and
assistant agents of the user-simulation server in NVIDIA-NeMo#3800. It references
them through fields such as `user_agent` and `assistant_agent`. Gym only
recognized the `agent_server` field. For such a server:

- The deprecation check from NVIDIA-NeMo#3929 treated its agents as unfronted and
generated a `legacy_agent` relay in front of each.
- Agent-routed rows could not find the server, because
`_environment_servers_by_agent` only read `agent_server`.

The first commit from NVIDIA-NeMo#4059 (authored by Felipe Vieira Frujeri) adds
`environment_server_agent_refs` to `nemo_gym/global_config.py`. Any
top-level field whose value has `type: responses_api_agents` references
an agent, and so does `agent_server`, whose type may be left out. The
deprecation check, agent routing, and `_retarget_environment_servers`
(which follows an agent swapped during composition) use it.

Two places in `nemo_gym/rollout_collection.py` still read only
`agent_server`:

- `_agent_name_for_row` names the agent a row's results are attributed
to. It decides whether token IDs are captured and labels aggregate
metrics. Results are now attributed to the server's `agent_server`, or
to the only agent it references. A server that fronts several agents
without an `agent_server` has no single agent to attribute, as before.
- `_validate_environment_servers` rejects a row whose `agent_ref` names
an agent the server does not front. It skipped the check for any server
without `agent_server`. A row may now name any agent its server
references.

### The migration script

The script assumed an environment server references one agent, through
`agent_server`. It now finds agent references with the same rule as
`environment_server_agent_refs`. The script depends only on PyYAML, so
it keeps its own copy of the rule, and a test checks that both agree.
Each referenced agent counts as fronted, so the script no longer adds
relays in front of agents a multi-agent server already fronts, such as
those in `resources_servers/usersim/configs/usersim.yaml` from NVIDIA-NeMo#3800.

For an agent renamed with `_inherit_from`, the renamed agent's server
used to inherit from the name the script would generate for the source,
always as a `legacy_agent` relay. That failed in three ways:

- The source's server has a custom name: the inherited name does not
exist, raising `InheritPathNotFoundError`.
- The source's server is `single_agent_turn_legacy`: the inherited
server gains a second `legacy_agent` block without an entrypoint,
raising `AlmostServerError`.
- Inheriting retires the source server's name, which
`environment_server_routes` may still use. For example, usersim routes
its tasksets to `usersim_environment`.

The script now handles a rename this way:

- Where a declared server references the source, the script points that
reference at the new name, on the existing server. The server keeps its
name, so routes and the server's other agents are unaffected. Renaming
several agents of one server writes one block for that server.
- Where the source has only the server the script generates, the renamed
agent's server inherits it, as before.
- A rename in the same file as a server that references its source
cannot be migrated by appending, because the server's key would repeat.
The script reports the field to update by hand and exits with 2.

### The renamed-agent hint

When an environment server references an agent that no longer exists,
`ServerRefNotFoundError` suggests the agent may have been renamed with
`_inherit_from`. The hint said the environment server "must be renamed
with it", which no longer matches the script.

- The hint now says the environment server must reference the agent's
new name, and names the field to update instead of always
`agent_server.name`.
- It is shown for any agent reference on an environment server, not only
`agent_server`.
- `fern/versions/latest/pages/troubleshooting/configuration.mdx`
describes the same rename behavior, and the script's exit code 2 for a
rename that needs a manual update.

### Declared tasksets routed to a multi-agent server

NVIDIA-NeMo#3818 added `resolve_dataset_agent`'s taskset path, used by benchmark
discovery, `gym eval prepare`, manifest validation, and collation. It
read only the routed environment server's `agent_server`, so a taskset
routed to a server that fronts several agents failed with "must bind a
valid agent_server".

A taskset routes to an environment server, not to an agent: rollout
collection sends materialized rows to the server that
`environment_server_routes` names and never uses an agent. So resolution
now checks the route instead of choosing an agent:

- Every agent the server references, through
`environment_server_agent_refs`, must exist.
- A dataset declared on an agent must be one of those agents.
- A dataset declared on a resources server must be the one the server
binds.
- A dataset with `taskset:` cannot set `agent:`. Only benchmark datasets
accept `agent:`, so requiring a pin would have left example and train
datasets for a server with several agents unable to collate, and would
have made an environment server that owns its dataset name one of its
own agents.

It returns the declaring agent, or the server's attributed agent (its
`agent_server`, or its only agent), or none when the server fronts
several agents without an `agent_server`.
`environment_server_agent_names` and
`environment_server_attributed_agent` move to `global_config.py` so
resolution and rollout attribution share that rule. Benchmarks record
the environment server, and `gym eval list` shows it when there is no
single agent. Environment manifest validation reports that a manifest,
which describes one agent, cannot describe such a taskset.
`resources-server-apis.mdx` describes the route check.

This supersedes NVIDIA-NeMo#4059. No issue is linked. It follows up NVIDIA-NeMo#3929, from
review on NVIDIA-NeMo#4050, and provides the runtime support NVIDIA-NeMo#3800 needs.

## Validation

- `tests/unit_tests/test_global_config.py`: a multi-agent server fronts
all of its agents and needs no relays, removing one agent's reference
makes that agent unfronted, and a composition swap retargets only the
swapped agent's reference. The rename hint test runs for an
`agent_server` and a `user_agent` reference.
- `tests/unit_tests/test_rollout_collection.py`: attribution to
`agent_server`, to a server's only agent, and to no agent for a server
with several, and row validation accepting any agent of the server and
rejecting others.
- `tests/unit_tests/test_add_legacy_agent_environment_servers.py`:
migrate-then-parse tests, which run the script and parse the result with
`GlobalConfigDictParser`. They cover a rename whose source server is
generated, custom-named, or `single_agent_turn_legacy`, a two-agent
server the script must leave alone, renaming both agents of that server
(parsed with `error_on_agent_without_environment_server: true`), and a
rename in the same file as the server it would update. A test checks
that the script and `environment_server_agent_refs` find the same
references.
- `tests/unit_tests/test_benchmarks.py`: a multi-agent taskset resolves
without a pin, to none or to the server's `agent_server`; any pin on a
taskset dataset is rejected; a reference to a non-agent is rejected; a
declaring participant is accepted; benchmark, example, and train
datasets collate and route end to end; the benchmark listing names the
environment server; and manifest validation reports a multi-agent
taskset. These tests fail without the change.
- `pytest tests/unit_tests/test_global_config.py
tests/unit_tests/test_add_legacy_agent_environment_servers.py
tests/unit_tests/test_rollout_collection.py
tests/unit_tests/test_environment_scaffold.py
tests/unit_tests/test_benchmarks.py
tests/unit_tests/test_task_materialization.py`: all pass.
- `pytest tests/unit_tests`: the tests that fail in this environment
fail identically on `main`. They need the `sandbox` and telemetry
extras, or Slurm.
- With NVIDIA-NeMo#3800 merged locally: the script leaves
`resources_servers/usersim/configs/usersim.yaml` unchanged. After
renaming `usersim_assistant`, the usersim config parses with
`error_on_agent_without_environment_server: true`, `usersim_environment`
fronts both agents, and both usersim routes still name an existing
server.
- `python scripts/add_legacy_agent_environment_servers.py --check` on
this repository reports the same files and blocks before and after this
change.
- `pre-commit run` on the changed files: all pass.

## Rollouts

N/A. Single-agent servers resolve, route, and attribute exactly as
before, and no configuration in this repository changes. The new
behavior applies only to servers that reference agents through fields
other than `agent_server`. None exist on `main` until NVIDIA-NeMo#3800, which
carries its own rollout evidence. The migration script runs offline.

## Compatibility and benchmark impact

- Environment servers that front several agents no longer get generated
relays, and their agents route to them.
- The error for a row that names the wrong agent for its environment
server now lists the server's agents.
- A dataset that declares `taskset:` can no longer set `agent:`. NVIDIA-NeMo#3818
accepted a pin that matched the routed agent; no configuration in this
repository declares a taskset.
- `gym eval list --json` adds an `environment_server` field, and
`agent_name` is null for a taskset routed to a server with several
agents.
- The migration script updates a declared server in place when an agent
is renamed, so server names and routes no longer change.
- No benchmark impact.

---------

Signed-off-by: Ananth Subramaniam <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>
Co-authored-by: Felipe Vieira Frujeri <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:config Hydra configuration, schemas, composition, and compatibility complexity:medium Single-domain change with interacting parts or a moderate review surface feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants