Repository navigation
feat(agents): deliver per-task agent context to agent sessions - #5703
Merged
Merged
Conversation
An agent session gets its initial model input and its grants, but no task data. Harnesses that build part of their input from the task row, such as gdp_pdf_agent's document manifest, labbench2_vlm_agent's media directory and CritPt's formatting prompt, had no supported way to receive it under single_agent_turn. A task row now carries that data in a reserved agent_context key: small inline values (at most 64 KiB) and artifact references, paths relative to a root the agent configures. SingleAgentTurnTaskInput lifts it out of task_data, so the Resources Server never receives it, and single_agent_turn passes it in AgentSeedSessionRequest.agent_context, omitted when empty. Each agent declares the keys it reads in agent_context_model. The base seed refuses with a terminal 422 a context the agent declares no model for, an undeclared key, a missing required key or a mistyped value, so a task never runs without data it was given. Agents read the typed context with parse_agent_context() and resolve artifacts with resolve_agent_context_artifact(), which refuses paths that leave the root. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
Contributor
Author
|
/ok to test c7831a5 |
…idation A server's TaskData schema validates the task-owned fields of a row and reports unknown keys. agent_context goes to the agent session, never to the Resources Server, so it joins RESERVED_ROW_KEYS instead of showing up as an unknown task field. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
Contributor
Author
|
/ok to test fb7fa47 |
Contributor
…tate An agent whose task context lives in its session state, such as a document or media to put in the model request, had to override responses() to reach that state from the episode it creates. Environment validation then infers custom-gym-agent-loop for it, though the agent loop is still Simple Agent's. responses() now creates a session activation's episode through _create_session_episode(state, body, **kwargs), which by default calls _create_episode. A subclass overrides it to use the session's context and leaves responses() and the agent loop alone. The sessionless path is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
Contributor
Author
|
/ok to test 48257f7 |
…ssions Signed-off-by: yaoyu-33 <[email protected]>
…erifier - Refuse an artifact path with a NUL byte at validation, and turn a path the filesystem cannot look up (name too long, no permission) into a 422 seed refusal instead of a 500; other OS errors stay retryable. - Count the 64 KiB values limit in UTF-8 bytes, not ASCII-escaped JSON. - Treat an empty agent_context as none in the task input and the seed, so the seed and task digest match a row without the key and an agent server that predates the key still accepts the seed. - Skip a task_data container's agent_context in dataset validation, as the task input lifts it out. - single_agent_turn_legacy: answer a row that fails the episode request model with the typed /run's 422. - Re-verification no longer sends a stored agent_context to the Resources Server's /verify. - Docs and helper docstring: a Simple Agent subclass resolves context in _new_session_state (restores rebuild through it) and overrides _create_session_episode, never responses(); configure the real directory as the root; files under a directory artifact are the agent's to confine. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
Contributor
Author
|
/ok to test 62d6961 |
Contributor
Author
|
/ok to test dee2b2c |
Signed-off-by: yaoyu-33 <[email protected]>
Contributor
Author
|
/ok to test 08032a7 |
Signed-off-by: yaoyu-33 <[email protected]>
Contributor
Author
|
/ok to test 7b3a26f |
Signed-off-by: yaoyu-33 <[email protected]>
Contributor
Author
|
/ok to test a8f97fb |
This was referenced Nov 11, 2026
Signed-off-by: yaoyu-33 <[email protected]>
Contributor
Author
|
/ok to test 3be1f4c |
Signed-off-by: yaoyu-33 <[email protected]>
Contributor
Author
|
/ok to test dc4c964 |
Signed-off-by: yaoyu-33 <[email protected]>
weijiac0619
approved these changes
Nov 13, 2026
Contributor
Author
|
/ok to test 39da43a |
kajalj22
approved these changes
Nov 13, 2026
Contributor
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/43466167688 |
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 and why
Agent sessions have model input and tool/sandbox grants, but no explicit channel for task data used by the harness itself. PDF and vision agents need document or media references; a staged agent may need a formatting prompt for a later model call. This PR adds
AgentSeedSessionRequest.agent_contextfor that data.A row's context is keyed by participant role. An episode can seed several agents (UserSim seeds a user and an assistant), so a task row's
agent_contextmaps each role to the context that role's session receives. Each Environment Server names its roles, refuses a role it does not have, and sends each role's context in that session's seed. The seed contract stays singular: oneAgentContextper session.flowchart TD T["Task row: agent_context by role"] --> E[Environment Server] E -->|"role A's context"| A[Agent session A] E -->|"role B's context"| B[Agent session B]single_agent_turnhas one role,agent:Its task-input model lifts the field out of
task_data, refuses any other role (including the unkeyed{"values": ..., "artifacts": ...}shape) with 422, and forwards theagentcontext to the agent seed. Initial messages stay inresponses_create_params.input; the Resources Server receives task data without agent context. Environments that send no context (Harbor, UserSim, SWE-Together) refuse the key.Contract
AgentContext.valuescarries small inline JSON fields.artifactscarries file/directory references relative to an agent-configured root; file contents do not travel in the seed. Each role's context is limited to 64 KiB of UTF-8 JSON, and a key cannot appear in both maps.AgentContextand its artifacts are frozen.agent_context_modeland reads the typed value withparse_agent_context(). Seeding returns terminal HTTP 422 for undeclared, missing, mistyped, or incorrectly channelled context. Artifact fields useartifacts; other fields usevalues. Parsing copies mutable inline input so it cannot rewrite the saved seed.SimpleAgent._create_session_episode()lets a subclass use session context when preparing a model request while retaining the existing agent loop.agent_context, at the top level or insidetask_data, before sandbox or agent setup. UserSim and SWE-Together already reject unsupported context through their input schemas; this PR records that behavior in tests. Environments must consume supplied context explicitly or reject it.agent_contextremains excluded from Resources ServerTaskDataschema projection. This does not declare support in every environment: validation leaves the source row unchanged, collation preserves context, and the destination environment validates its own input. A regression test covers that distinction through actual collation and Harbor validation.Compatibility and consumers
{},{"agent": null}and{"agent": {}}count as no context./runpath still receives the whole row; thesingle_agent_turn_legacyadapter uses the scoped single-agent contract and returns 422 for invalid rows./verifyboundary for native and ATIF inputs, including nestedtask_data.agent_context.labbench2_vlm_agent(feat(labbench2_vlm_agent): embed the task's media in agent sessions #5704),gdp_pdf_agent(feat(gdp_pdf_agent): deliver the document in agent sessions #5706), and SciCode (feat(scicode): run the SciCode sub-step loop in agent sessions #5824). feat(labbench2_vlm_agent): embed the task's media in agent sessions #5704 and feat(gdp_pdf_agent): deliver the document in agent sessions #5706 write the role-keyed shape; feat(scicode): run the SciCode sub-step loop in agent sessions #5824 still writes the unkeyed shape and needs the same change. This PR does not change benchmark scoring.No separate public issue: this PR establishes the session contract used by those focused follow-ups.
Validation
Conflict resolution (
39da43a03511064edf4f2e21a4f6600ee14bf35e, 2026-11-12, workstationws)Merged
mainat1f88c43d55b61143378b0823ad9ce45d85cd4f16. The sole textual conflict was in SWE-Together tests; the resolution preserves both agent-context rejection coverage and main's skip-token-capture activation coverage.python -m pre_commit run --all-filesandgit diff --checkpassed. Hooks left the source unchanged.python -m pytest \ tests/unit_tests/server_runtime/test_agent_context.py \ tests/unit_tests/agents/test_agent_context.py \ tests/unit_tests/agents/test_agent_sessions.py \ tests/unit_tests/agents/test_base_responses_api_agent.py \ tests/unit_tests/data/test_task_data.py \ tests/unit_tests/eval/test_rollout_reverification.py \ tests/unit_tests/server_runtime/test_checkpoint_identity.py \ tests/unit_tests/server_runtime/test_checkpoint_participant_workers.py \ responses_api_agents/simple_agent/tests/test_app.py \ environment_servers/single_agent_turn/tests \ environment_servers/single_agent_turn_legacy/tests \ environment_servers/harbor/tests/test_app.py \ environment_servers/swe_together/tests/test_environment.py \ tests/unit_tests/test_public_api.py \ tests/unit_tests/test_public_api_facades.py \ tests/unit_tests/test_import_linter_coverage.py \ tests/unit_tests/test_orchestration_boundary.py \ --import-mode=importlib -q -o addopts= -o log_cli=false \ --junitxml="$task_root/evidence/tests.xml"Main checkpoint integration (
dc4c9647f36b709a3fb7b6e8ae2175219420d09e, 2026-11-12, workstationws)pre-commit run --all-filespassed on the final tree, with no generated edits. Independent source review found no remaining blocker.At
79b7c92c1(role-keyedagent_context, withaeee565f9merged), on a Linux workstation with Python 3.13.14: the suites listed below plustests/unit_tests/data/tasks/harbor,tests/unit_tests/test_moved_paths.pyandtests/unit_tests/test_public_api.py: 2,980 passed, 35 failed, 31 errors. The same 66 tests fail the same way atccd50dc04, the previous head (2,966 passed there), from that workstation's environment: nojinja2, noharbor.models, agitwithoutinit -b, and no git checkout for repository data discovery.TestRepoDataMatchesSchemaspasses in a git checkout of #5704 and #5706, which contain this head.pre-commit run --files <changed files>: clean. New tests:test_single_agent_turn_refuses_a_role_it_does_not_have(the unkeyed shape and unknown roles, at the top level and insidetask_data),test_the_size_limit_applies_to_each_roles_context, and digest pins for{"agent": null}and{"agent": {}}.At
12eb72992: mainf636596db(documentation only) merged into79b7c92c1. Its guide edit conflicted with theagent_contextmention in the seed-request paragraph; the resolution keeps both.test_fern_docs_links.py: 29 passed.Earlier, at
ccd50dc04: executed on the Linux workstation with Python 3.13.14 against the source published asccd50dc046212c3116147b110bb8baa2b2477f8f. Imports were checked to resolve to that source, using a task-specific interpreter; shared environments were not modified.2,409 tests passed across the context contracts, agent sessions, task-data validation, reverification, Simple Agent, affected environments, and public API checks.
pre-commit run --all-files: passed, including import-linter.cd fern && npm run check -- --warnings: zero errors; authenticated missing-redirect check skipped because Fern credentials were unavailable.git diff --check: passed.Model smoke
Real inference through Gym's stock
vllm_modeladapter againstnvidia/nemotron-3.5-super-vl-120b-a12b, with the stock Simple Agent loop andexample_single_tool_callweather verifier. A task-only Simple Agent subclass declared a city value plus an instruction-file artifact; a recording resources subclass retained the original tool and verifier behavior.get_weather(city="Tokyo")get_weather(city="Sydney")get_weather(city="Paris")The two context rollouts ran concurrently with distinct session IDs. The stock agent refused undeclared context with HTTP 422. All six resource seed/verify requests excluded
agent_context, and all six server processes exited cleanly. Inputs, outputs, model-call capture, seed/resource records, configuration, and cleanup receipts were retained with the workstation evidence. This verifies the shared contract with a real model; downstream PDF/image benchmarks retain their own rollout requirements.Role-keyed rows, real model (2026-11-09, at this head through #5704 and #5706). The shipped
labbench2_vlmandgdp_pdfconfigs (single_agent_turn_legacy) ran their example rows written as{"agent": {...}}with hostednvidia/nemotron-3.5-super-vl-120b-a12bas policy and judge. Every policy request (4 labbench2 rows, 3 GDP.pdf documents with 10, 4 and 5 page images) had the same SHA-256 as the session run of the unkeyed rows earlier that day, so keying by role changes nothing the model sees. A row in the unkeyed shape was refused by the Environment Server with 422 attask.task_input.agent_context, with no model call, and the refusal message reached the failures file. Details are in #5704 and #5706.🤖 Generated with Claude Code