Repository navigation
feat(agent): add a base helper that chooses a harness's model endpoint - #4276
Conversation
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]>
yaoyu-33
left a comment
There was a problem hiding this comment.
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.
|
@ananthsub , could you check the remaining CI failures? |
| """ | ||
| if session_endpoint is not None: | ||
| return session_endpoint | ||
| if model_server is not None: |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
could include self.config.name in the error so it's obvious which agent is misconfigured.
|
/ok to test 6e687c8 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/38781830195 |
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_urlso the rollout capture prefix is kept, or an endpoint configured directly on the agent (openai_base_urlon Codex, a provider inmodels_configon 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_endpointmakes that choice in one place and returns aModelEndpointwith abase_url(ending in the API version) and an optionalmodel. 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"]session_endpointis a plain optional parameter supplied by the caller for the episode's session. It is the only branch that may setmodel, for an endpoint that dictates the model name. Nothing in this change produces one yet.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.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 passbase_url=self.config.openai_base_url or "https://api.openai.com/v1"; Pi only overrides its provider whenmodel_serveris set, so it calls the helper on that path only.A shared configuration validator (reject
model_servertogether 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 needsmodelalongside 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
New tests in
tests/unit_tests/test_base_responses_api_agent.pycover each branch of the order against a realSimpleResponsesAPIAgentwith 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. Threepi_agentoutcome tests that need the pinned Pi CLI fail identically onmainwithout 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.
ModelEndpointandSimpleResponsesAPIAgent.model_endpointare new; existing methods are unchanged.