Repository navigation
Conversation
An agent session can now hand back token-level training data that was captured outside Gym's model server, for example by a component that records the harness's model calls next to the task sandbox. `AgentCloseSessionResponse` gains an optional `token_capture` field holding a `TokenCapture`: the captured ATIF trajectories, capture metrics, and a masked flag with its reason. After the agent session closes, the single_agent_turn environment server adds the capture to the episode result: `atif_trajectories` and `_ng_token_capture` at the top level, and `mask_sample` only when the capture is masked. The reward is unchanged and an unmasked capture never clears a mask the verifier set. The single_agent_turn_legacy flat-row wrapper keeps these fields at the top level of the row. Signed-off-by: Ananth Subramaniam <[email protected]>
Rollout collection rejected every `_ng_*` key in an environment server's typed result, so any SingleAgentTurnRequest episode that carried `_ng_token_capture` from a capture outside Gym's model server failed. Allow exactly that key; identity, failure, and assembled observation keys remain reserved for rollout collection. Co-authored-by: yaoyu-33 <[email protected]> Signed-off-by: Ananth Subramaniam <[email protected]>
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]>
…ifecycle Some training setups record a harness's model calls, with their token ids, from a component that runs next to the harness inside the task sandbox, for example a proxy the harness calls instead of the model. SandboxSession, the execute, stop, collect and release lifecycle shared by the Codex, Hermes and Pi agents, now runs such a component when one is configured, so agents do not each implement its start, collection and cleanup ordering. A capture implements the new SessionCapture interface: start returns the ModelEndpoint the harness must call, collect stops the component and returns a TokenCapture, and abort stops it without collecting. SessionCaptureConfig selects the implementation by import path with keyword options and a collect timeout; the class and its options are validated when the configuration loads, so a bad path, a class that is not a complete SessionCapture, or unknown options fail at agent startup. The adapter awaits start_session_capture before it builds the harness command and passes the endpoint to model_endpoint. Close collects the capture after the harness has stopped and before the sandbox is released (an owned sandbox is stopped, a borrowed one is handed back), at most once, and token_capture returns it for the agent's close response. A borrowed session whose harness cleanup is not confirmed defers collection to the retried close, because the harness may still be calling the component. Capture problems never fail the episode: a start that fails or is cancelled, a collection that raises or exceeds its timeout, or a session closed before the capture ran produce a masked TokenCapture with the reason, and the component is aborted under a shield so a cancelled caller cannot interrupt it. When the capture did not start, execute refuses to run the harness and session_capture_failed tells the adapter to answer the activation without it. Without a configured capture the lifecycle is unchanged. No agent opts in here; each does in its own change. Signed-off-by: Ananth Subramaniam <[email protected]>
…ailing the episode When a sandbox session's capture does not start, execute refuses to run the harness, but raising from the activation would fail the whole episode for a capture problem. harness_not_run_response gives every agent the same answer instead: a failed response with an empty assistant message, the request's model and tool fields, and the reason as its error message. harness_not_run_observations returns the matching observations, one harness_not_run gap whose detail is the reason, so the close response does not report an unrelated observation failure. The environment server then still verifies and closes the episode, its result shows why the harness did not run, and the session's masked token capture keeps the sample out of training. Signed-off-by: Ananth Subramaniam <[email protected]>
|
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. |
The capture runs only inside a SandboxSession, and agents refuse it on every other path. Naming it after the sandbox session says so where it is configured and in its error messages. The module moves to nemo_gym/agent_utils/sandbox_session_capture.py. SandboxSession keeps its session_capture field and start_session_capture method, which are already scoped by the class. Signed-off-by: Ananth Subramaniam <[email protected]>
Pi sandbox sessions can now run a configured session capture, a component in the task sandbox that records the harness's model calls. With a session_capture block, the session's SandboxSession starts the capture at seed, after the Pi runtime and runner are staged, so its endpoint is known when the activation writes Pi's provider config. The activation then takes its base URL from model_endpoint (the capture's endpoint, else the Gym model server with the rollout prefix) and uses the capture's model name for Pi's provider entry, its --model flag, and the response when the capture supplies one. The session close returns the capture as token_capture. A config that sets both model_server and session_capture is rejected when it loads, since either one alone decides where sandboxed calls go; set model_server: null to use the capture. The seed check that requires a model endpoint now accepts a session capture in place of a model server. Calls a capture serves are not attributed to a Gym model server, so the observations keep their existing model_call_ownership_unavailable gap. When the capture did not start, Pi does not run: the activation returns a failed response with an empty assistant message, the observations record a harness_not_run gap, and close returns the masked capture, so the episode is still verified. Without session_capture nothing changes; the local compatibility path keeps its own provider configuration. Signed-off-by: Ananth Subramaniam <[email protected]>
Only sandbox sessions run the capture. The local /v1/responses and /run paths called the model directly and recorded nothing, so a misrouted request produced an uncaptured rollout. They now fail with 422 before any work, matching the Codex agent. Signed-off-by: Ananth Subramaniam <[email protected]>
…ture Follows the rename of SessionCapture to SandboxSessionCapture. The field only takes effect in sandbox sessions, and Pi refuses it elsewhere, so the name now says where it applies. Signed-off-by: Ananth Subramaniam <[email protected]>
ananthsub
force-pushed
the
ananthsub/pi-session-capture
branch
from
October 9, 2026 13:20
2c43fa5 to
143129b
Compare
7 tasks done
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What changed and why
Pi sandbox sessions can now run a configured sandbox session capture: a component in the task sandbox, such as a proxy next to the harness, that records every model call Pi makes and returns those calls when the session closes. This is the first agent adoption of the sandbox session capture hooks in #4279.
With a
sandbox_session_captureblock on the Pi agent config, each session'sSandboxSessionbuilds its own capture and starts it at seed, after the Pi runtime andsandbox_runner.pyare staged and before the activation writes Pi's provider config. The activation takes its base URL frommodel_endpoint(...): the capture's endpoint when one is running, otherwise the Gym model server with the rollout prefix, exactly as before. When the capture supplies a model name, Pi uses it for thenemoprovider entry inmodels.json, for--model, and for the response'smodel. The session close returns the capture astoken_captureonAgentCloseSessionResponse.A config that sets both
model_serverandsandbox_session_capturefails validation at load with a message that says to setmodel_server: null, because each one alone decides where the sandboxed calls go. The existing seed check that rejects a session without a model endpoint now accepts a sandbox session capture in place of a model server. The local/v1/responsesand/runpaths refuse with a 422 whensandbox_session_captureis set, as the Codex agent does, because they call the model directly and the capture would record nothing.Calls that a capture serves are not attributed to a Gym model server. Pi already omits model call references when no
model_serveris configured and records amodel_call_ownership_unavailablegap, so the observations follow that existing convention unchanged.When the capture did not start, Pi does not run. The activation returns
harness_not_run_response(...), a failed response with an empty assistant message and the capture's reason; the observations hold oneharness_not_rungap with the same reason; and close returns the maskedtoken_capture. The environment server therefore still verifies and closes the episode instead of failing it for a capture problem.flowchart TD A["Seed: install Pi runtime and runner"] --> B{"sandbox_session_capture configured?"} B -->|no| D["Activation: Gym model server endpoint"] B -->|yes| C["start_session_capture()"] C -->|started| E["Activation: capture endpoint and model"] C -->|did not start| F["Activation: harness_not_run_response, no Pi run"] D --> G["Close: token_capture is null"] E --> H["Close: collected token_capture"] F --> I["Close: masked token_capture"]Without
sandbox_session_capturenothing changes: the sandbox path resolves the same model server URL throughmodel_endpoint(...), and the local compatibility path keeps_resolve_model_base_urland_build_models_config, which other harness wrappers patch. Thenemoprovider entry is now built by a shared_nemo_providerhelper used by both paths.Dependencies
Depends on #4279 (sandbox session capture lifecycle in
SandboxSessionand the harness-not-run helpers), and transitively on #4276 (SimpleResponsesAPIAgent.model_endpointandModelEndpoint) and #4278 (TokenCaptureandAgentCloseSessionResponse.token_capture). Review only the top commit until those merge.Linked issue
None; this is the Pi adoption of the sandbox session capture interface introduced in #4279.
Validation
NEMO_GYM_EXTRA_ROOTS=$PWD PYTHONPATH=$PWD python -m pytest responses_api_agents/pi_agent responses_api_agents/pi_sandboxed_agent tests/unit_tests/test_sandbox_session.py tests/unit_tests/test_base_responses_api_agent.py tests/unit_tests/test_harness_conformance_ci.py -q -p no:cacheproviderresponses_api_agents/pi_agent/tests/test_outcome.pythat need the pinned Pi CLI installed locally; they fail identically on the base branch without this change.responses_api_agents/pi_agent/tests/test_sandbox.py, using a fakeSandboxSessionCaptureselected by import path:model_servertogether withsandbox_session_captureand accepts either alone;sandbox_session_captureset, the local/v1/responsesand/runpaths answer 422 before creating an episode, starting the capture, or launching Pi;models.json,--model, and the response, does not resolve a Gym model server URL, records no model call references, and returns the collectedtoken_captureon close;harness_not_rungap, aborts the capture, and returns the maskedtoken_captureon close;token_capturewithout a capture.token_captureon close, configured model on--model).pre-commit run --fileson the changed files.Rollouts
N/A. The change wires an optional configuration hook; without
sandbox_session_capturethe sandbox and local paths produce the same provider config, command, and observations as before, which the existing Pi sandbox tests cover. A capture implementation is not part of this repository, so a smoke rollout with a real capture belongs with that implementation.Compatibility
No change for existing configs.
sandbox_session_capturedefaults tonull. Configs that set it must also setmodel_server: null. A config withsandbox_session_captureserves only agent sessions; its local paths refuse requests. The response'smodelreports the capture's model name when a capture supplies one.