Repository navigation
Description
Problem
Gym renames agents in two ways, and they do not follow the rename the same way.
- Agent swap:
compose_unbound_agentrenames each target instance, then runs three steps on the old-to-new names._retarget_environment_serverspoints environment servers at the new name._raise_on_outdated_routingraises an error whenagent_name, anagent_mapvalue, or afan_outentry still names the old instance._route_rows_stamped_before_the_swapadds anagent_mapentry from the old name to the new one, so rows whoseagent_refuses the old name still reach the agent.
- Rename with
_inherit_from: after fix(config): preserve environment server references when agents are renamed #4141,_recursively_swap_keysruns only_retarget_environment_servers.
Neither path updates dataset agent: pins, which dataset_agent_pins reads.
The gaps show up late. A rename that leaves agent_name: <old name> in the config loads, then fails during rollout collection. A dataset pin that names a renamed or swapped agent loads, then fails in resolve_dataset_agent during benchmark discovery, gym eval prepare, collation, or dispatch.
Proposed change
flowchart TD
R["Rename with _inherit_from<br/>found in parse()"]
W["Agent swap<br/>compose_unbound_agent()"]
S["_follow_renamed_agents(renames)<br/>one step, called by both"]
E["Environment server references<br/>point at the new name"]
T["agent_name, agent_map values, fan_out<br/>naming the old name raise an error"]
M["Rows stamped with the old name<br/>reach the new agent through agent_map"]
P["Dataset agent: pins<br/>rewritten to the new name"]
R --> S
W --> S
S --> E
S --> T
S --> M
S --> P
classDef done fill:#E1F5EE,stroke:#0F6E56,color:#085041
classDef todo fill:#FAECE7,stroke:#993C1D,color:#712B13
class E done
class S,T,M,P todo
Green already runs for both paths after #4141.
- Move the three swap steps into one method, for example
_follow_renamed_agents(global_config_dict, renames), and call it for swaps and renames. - Add a step that rewrites dataset
agent:pins naming the old agent, for both swaps and renames. - Reword the
_raise_on_outdated_routingmessage, which says "once the agent is swapped", so it also fits a rename. - Move rename detection out of
_recursively_swap_keys, which is the generic pass for_inherit_from,_copy, and_delete_key, into a named step thatparse()calls. - Use one helper for the rule that decides which environment server fields reference an agent. After fix(config): preserve environment server references when agents are renamed #4141 the rule is written out in
environment_server_agent_refsand again in_raise_on_ambiguous_environment_agent_renames. The migration script keeps its own copy, checked by a test.
Compatibility
144 config files under benchmarks/ rename an agent with _inherit_from and declare their own environment server for the new name. The shared step will run for them. Every benchmark should resolve to the same agent and environment servers as before, and gym eval list --json output should not change. The expected difference in resolved configs is the added agent_map entries.
Tests
- A rename where
agent_name, anagent_mapvalue, or afan_outentry names the old agent raises the same error a swap does. - A row whose
agent_refnames the old agent is dispatched to the renamed agent. - A dataset
agent:pin naming the old agent resolves to the new agent throughresolve_dataset_agent, after a rename and after a swap. - A chained rename,
atobtoc, either loads with the server oncor fails with a clear error. - A rename and an agent swap in the same config.
- A rename whose new entry adds a second agent type is not followed, and fails with a clear error.
Activity