Skip to content

feat(agent): add a base helper that chooses a harness's model endpoint - #4276

Merged
oyilmaz-nvidia merged 2 commits into
mainfrom
ananthsub/agent-model-endpoint
Oct 15, 2026
Merged

oyilmaz-nvidia merged 2 commits into
mainfrom
ananthsub/agent-model-endpoint

Conversation

@ananthsub

Copy link
Copy Markdown
Contributor

What changed and why

Agents that drive an external harness (for example Hermes, Pi, and Codex) each decide on their own where the harness sends its model calls. Today that is either the Gym model server, resolved with resolve_model_base_url so the rollout capture prefix is kept, or an endpoint configured directly on the agent (openai_base_url on Codex, a provider in models_config on Pi). Two upcoming needs make a shared decision point worthwhile: agents should be able to run without a Gym model server when another endpoint is supplied, and a session component that records model calls (for example a sidecar container next to the task sandbox) needs to substitute its own endpoint without changing each agent.

SimpleResponsesAPIAgent.model_endpoint makes that choice in one place and returns a ModelEndpoint with a base_url (ending in the API version) and an optional model. The order is:

flowchart TD
    A["model_endpoint(...)"] --> B{"session_endpoint given?"}
    B -->|yes| C["return session_endpoint as is"]
    B -->|no| D{"model_server set?"}
    D -->|yes| E["resolve_model_base_url with the rollout prefix"]
    D -->|no| F{"base_url set?"}
    F -->|yes| G["return base_url verbatim"]
    F -->|no| H["raise ValueError"]
Loading
  • session_endpoint is a plain optional parameter supplied by the caller for the episode's session. It is the only branch that may set model, for an endpoint that dictates the model name. Nothing in this change produces one yet.
  • The model server branch goes through the existing resolve_model_base_url, so the rollout prefix and the training token capture route (/ng-rollout/<id>/training-token-capture) are preserved exactly as they are today.
  • The configured base URL is returned without a prefix, because a direct endpoint has no prefix routing and a prefix would make every call fail. This matches what Codex does today.
  • All arguments are keyword-only.

No agent is changed. Each agent adopts the helper in its own follow-up change. The helper fits the current agents without forcing changes: Hermes always has model_server; Codex can pass base_url=self.config.openai_base_url or "https://api.openai.com/v1"; Pi only overrides its provider when model_server is set, so it calls the helper on that path only.

A shared configuration validator (reject model_server together with another endpoint source, reject none at all) is not included. The rules differ per agent today: Codex defaults to the public OpenAI endpoint, Pi and the local OpenCode path can run on their own provider configuration, and Hermes needs model alongside a direct base URL. A shared validator would not fit them without changing behavior, so each agent's follow-up adds its own validator.

Linked issue

None. This is a small internal hook that prepares the follow-up per-agent changes; the PR description carries the rationale.

Validation

NEMO_GYM_EXTRA_ROOTS=$PWD PYTHONPATH=$PWD python -m pytest tests/unit_tests/test_base_responses_api_agent.py -q
NEMO_GYM_EXTRA_ROOTS=$PWD PYTHONPATH=$PWD python -m pytest tests/unit_tests/test_agent_session_retries.py tests/unit_tests/test_agent_sessions.py tests/unit_tests/test_base_responses_api_model.py tests/unit_tests/test_rollout_correlation.py tests/unit_tests/test_aggregate_metrics.py tests/unit_tests/telemetry/test_call_sites.py -q
NEMO_GYM_EXTRA_ROOTS=$PWD PYTHONPATH=$PWD python -m pytest responses_api_agents/hermes_agent/tests responses_api_agents/pi_agent/tests responses_api_agents/codex_agent/tests -q
pre-commit run --files nemo_gym/base_responses_api_agent.py tests/unit_tests/test_base_responses_api_agent.py

New tests in tests/unit_tests/test_base_responses_api_agent.py cover each branch of the order against a real SimpleResponsesAPIAgent with a model server in the global configuration: the session endpoint winning over a model server and a base URL, the model server keeping the rollout prefix, the model server without a rollout id, the training token capture route when token capture is enabled, the configured base URL used verbatim even when token capture is enabled, and the error when nothing is configured (both missing and empty base URL). The tests fail without the change (import error), and fail when the rollout id is dropped or when the session endpoint is checked after the model server. Three pi_agent outcome tests that need the pinned Pi CLI fail identically on main without this change.

Rollouts

N/A. This adds an unused helper on the agent base class; no agent, configuration, or request path changes behavior.

Compatibility

Additive only. ModelEndpoint and SimpleResponsesAPIAgent.model_endpoint are new; existing methods are unchanged.

Agents that drive an external harness each decide on their own where the
harness sends model calls: a Gym model server with the rollout capture
prefix, or a directly configured OpenAI-compatible base URL. A later
session component that records model calls needs to substitute its own
endpoint, and agents should be able to run without a Gym model server
when another endpoint is supplied.

SimpleResponsesAPIAgent.model_endpoint now makes that choice in one
place. It returns a ModelEndpoint (base URL and an optional model name)
in this order: an endpoint the caller passes for the episode's session,
the model server through resolve_model_base_url (keeping the rollout
prefix and the training token capture route), then the agent's
configured base URL verbatim. It raises ValueError when none is set.
No agent is changed here; each adopts the helper in its own change.

Signed-off-by: Ananth Subramaniam <[email protected]>
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team October 9, 2026 05:58
@yaoyu-33 yaoyu-33 added area:agent Agent harnesses and Responses API agent behavior complexity:low Localized change in one scope with a small, straightforward review surface feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer labels Oct 9, 2026
@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Oct 12, 2026

@yaoyu-33 yaoyu-33 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.

LGTM. Endpoint precedence is clear and the Gym model-server path preserves per-rollout correlation and capture routing. 15 focused tests passed locally. Harness conformance CI still needs to be cleared before merge.

@yaoyu-33 yaoyu-33 added ready-to-merge PR is approved, current, and waiting for final CI or merge and removed needs-review PR is ready for code review and waiting on a reviewer labels Oct 13, 2026
@zyzhou5

zyzhou5 commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

@ananthsub , could you check the remaining CI failures?

"""
if session_endpoint is not None:
return session_endpoint
if model_server is not None:

@cmunley1 cmunley1 Oct 15, 2026 •

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.

if both model_server and base_url are set, base_url is silently ignored. maybe one line in the docstring saying model_server wins?

return ModelEndpoint(base_url=self.resolve_model_base_url(model_server.name, rollout_id))
if base_url:
return ModelEndpoint(base_url=base_url)
raise ValueError("No model endpoint: configure model_server or a model base URL")

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 include self.config.name in the error so it's obvious which agent is misconfigured.

@oyilmaz-nvidia

Copy link
Copy Markdown
Contributor

/ok to test 6e687c8

@oyilmaz-nvidia
oyilmaz-nvidia added this pull request to the merge queue Oct 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/38781830195

Merged via the queue into main with commit d6af148 Oct 15, 2026
49 of 54 checks passed
@oyilmaz-nvidia
oyilmaz-nvidia deleted the ananthsub/agent-model-endpoint branch October 15, 2026 18:18

This branch was previously deployed

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

Labels

area:agent Agent harnesses and Responses API agent behavior complexity:low Localized change in one scope with a small, straightforward review surface feature New capabilities, enhancements, or enablement work ready-to-merge PR is approved, current, and waiting for final CI or merge sla:review-overdue Review response is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants