Skip to content

fix(agents): honor generation controls in coding agent sessions - #4867

Closed
zyzhou5 wants to merge 9 commits into
NVIDIA-NeMo:mainfrom
zyzhou5:fix-coding-agent-generation-controls
Closed

zyzhou5 wants to merge 9 commits into
NVIDIA-NeMo:mainfrom
zyzhou5:fix-coding-agent-generation-controls

Conversation

@zyzhou5

@zyzhou5 zyzhou5 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #4656. Accepts NeMo-RL's temperature, top_p, and max_output_tokens in Hermes, Pi, Codex, OpenCode, and OpenClaw agent sessions and applies them to the actual model calls. Hermes host execution uses the same contract.

Each activation carries its settings in its Model Server URL. The Model Server applies them before capture and checkpoint admission, keeping concurrent rollouts independent. max_output_tokens is a per-call cap, including summary calls, and preserves smaller limits selected by the harness.

Validation

  • Current CI: core tests, all eight server-suite shards, and release validation passed at 3ba458eb. The nonblocking Kilocode conformance failure matches the previous revision. CI run.
  • Review-fix validation at 3ba458eb: 125 focused tests passed across sampling middleware, vLLM conversion/overrides, and Pi request validation. Full pre-commit checks passed.
  • Initial local validation: 1,294 tests passed, 4 skipped across the core sampling/routing tests and five agents' host/session tests. The skips require the installed Pi runtime.
  • After rebasing, before the review fixes: 704 passed, 6 skipped across core/model-server tests, and 624 passed, 5 skipped across Codex, Pi, and OpenCode session/continuation tests. These overlap the initial selection. Skips require Switchyard, Pi 0.80.2, or Python 3.8.
  • Sampling module coverage in the initial validation: 99.07%.
  • pre-commit run --all-files and git diff --check passed.
Focused test selections

These suite selections cover the initial and post-rebase runs. Tests were invoked through pytest.main in the existing project environments, with editable imports redirected to this checkout. Equivalent pytest selections:

pytest -q \
  tests/unit_tests/test_model_sampling.py \
  tests/unit_tests/test_base_responses_api_model.py \
  tests/unit_tests/test_base_responses_api_agent.py \
  tests/unit_tests/test_rollout_correlation.py \
  responses_api_models/{openai_model,switchyard_model,vllm_model}/tests/test_app.py \
  responses_api_models/vllm_model/tests/test_model_sampling.py

pytest -q \
  responses_api_agents/{hermes_agent,pi_agent,codex_agent,opencode_agent,openclaw_agent}/tests/test_app.py \
  responses_api_agents/hermes_agent/tests/test_sandbox.py \
  responses_api_agents/hermes_agent/tests/test_sandbox_runner.py \
  responses_api_agents/pi_agent/tests/test_sandbox.py \
  responses_api_agents/codex_agent/tests/test_sandbox_sessions.py \
  responses_api_agents/codex_agent/tests/test_sandbox_transport.py \
  responses_api_agents/codex_agent/tests/test_sandbox_runner.py \
  responses_api_agents/opencode_agent/tests/test_sandbox_sessions.py \
  responses_api_agents/opencode_agent/tests/test_continuation.py \
  responses_api_agents/openclaw_agent/tests/test_sandbox.py

python -m coverage report --include='*/nemo_gym/model_sampling.py' --fail-under=96
pre-commit run --all-files
git diff --check

CI also ran responses_api_agents/pi_sandboxed_agent/tests/test_app.py: 51 passed in server-suite shard 0. This is CI evidence, separate from the local selections above.

Rollouts

Real-model validation on AGA used NVIDIA-Nemotron-3-Nano-30B-A3B-BF16 through single_agent_turn, with temperature=0.6, top_p=0.85, and a per-call output cap of 2,048 tokens.

  • Five-harness sampling, token capture off: Hermes, Pi, Codex, OpenCode, and OpenClaw ran the same NodeBB task from SWE-bench Pro. All five demonstrated tool-result continuation and forwarded the requested settings across 283 requests; all 280 completed model responses stayed within their caps. Four episodes returned verifier results. OpenClaw passed the sampling checks on all 20 model calls but ended with the diagnosed HTTP 502 below. W&B run (AGA job 1396409).
  • Codex RL training, token capture and R3 on: a smaller, derived NodeBB Redis mget task on four GPUs completed two GRPO steps, with two generations per prompt: four rollouts and 66 captured model calls. Sampling checks passed, losses were finite, gradients were nonzero, and there were zero invalid rows or poisoned captures. Job exited 0. W&B run (AGA job 1396416).
