Skip to content

feat: add --agent-type CLI flag to enable agent swaping - #2641

Merged
marta-sd merged 9 commits into
mainfrom
martas/agent-selector
Aug 28, 2026
Merged

marta-sd merged 9 commits into
mainfrom
martas/agent-selector

Conversation

@marta-sd

@marta-sd marta-sd commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

This PR introduces possibility to swap agents in your experiment during runtime, without a need to create a dedicated config. It builds on top of #2640 and passes a selected agent's config to the config composition machinery.

The entire PR stack will introduce the following changes:

  1. config composition
  2. --agent-type flag in the CLI for selecting the agent (this PR)
  3. safeguard preventing unsupported env <> agent pairings
  4. aligning with dataset changes introduced in epic epic: dataset preparation #1338
  5. docs update

@copy-pr-bot

copy-pr-bot Bot commented Aug 20, 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.

@marta-sd
marta-sd force-pushed the martas/agent-selector branch from aaeacda to 12c1af6 Compare August 20, 2026 22:02
@copy-pr-bot

copy-pr-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@marta-sd
marta-sd force-pushed the martas/agent-selector branch from 12c1af6 to aaeacda Compare August 20, 2026 22:02
@marta-sd
marta-sd force-pushed the martas/agent-selector branch from aaeacda to 7ae0b46 Compare August 21, 2026 16:17
@marta-sd marta-sd linked an issue Aug 21, 2026 that may be closed by this pull request
@marta-sd
marta-sd marked this pull request as ready for review August 21, 2026 21:14
@marta-sd
marta-sd force-pushed the martas/agent-selector branch from dff1bff to 1ee85dc Compare August 21, 2026 21:25
@marta-sd
marta-sd force-pushed the martas/agent-selector branch from 96fc1e5 to cb7ee33 Compare August 24, 2026 07:57
@github-actions github-actions Bot added the sla:triage-overdue Review assignment is over the one-business-day SLA label Aug 24, 2026
@cmunley1

Copy link
Copy Markdown
Contributor

/claude review

@github-actions github-actions Bot removed the sla:triage-overdue Review assignment is over the one-business-day SLA label Aug 25, 2026
@claude

claude Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

SHIP — config plumbing refactor, no reliability concerns.

Reviewed the whole diff (32 files). This renames four agent configs to match their dirs, extracts standalone agent configs pulled in via config_paths, and makes eval run --agent mode-dependent. Verified the pieces that could silently break:

  • Merge order is correct. load_extra_config_paths flattens the include tree post-order (nemo_gym/global_config.py:385-398), so a pulled-in agent config merges before the resources-server config that pulls it — the server correctly re-binds resources_server.name over the extracted ???, and the dropped type: lines are re-supplied by the pulled-in block. No unbound-agent regression.
  • _inherit_from benchmarks stay whole. critpt / scicode / finance_sec_search / toolsandbox benchmarks inherit from the resources-server agent instances; shared fields arrive through config_paths during parse before the inherit swap, so inherited blocks are fully populated. The labbench2 duplication note documents the single case where inheriting would break instead.
  • No stale config references. README table, benchmark config_paths, and READMEs all updated for the four renames. (responses_api_agents/opencode_agent/README.md is a different directory, not stale.)
  • CLI split is coherent and tested. --no-serve → +agent_name=X; serve mode → composes the agent config path. TestAgentSelector covers both modes plus benchmark/config composition and the did-you-mean path.
  • Test helpers correctly switched from raw yaml.safe_load to full parser resolution, which is required now that shared agent fields come in via config_paths.

