Repository navigation
fix(anyswe_agent): request the training-token-capture prefix and run the inner harness in capture mode #4016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
linj-glitch
wants to merge
5
commits into
NVIDIA-NeMo:main
Choose a base branch
from
linj-glitch:linj/anyswe-token-capture
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+291
−8
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4402c2f
fix(anyswe_agent): request the training-token-capture prefix and run …
linj-glitch 980f26e
Merge main into anyswe token capture follow-up
linj-glitch 1d4013d
fix(anyswe_agent): align capture IDs with the sandbox model URL
linj-glitch 2253ab2
Merge main to refresh AnySWE PR #4016
linj-glitch 391f8a6
test(anyswe_agent): preserve trace context alongside token capture
linj-glitch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
responses_api_agents/anyswe_agent/tests/test_token_capture.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| """Training-token capture wiring for anyswe_agent and its in-sandbox runner.""" | ||
|
|
||
| from pathlib import Path | ||
| from types import SimpleNamespace | ||
|
|
||
| import pytest | ||
|
|
||
| from nemo_gym.openai_utils import NeMoGymResponse, NeMoGymResponseCreateParamsNonStreaming | ||
| from responses_api_agents.anyswe_agent.agent_runner import _runner_global_config | ||
| from responses_api_agents.anyswe_agent.app import ( | ||
| AnySweAgent, | ||
| AnySweServerConfig, | ||
| _model_url_for_rollout, | ||
| _outer_response_id, | ||
| ) | ||
| from responses_api_agents.anyswe_agent.tests.test_app import _config | ||
|
|
||
|
|
||
| def test_model_url_carries_the_training_capture_prefix() -> None: | ||
| assert ( | ||
| _model_url_for_rollout("http://model-host:8000", "3-1", token_capture=True) | ||
| == "http://model-host:8000/ng-rollout/3-1/training-token-capture" | ||
| ) | ||
| assert _model_url_for_rollout("http://model-host:8000", "3-1") == "http://model-host:8000/ng-rollout/3-1" | ||
| assert _model_url_for_rollout("", "3-1", token_capture=True) == "" | ||
| assert _model_url_for_rollout("http://model-host:8000", None, token_capture=True) == "http://model-host:8000" | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("capture", [False, True]) | ||
| def test_setup_params_requests_the_capture_prefix_when_capture_is_on(tmp_path: Path, capture: bool) -> None: | ||
| server = AnySweServerConfig( | ||
| run_session_id="s", | ||
| base_results_dir=tmp_path, | ||
| model_server_url="http://policy:8000", | ||
| resolved_sandbox_provider={"opensandbox": {}}, | ||
| sandbox_default_metadata={}, | ||
| ) | ||
| agent = AnySweAgent.__new__(AnySweAgent) | ||
| object.__setattr__( | ||
| agent, | ||
| "__dict__", | ||
| { | ||
| "config": _config(token_id_capture=True), | ||
| "server_client": SimpleNamespace(global_config_dict={"token_id_capture": {"enabled": capture}}), | ||
| }, | ||
| ) | ||
| object.__setattr__(agent, "__pydantic_fields_set__", set()) | ||
| object.__setattr__(agent, "__pydantic_extra__", None) | ||
| object.__setattr__(agent, "__pydantic_private__", {"_server": server, "_sem": None}) | ||
| body = NeMoGymResponseCreateParamsNonStreaming(input="fix it", metadata={"instance_id": "astropy__astropy-12907"}) | ||
|
|
||
| params = agent._setup_params(body, rollout_id="7-2") | ||
|
|
||
| suffix = "/training-token-capture" if capture else "" | ||
| assert params.model_server_url == f"http://policy:8000/ng-rollout/7-2{suffix}" | ||
|
|
||
|
|
||
| def test_inner_agent_learns_that_token_capture_is_on_from_the_model_url() -> None: | ||
| assert _runner_global_config("", "policy_model") == {} | ||
| eval_config = _runner_global_config("http://policy:8000/ng-rollout/7-2", "policy_model") | ||
| assert "token_id_capture" not in eval_config | ||
| assert eval_config["policy_model"]["responses_api_models"]["model"]["port"] == 0 | ||
| capture_config = _runner_global_config("http://policy:8000/ng-rollout/7-2/training-token-capture", "policy_model") | ||
| assert capture_config["token_id_capture"] == {"enabled": True, "all_agents": True} | ||
|
|
||
|
|
||
| def test_outer_response_keeps_the_inner_served_id_only_under_capture() -> None: | ||
|
linj-glitch marked this conversation as resolved.
Resolved
|
||
| inner = NeMoGymResponse.model_construct(id="resp_served123") | ||
| instance_id = "astropy__astropy-12907" | ||
| assert _outer_response_id(instance_id, inner, token_capture=True) == "resp_served123" | ||
| assert _outer_response_id(instance_id, inner, token_capture=False) == "anyswe-astropy__astropy-12907" | ||
| assert _outer_response_id(instance_id, None, token_capture=True) == "anyswe-astropy__astropy-12907" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.