Tested revisions and run notes
  • Both reruns used Gym 3ba458eb and RL 1f299a8c. Run-local setup included an RL logging accessor correction, Codex prompt guidance naming its available tools, and request/process diagnostics.
  • OpenClaw's retained HTTP body says OpenClaw produced no terminal assistant result. After repeated requests for an unavailable tool, its CLI exited 0 with final stopReason=toolUse, without a terminal stop record. Gym's existing, unchanged completion check rejected that state. Full HTTP error, stdout, stderr, and native transcript were retained; all 20 model calls returned HTTP 200 with the requested controls.
  • The sampling run also recorded one Pi context-length rejection and interrupted Codex/OpenCode calls. These are excluded from the 280 completed-response cap checks. After results and W&B sync completed, leftover Gym server processes were stopped to unblock shutdown; the job exited 0.
  • Codex training's final rows, capture lineage, and per-call response usage passed the corrected artifact checker. Raw per-call token arrays and prev_logprobs were not retained.

Compatibility and benchmark impact

Omitted controls retain existing defaults, and Model Server sampling_overrides retain precedence. Pi, Codex, OpenCode, and OpenClaw's older local entrypoints are unchanged. Explicit controls can change generated trajectories; no benchmark-score equivalence is claimed.

Checklist

  • I have read the contributing guidelines.
  • The change is focused; unrelated fixes remain separate.
  • Tests added or updated and pass locally, with skips reported above.
  • Existing agent documentation updated.
  • Pre-commit checks pass locally.
  • New source files include the Apache-2.0 SPDX header.
  • All commits have DCO sign-off.

@zyzhou5 zyzhou5 added bug Something isn't working area:agent Agent harnesses and Responses API agent behavior labels Oct 21, 2026
@copy-pr-bot

copy-pr-bot Bot commented Oct 21, 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.

@zyzhou5
zyzhou5 marked this pull request as ready for review October 21, 2026 22:32
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Oct 21, 2026
@zyzhou5
zyzhou5 force-pushed the fix-coding-agent-generation-controls branch from eeca3a4 to ce58397 Compare October 21, 2026 23:17
@zyzhou5

zyzhou5 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test ce58397

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

@zyzhou5
zyzhou5 force-pushed the fix-coding-agent-generation-controls branch from ce58397 to 5ca238b Compare October 21, 2026 23:37
@zyzhou5

zyzhou5 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 5ca238b

@zyzhou5
zyzhou5 force-pushed the fix-coding-agent-generation-controls branch from f52a47c to 8635ca1 Compare October 22, 2026 19:15
@zyzhou5

zyzhou5 commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 8635ca1

@zyzhou5
zyzhou5 requested a review from a team as a code owner October 23, 2026 00:32
@zyzhou5

zyzhou5 commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 69687e6

@zyzhou5

zyzhou5 commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 9ccebc4

@zyzhou5

zyzhou5 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of a broader approach. Instead of each harness agent accepting sampling fields in its requests, the training framework sends its sampling values with each rollout, and Gym carries them to every model call the trained agent makes, whatever the agent:

The review comments here that still apply are carried over; #5463's description lists each one. Thanks for the reviews.

@zyzhou5 zyzhou5 closed this Nov 2, 2026
zyzhou5 added a commit to zyzhou5/Gym that referenced this pull request Nov 3, 2026
… model call