NOTE (author's call, non-blocking): responses_api_agents/tau2/configs/tau2_agent_turn_limit.yaml:22 has a comment still referencing tau2_agent.yaml (now tau2.yaml). Comment-only, that file isn't otherwise touched by this PR.

Could not execute pytest in this sandbox, but the merge/inherit semantics and updated test wiring check out by inspection.

@marta-sd

Copy link
Copy Markdown
Contributor Author

@cmunley1 it was reviewed by a bot already, I wouldn't waste your time if it wasn't

cmunley1
cmunley1 previously approved these changes Aug 26, 2026
@cmunley1

Copy link
Copy Markdown
Contributor

Here is some additional comments from Claude review, could you take a look? If they are incorrect, no worries.


  1. nemo_gym/cli/main.py — line 428 (or multi-line 423–428)

In serve mode this switches --agent from +agent_name= to appending a config path, which silently changes what the flag means for commands that already exist today. Two cases in-tree:

Silent wrong config. responses_api_agents/harbor_agent/configs/harbor_agent_opensandbox.yaml:10-13 documents:

gym eval run --config $AGENT --config $PROVIDER --config $MODEL --agent harbor_agent --split benchmark

harbor_agent is also an agent directory, so it now resolves and appends configs/harbor_agent.yaml last in config_paths, overriding the opensandbox overlay the user explicitly passed. Resolving both orderings through GlobalConfigDictParser: concurrency 89→50, harbor_agent_kwargs.collect_rollout_details False→True, harbor_agent_kwargs.max_turns None→20. The run proceeds with a different harness config, and agent_name is never set at all.

Hard error. responses_api_agents/codex_agent/README.md:141 and claude_code_agent/README.md:170,175 run gym eval run --agent reasoning_gym_codex_agent ... without --no-serve. That's an instance name, not a directory, so it now exits at argparse with:

error: `--agent reasoning_gym_codex_agent` was specified which implies config
responses_api_agents/reasoning_gym_codex_agent/configs/reasoning_gym_codex_agent.yaml,
which does not exist. Did you mean `scicode_agent`?

RolloutCollectionConfig.agent_name (nemo_gym/rollout_collection.py:466, consumed at :618-620) is still live on the serve path, so naming an instance has no replacement other than raw +agent_name=.

Could serve mode fall back to +agent_name= when the value doesn't resolve as an agent config? Otherwise a separate flag would keep both meanings unambiguous. Either way the three docs above need updating.


  1. tests/unit_tests/test_cli_main.py — line 1294

This covers the --no-serve half of exactly the right concern — the comment below it is correct that instance names never resolve as agent configs. The serve-mode half is untested, and that's the half that breaks: ["eval", "run", "-a", "reasoning_gym_codex_agent"] without --no-serve currently exits non-zero at argparse, and that exact command is in codex_agent/README.md:141.

Worth a companion case here asserting whatever serve mode should do with a non-config name.


  1. tests/unit_tests/test_cli_main.py — line 146

These two removed cases were the only assertions that eval run --agent NAME produces +agent_name=NAME. TestAgentSelector picks up serve-mode composition and the --no-serve passthrough, but nothing now asserts serve-mode behavior for a name that isn't an agent config — which is where the behavior change actually bites.


  1. nemo_gym/cli/main.py — line 418

nit: -a is asymmetric across commands. EVAL_RUN_AGENT registers it, but AGENT goes through _asset_selector, which supports no aliases — so gym eval run -a hermes_agent works while gym env start -a hermes_agent fails with unrecognized arguments: -a. Same flag name, different surface per command.


gwarmstrong
gwarmstrong previously approved these changes Aug 27, 2026

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

A couple nits but otherwise lgtm

Comment thread nemo_gym/cli/main.py Outdated
Comment on lines +423 to +429
translate_to_hydra=lambda args: (
[]
if not args.agent
else [f"+agent_name={args.agent}"]
if args.no_serve
else [f"+config_paths=[{_asset_config_path('agent', args.agent)}]"]
),

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.

The --agent flag can give different results here depending on the --no_serve flag, which could be confusing end user behavior:

$ gym eval run --benchmark gpqa --model-type vllm_model --agent gpqa_mcqa_simple_agent -o out.jsonl
gym eval run: error: `--agent gpqa_mcqa_simple_agent` was specified which implies config
`responses_api_agents/gpqa_mcqa_simple_agent/configs/gpqa_mcqa_simple_agent.yaml`, which does not
exist. Did you mean `simple_agent`?

$ gym eval run --no-serve --agent gpqa_mcqa_simple_agent -i rows.jsonl -o out.jsonl
Using `gpqa_mcqa_simple_agent` for rows that do not already have an agent ref

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, --agent is doing double duty in determining both where this row should go in choosing a running agent instance, and also which harness does that instance run.

would splitting this into 2 flags make the intent clearer? e.g. --agent-instance and --agent-implementation?

gym eval run \
  --environment math \
  --agent-instance math_agent \
  --agent-implementation hermes_agent
  • Load the environment’s math_agent instance.
  • Replace only its harness with Hermes.
  • Keep its resources-server and model bindings.
  • Route the selected rows to math_agent.

and with existing servers,

gym eval run --no-serve --agent-instance math_agent

routes rows to the running math_agent. adding --agent-implementation with --no-serve should fail since the server is already running

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.

fair point. I will go with --agent-instance and --agent-type to be consistent with --model-type

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 1b4c042

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.

Actually there's no need to touch old --agent flag. I'll revert this change and just add a new --agent-type flag for the new functionality

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 0be167e

Comment thread nemo_gym/cli/main.py Outdated
RESOURCES_SERVER_CONFIG = _asset_selector("resources-server")
MODEL_TYPE = _asset_selector("model-type")

AGENT = _asset_selector("agent")

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.

_asset_selector() registers only the long form, while EVAL_RUN_AGENT below allows both --agent and -a, so the short form only works on some commands, e.g.,

$ gym eval run -a hermes_agent ...        # accepted
$ gym env start -a hermes_agent ...
gym env start: error: unrecognized arguments: -a

@marta-sd marta-sd Aug 27, 2026 •

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.

should we keep -a for agent instance or use it for agent type? I split the flag per the other comment. Or introduce two aliases?

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.

I'll keep is backward compatible: -a stays with --agent and --agent-type don't get an alias, at least for now. I couldn't come up with any alias that wouldn't be confusing. We can add it later if anyone has a good idea which latter we should use 😅

@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Aug 27, 2026
ananthsub
ananthsub previously approved these changes Aug 27, 2026
@github-actions github-actions Bot removed the sla:review-overdue Review response is over the one-business-day SLA label Aug 27, 2026
@marta-sd
marta-sd dismissed ananthsub’s stale review August 27, 2026 12:15

The merge-base changed after approval.

agronskiy
agronskiy previously approved these changes Aug 28, 2026
@marta-sd marta-sd changed the title feat: add --agent CLI flag to enable agent swaping feat: add --agent-type CLI flag to enable agent swaping Aug 28, 2026
@marta-sd
marta-sd force-pushed the martas/agent-selector branch from 55514ee to 19af282 Compare August 28, 2026 12:15
Base automatically changed from martas/agent-composition-transform to main August 28, 2026 12:20
Signed-off-by: Marta Stepniewska-Dziubinska <[email protected]>
Signed-off-by: Marta Stepniewska-Dziubinska <[email protected]>
Signed-off-by: Marta Stepniewska-Dziubinska <[email protected]>
Signed-off-by: Marta Stepniewska-Dziubinska <[email protected]>
Signed-off-by: Marta Stepniewska-Dziubinska <[email protected]>
Signed-off-by: Marta Stepniewska-Dziubinska <[email protected]>
Signed-off-by: Marta Stepniewska-Dziubinska <[email protected]>
@marta-sd
marta-sd force-pushed the martas/agent-selector branch from 19af282 to a5ffcb4 Compare August 28, 2026 12:28
@marta-sd
marta-sd merged commit dc97949 into main Aug 28, 2026
39 checks passed
@marta-sd
marta-sd deleted the martas/agent-selector branch August 28, 2026 12:41
adil-a added a commit that referenced this pull request Aug 28, 2026
Main's #2641 compose test asserts the composed agent block carries the gpqa
benchmark dataset; the migration moved it to the resources server.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
adil-a added a commit that referenced this pull request Aug 28, 2026
Main's #2641 compose test asserts the composed agent block carries the gpqa
benchmark dataset; the migration moved it to the resources server.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
adil-a added a commit that referenced this pull request Aug 28, 2026
Main's #2641 compose test asserts the composed agent block carries the gpqa
benchmark dataset; the migration moved it to the resources server.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>

This branch was previously deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Introduce --agent CLI flag that allows to select agent at runtime

5 participants