A training framework that serves the policy needs every model call of the agents
it trains sampled with its own values: its training values, or its validation
values for a validation rollout. NeMo RL writes them into each row's
responses_create_params today. Harness agents reject those fields (NVIDIA-NeMo#4656), CLI
harnesses do not send them on every call, and multi-agent rows have no single
responses_create_params to write into.

The framework now sets the values on each row as _ng_model_sampling, next to
_ng_rollout_id, and leaves the task unchanged. Gym carries them into the URL of
every model call the rollout's agent makes, as /ng-sampling/<values> after any
rollout prefix. The Model Server writes them into the request before policy
admission and capture see it: temperature and top_p replace the call's, and
max_output_tokens caps the call's own limit under each endpoint's name.

- Typed rows: the collector copies the field into the episode request, and
  single_agent_turn and harbor add the segment to the agent's activation URL.
  single_agent_turn_legacy reads it from the flat row.
- Flat rows: the agent reads it from its /run body.
- Agents: an inbound segment becomes the request's, and Gym's URL helpers and
  ServerClient put it on every model URL the agent builds.
- In a run that sets the model_call_sampling block, resources servers send
  /ng-sampling/null with their model calls, so a verifier's LLM judge keeps its
  own sampling or its Model Server's sampling_overrides. vllm_model forwards
  null to its generation server as the header x-ng-sampling: null.
- A Model Server in model_call_sampling.required_model_servers refuses a
  generation call without a segment and cannot set sampling_overrides.

Gym-only evaluation sets neither the field nor the block, so its URLs and
requests are unchanged.

Replaces NVIDIA-NeMo#4867.

Signed-off-by: Zeyu Zhou <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
zyzhou5 added a commit to zyzhou5/Gym that referenced this pull request Nov 3, 2026
… model call

A training framework that serves the policy needs every model call of the agents
it trains sampled with its own values: its training values, or its validation
values for a validation rollout. NeMo RL writes them into each row's
responses_create_params today. Harness agents reject those fields (NVIDIA-NeMo#4656), CLI
harnesses do not send them on every call, and multi-agent rows have no single
responses_create_params to write into.

The framework now sets the values on each row as _ng_model_sampling, next to
_ng_rollout_id, and leaves the task unchanged. Gym carries them into the URL of
every model call the rollout's agent makes, as /ng-sampling/<values> after any
rollout prefix. The Model Server writes them into the request before policy
admission and capture see it: temperature and top_p replace the call's, and
max_output_tokens caps the call's own limit under each endpoint's name.

- Typed rows: the collector copies the field into the episode request, and
  single_agent_turn and harbor add the segment to the agent's activation URL.
  single_agent_turn_legacy reads it from the flat row.
- Flat rows: the agent reads it from its /run body.
- Agents: an inbound segment becomes the request's, and Gym's URL helpers and
  ServerClient put it on every model URL the agent builds.
- In a run that sets the model_call_sampling block, resources servers send
  /ng-sampling/null with their model calls, so a verifier's LLM judge keeps its
  own sampling or its Model Server's sampling_overrides. vllm_model forwards
  null to its generation server as the header x-ng-sampling: null.
- A Model Server in model_call_sampling.required_model_servers refuses a
  generation call without a segment and cannot set sampling_overrides.

Gym-only evaluation sets neither the field nor the block, so its URLs and
requests are unchanged.

Replaces NVIDIA-NeMo#4867.

Signed-off-by: Zeyu Zhou <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
zyzhou5 added a commit to zyzhou5/Gym that referenced this pull request Nov 3, 2026
… model call

A training framework that serves the policy needs every model call of the agents
it trains sampled with its own values: its training values, or its validation
values for a validation rollout. NeMo RL writes them into each row's
responses_create_params today. Harness agents reject those fields (NVIDIA-NeMo#4656), CLI
harnesses do not send them on every call, and multi-agent rows have no single
responses_create_params to write into.

The framework now sets the values on each row as _ng_model_sampling, next to
_ng_rollout_id, and leaves the task unchanged. Gym carries them into the URL of
every model call the rollout's agent makes, as /ng-sampling/<values> after any
rollout prefix. The Model Server writes them into the request before policy
admission and capture see it: temperature and top_p replace the call's, and
max_output_tokens caps the call's own limit under each endpoint's name.

- Typed rows: the collector copies the field into the episode request, and
  single_agent_turn and harbor add the segment to the agent's activation URL.
  single_agent_turn_legacy reads it from the flat row.
- Flat rows: the agent reads it from its /run body.
- Agents: an inbound segment becomes the request's, and Gym's URL helpers and
  ServerClient put it on every model URL the agent builds.
- In a run that sets the model_call_sampling block, resources servers send
  /ng-sampling/null with their model calls, so a verifier's LLM judge keeps its
  own sampling or its Model Server's sampling_overrides. vllm_model forwards
  null to its generation server as the header x-ng-sampling: null.
- A Model Server in model_call_sampling.required_model_servers refuses a
  generation call without a segment and cannot set sampling_overrides.

Gym-only evaluation sets neither the field nor the block, so its URLs and
requests are unchanged.

Replaces NVIDIA-NeMo#4867.

Signed-off-by: Zeyu Zhou <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
zyzhou5 added a commit to zyzhou5/Gym that referenced this pull request Nov 4, 2026
… model call

A training framework that serves the policy needs every model call of the agents
it trains sampled with its own values: its training values, or its validation
values for a validation rollout. NeMo RL writes them into each row's
responses_create_params today. Harness agents reject those fields (NVIDIA-NeMo#4656), CLI
harnesses do not send them on every call, and multi-agent rows have no single
responses_create_params to write into.

The framework now sets the values on each row as _ng_model_sampling, next to
_ng_rollout_id, and leaves the task unchanged. Gym carries them into the URL of
every model call the rollout's agent makes, as /ng-sampling/<values> after any
rollout prefix. The Model Server writes them into the request before policy
admission and capture see it: temperature and top_p replace the call's, and
max_output_tokens caps the call's own limit under each endpoint's name.

- Typed rows: the collector copies the field into the episode request, and
  single_agent_turn and harbor add the segment to the agent's activation URL.
  single_agent_turn_legacy reads it from the flat row.
- Flat rows: the agent reads it from its /run body.
- Agents: an inbound segment becomes the request's, and Gym's URL helpers and
  ServerClient put it on every model URL the agent builds.
- In a run that sets the model_call_sampling block, resources servers send
  /ng-sampling/null with their model calls, so a verifier's LLM judge keeps its
  own sampling or its Model Server's sampling_overrides. vllm_model forwards
  null to its generation server as the header x-ng-sampling: null.
- A Model Server in model_call_sampling.required_model_servers refuses a
  generation call without a segment and cannot set sampling_overrides.

Gym-only evaluation sets neither the field nor the block, so its URLs and
requests are unchanged.

Replaces NVIDIA-NeMo#4867.

Signed-off-by: Zeyu Zhou <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
zyzhou5 added a commit to zyzhou5/Gym that referenced this pull request Nov 4, 2026
… model call

A training framework that serves the policy needs every model call of the agents
it trains sampled with its own values: its training values, or its validation
values for a validation rollout. NeMo RL writes them into each row's
responses_create_params today. Harness agents reject those fields (NVIDIA-NeMo#4656), CLI
harnesses do not send them on every call, and multi-agent rows have no single
responses_create_params to write into.

The framework now sets the values on each row as _ng_model_sampling, next to
_ng_rollout_id, and leaves the task unchanged. Gym carries them into the URL of
every model call the rollout's agent makes, as /ng-sampling/<values> after any
rollout prefix. The Model Server writes them into the request before policy
admission and capture see it: temperature and top_p replace the call's, and
max_output_tokens caps the call's own limit under each endpoint's name.

- Typed rows: the collector copies the field into the episode request, and
  single_agent_turn and harbor add the segment to the agent's activation URL.
  single_agent_turn_legacy reads it from the flat row.
- Flat rows: the agent reads it from its /run body.
- Agents: an inbound segment becomes the request's, and Gym's URL helpers and
  ServerClient put it on every model URL the agent builds.
- In a run that sets the model_call_sampling block, resources servers send
  /ng-sampling/null with their model calls, so a verifier's LLM judge keeps its
  own sampling or its Model Server's sampling_overrides. vllm_model forwards
  null to its generation server as the header x-ng-sampling: null.
- A Model Server in model_call_sampling.required_model_servers refuses a
  generation call without a segment and cannot set sampling_overrides.

Gym-only evaluation sets neither the field nor the block, so its URLs and
requests are unchanged.

Replaces NVIDIA-NeMo#4867.

Signed-off-by: Zeyu Zhou <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
zyzhou5 added a commit to zyzhou5/Gym that referenced this pull request Nov 6, 2026
… model call

A training framework that serves the policy needs every model call of the agents
it trains sampled with its own values: its training values, or its validation
values for a validation rollout. NeMo RL writes them into each row's
responses_create_params today. Harness agents reject those fields (NVIDIA-NeMo#4656), CLI
harnesses do not send them on every call, and multi-agent rows have no single
responses_create_params to write into.

The framework now sets the values on each row as _ng_model_sampling, next to
_ng_rollout_id, and leaves the task unchanged. Gym carries them into the URL of
every model call the rollout's agent makes, as /ng-sampling/<values> after any
rollout prefix. The Model Server writes them into the request before policy
admission and capture see it: temperature and top_p replace the call's, and
max_output_tokens caps the call's own limit under each endpoint's name.

- Typed rows: the collector copies the field into the episode request, and
  single_agent_turn and harbor add the segment to the agent's activation URL.
  single_agent_turn_legacy reads it from the flat row.
- Flat rows: the agent reads it from its /run body.
- Agents: an inbound segment becomes the request's, and Gym's URL helpers and
  ServerClient put it on every model URL the agent builds.
- In a run that sets the model_call_sampling block, resources servers send
  /ng-sampling/null with their model calls, so a verifier's LLM judge keeps its
  own sampling or its Model Server's sampling_overrides. vllm_model forwards
  null to its generation server as the header x-ng-sampling: null.
- A Model Server in model_call_sampling.required_model_servers refuses a
  generation call without a segment and cannot set sampling_overrides.

Gym-only evaluation sets neither the field nor the block, so its URLs and
requests are unchanged.

Replaces NVIDIA-NeMo#4867.

Signed-off-by: Zeyu Zhou <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
zyzhou5 added a commit to zyzhou5/Gym that referenced this pull request Nov 9, 2026
… model call

A training framework that serves the policy needs every model call of the agents
it trains sampled with its own values: its training values, or its validation
values for a validation rollout. NeMo RL writes them into each row's
responses_create_params today. Harness agents reject those fields (NVIDIA-NeMo#4656), CLI
harnesses do not send them on every call, and multi-agent rows have no single
responses_create_params to write into.

The framework now sets the values on each row as _ng_model_sampling, next to
_ng_rollout_id, and leaves the task unchanged. Gym carries them into the URL of
every model call the rollout's agent makes, as /ng-sampling/<values> after any
rollout prefix. The Model Server writes them into the request before policy
admission and capture see it: temperature and top_p replace the call's, and
max_output_tokens caps the call's own limit under each endpoint's name.

- Typed rows: the collector copies the field into the episode request, and
  single_agent_turn and harbor add the segment to the agent's activation URL.
  single_agent_turn_legacy reads it from the flat row.
- Flat rows: the agent reads it from its /run body.
- Agents: an inbound segment becomes the request's, and Gym's URL helpers and
  ServerClient put it on every model URL the agent builds.
- In a run that sets the model_call_sampling block, resources servers send
  /ng-sampling/null with their model calls, so a verifier's LLM judge keeps its
  own sampling or its Model Server's sampling_overrides. vllm_model forwards
  null to its generation server as the header x-ng-sampling: null.
- A Model Server in model_call_sampling.required_model_servers refuses a
  generation call without a segment and cannot set sampling_overrides.

Gym-only evaluation sets neither the field nor the block, so its URLs and
requests are unchanged.

Replaces NVIDIA-NeMo#4867.

Signed-off-by: Zeyu Zhou <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
zyzhou5 added a commit to zyzhou5/Gym that referenced this pull request Nov 10, 2026
… model call

A training framework that serves the policy needs every model call of the agents
it trains sampled with its own values: its training values, or its validation
values for a validation rollout. NeMo RL writes them into each row's
responses_create_params today. Harness agents reject those fields (NVIDIA-NeMo#4656), CLI
harnesses do not send them on every call, and multi-agent rows have no single
responses_create_params to write into.

The framework now sets the values on each row as _ng_model_sampling, next to
_ng_rollout_id, and leaves the task unchanged. Gym carries them into the URL of
every model call the rollout's agent makes, as /ng-sampling/<values> after any
rollout prefix. The Model Server writes them into the request before policy
admission and capture see it: temperature and top_p replace the call's, and
max_output_tokens caps the call's own limit under each endpoint's name.

- Typed rows: the collector copies the field into the episode request, and
  single_agent_turn and harbor add the segment to the agent's activation URL.
  single_agent_turn_legacy reads it from the flat row.
- Flat rows: the agent reads it from its /run body.
- Agents: an inbound segment becomes the request's, and Gym's URL helpers and
  ServerClient put it on every model URL the agent builds.
- In a run that sets the model_call_sampling block, resources servers send
  /ng-sampling/null with their model calls, so a verifier's LLM judge keeps its
  own sampling or its Model Server's sampling_overrides. vllm_model forwards
  null to its generation server as the header x-ng-sampling: null.
- A Model Server in model_call_sampling.required_model_servers refuses a
  generation call without a segment and cannot set sampling_overrides.

Gym-only evaluation sets neither the field nor the block, so its URLs and
requests are unchanged.

Replaces NVIDIA-NeMo#4867.

Signed-off-by: Zeyu Zhou <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
zyzhou5 added a commit to zyzhou5/Gym that referenced this pull request Nov 10, 2026
… model call

A training framework that serves the policy needs every model call of the agents
it trains sampled with its own values: its training values, or its validation
values for a validation rollout. NeMo RL writes them into each row's
responses_create_params today. Harness agents reject those fields (NVIDIA-NeMo#4656), CLI
harnesses do not send them on every call, and multi-agent rows have no single
responses_create_params to write into.

The framework now sets the values on each row as _ng_model_sampling, next to
_ng_rollout_id, and leaves the task unchanged. Gym carries them into the URL of
every model call the rollout's agent makes, as /ng-sampling/<values> after any
rollout prefix. The Model Server writes them into the request before policy
admission and capture see it: temperature and top_p replace the call's, and
max_output_tokens caps the call's own limit under each endpoint's name.

- Typed rows: the collector copies the field into the episode request, and
  single_agent_turn and harbor add the segment to the agent's activation URL.
  single_agent_turn_legacy reads it from the flat row.
- Flat rows: the agent reads it from its /run body.
- Agents: an inbound segment becomes the request's, and Gym's URL helpers and
  ServerClient put it on every model URL the agent builds.
- In a run that sets the model_call_sampling block, resources servers send
  /ng-sampling/null with their model calls, so a verifier's LLM judge keeps its
  own sampling or its Model Server's sampling_overrides. vllm_model forwards
  null to its generation server as the header x-ng-sampling: null.
- A Model Server in model_call_sampling.required_model_servers refuses a
  generation call without a segment and cannot set sampling_overrides.

Gym-only evaluation sets neither the field nor the block, so its URLs and
requests are unchanged.

Replaces NVIDIA-NeMo#4867.

Signed-off-by: Zeyu Zhou <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
RyaliNvidia pushed a commit to RyaliNvidia/Gym that referenced this pull request Nov 10, 2026
… model call (NVIDIA-NeMo#5463)

* feat(rollouts): carry a training framework's sampling values to every model call

A training framework that serves the policy needs every model call of the agents
it trains sampled with its own values: its training values, or its validation
values for a validation rollout. NeMo RL writes them into each row's
responses_create_params today. Harness agents reject those fields (NVIDIA-NeMo#4656), CLI
harnesses do not send them on every call, and multi-agent rows have no single
responses_create_params to write into.

The framework now sets the values on each row as _ng_model_sampling, next to
_ng_rollout_id, and leaves the task unchanged. Gym carries them into the URL of
every model call the rollout's agent makes, as /ng-sampling/<values> after any
rollout prefix. The Model Server writes them into the request before policy
admission and capture see it: temperature and top_p replace the call's, and
max_output_tokens caps the call's own limit under each endpoint's name.

- Typed rows: the collector copies the field into the episode request, and
  single_agent_turn and harbor add the segment to the agent's activation URL.
  single_agent_turn_legacy reads it from the flat row.
- Flat rows: the agent reads it from its /run body.
- Agents: an inbound segment becomes the request's, and Gym's URL helpers and
  ServerClient put it on every model URL the agent builds.
- In a run that sets the model_call_sampling block, resources servers send
  /ng-sampling/null with their model calls, so a verifier's LLM judge keeps its
  own sampling or its Model Server's sampling_overrides. vllm_model forwards
  null to its generation server as the header x-ng-sampling: null.
- A Model Server in model_call_sampling.required_model_servers refuses a
  generation call without a segment and cannot set sampling_overrides.

Gym-only evaluation sets neither the field nor the block, so its URLs and
requests are unchanged.

Replaces NVIDIA-NeMo#4867.

Signed-off-by: Zeyu Zhou <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* feat(harbor): keep a sidecar's own sampling in training runs

Harbor's compose sidecars, such as a simulated user, call a model server
through URLs that harbor builds for them. They are never the agent being
trained, so in a run that sets model_call_sampling their URLs now carry
/ng-sampling/null. Their calls keep their own sampling instead of failing
policy_model's missing-segment check or the training framework's check on
the policy's values.

Signed-off-by: Zeyu Zhou <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* feat(agents): carry the rollout's sampling in three agents' own model URLs

verifiers_agent, mini_swe_agent and harbor_agent build their model URLs
without Gym's URL helpers. In a training run, their calls therefore reached
the trained agent's model server without the rollout's sampling values and
were refused. NeMo RL's QA distillation recipe runs verifiers_agent this way.

- verifiers_agent uses its per-rollout client copy whenever the rollout
  carries values, not only when capture is on. The shared client's URL,
  built once for every rollout, still carries none.
- mini_swe_agent builds its model URL with base_url_for_run, as
  mini_swe_agent_2 already does. A caller's policy_base_url is still used
  as given.
- harbor_agent builds its model URL with base_url_for_run.

With observability or capture on, mini_swe_agent's and harbor_agent's calls
now also carry the rollout prefix, so they appear in per-rollout capture.

Signed-off-by: Zeyu Zhou <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(vllm_model): allow a trained agent's server to pin what the engine reports

NeMo RL's score centering pins logprobs and top_logprobs on policy_model, which
a training run lists as required, so score-centering runs failed at startup.
These fields change what the engine reports, not how it samples: both the
startup refusal and the per-call refusal now ignore them.

A real pin conflict is a configuration error, so the per-call refusal answers
409 instead of a plain error that surfaced as a retryable 500. A test also
checks that a null call's x-ng-sampling header reaches the HTTP request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Zeyu Zhou <[email protected]>

* fix(client): carry the sampling segment on an agent's self-call

ServerClient gave the current segment only to calls aimed at a model server, so
an agent calling its own /v1/responses (langgraph, haystack, finance_agent)
started a request without it, and its model calls got a 422 from a required
policy_model. Generation calls to agents now carry it too; /run does not.

apply_rollout_prefix now keeps an explicitly passed segment even with
trace_context=False, as its docstring said. CallerSamplingMiddleware declares
applies_to_mcp_requests, so a resources server that exposes tools over MCP
starts in a training run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Zeyu Zhou <[email protected]>

* fix(swe_agents): hand OpenHands the per-run URL whenever the rollout carries sampling

OpenHands ignores llm.base_url and reads the model server from the global config
unless the overlay redirects it, and the overlay was installed only under token
capture. With capture off, as in NeMo RL's SWE2 recipes, every policy call lost
the sampling segment and got a 422. Gym-only evaluation, which carries no
segment, keeps the bare URL.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Zeyu Zhou <[email protected]>

* fix(agents): keep the sampling of roles an agent runs but does not train

An agent's URL helpers gave every model URL it built the run's segment, so a
role the agent runs besides the one a training framework trains sampled with
the framework's values: tau2's simulated user, pinchbench's judge (when
judge_model_server is set) and conversational_tool_use_policy_tool_generation's
judge. On a Model Server with its own sampling_overrides, every such call
failed with 409.

url_path_for_run, base_url_for_run and resolve_model_base_url take trained=False
for such a role, which then gets null wherever the run carries a segment, and
those three agents pass it. A run without values is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Zeyu Zhou <[email protected]>

* feat(environments): refuse sampling values on environment servers that ignore them

An episode request carries a training framework's sampling values in
model_sampling, but only single_agent_turn (and its legacy variant) and harbor
put them in the trained agent's URLs. Every other environment server accepted
them and ran its agents without them: the agent the framework trains then got a
422 from its required Model Server, which agent sessions turn into failed, empty
turns, so an RL run continued, or failed much later with an unrelated error.

Environment servers now declare applies_model_sampling. An episode that carries
values is refused at admission, terminally, by a server that does not declare
it; Gym-only evaluation sends no values and is unaffected.
single_agent_turn and harbor declare it.

model_sampling_segment gives one participant's segment value: the episode's
values for a participant the framework trains, null for every other one, none
without values. single_agent_turn and harbor use it for their agent's path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Zeyu Zhou <[email protected]>

* docs(rollouts): state the sampling rules as Gym enforces them

A trained agent's server may still pin logprobs and top_logprobs. The null
header is sent on Chat Completions requests. Only model calls a resources server
makes through Gym's server client while handling a request are marked null;
judges with their own clients and agent-driven untrained roles are not yet. The
middleware comment says where it runs instead of calling it outermost.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Zeyu Zhou <[email protected]>

---------

Signed-off-by: Zeyu Zhou <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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 bug Something isn't working needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Coding-agent servers reject generation controls sent by NeMo-RL

4 participants