Skip to content

docs(environments): teach the typed session contract in the tutorials - #6031

Draft
yaoyu-33 wants to merge 1 commit into
mainfrom
yuya/docs-env-tutorials-typed-sessions
Draft

yaoyu-33 wants to merge 1 commit into
mainfrom
yuya/docs-env-tutorials-typed-sessions

Conversation

@yaoyu-33

@yaoyu-33 yaoyu-33 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

The environment tutorials taught the path that predates Environment Servers: an agent's /run seeds the Resources Server with the dataset row as a flat cookie seed, and the Resources Server overrides seed_session to store state. That is not how main runs new environments. Under the single_agent_turn Environment Server:

  • The Environment Server, not the agent, seeds each session with a typed ResourcesSeedSessionRequest (resources_session_id, episode_id, task_id, task_data), and it rejects a seed reply without resources_session_id (single_agent_turn/app.py L420-L451).
  • It keeps the seed reply's cookie and sends it with the agent's direct HTTP tool grant and with /verify (L436, L532, L668), then closes the session through /close_session (L639-L651).
  • SimpleResourcesServer serves seed and close through three state hooks and validates task_data against seed_request_model (base_resources_server.py L587, L1134-L1161). A repeated seed returns the existing session, and the same ID from another episode or task gets 409 (L1136-L1142). Close releases by ID and fences the session (L1163-L1190).
  • A verify for a session the server no longer holds returns lost_session_verification(), a masked sample, and a tool call for it raises ResourcesSessionLostError (404) (L394-L432, L1192-L1199).

This PR corrects the statements that contradict that and makes single_agent_turn with a typed taskset the default path. It does not rewrite the tutorials.

Page Change
stateful-environment.mdx The counter server implements has_session_state / initialize_session_state / release_session_state with seed_request_model instead of overriding seed_session. Tools raise ResourcesSessionLostError instead of creating a counter at 0. verify uses verifying() and masks a lost session instead of scoring 0. The note that told readers to re-assign state on every seed is replaced: a repeated seed is a retry and keeps its state. Adds a check_resources_session_contract test. The Environment Server seeds, verifies and closes in the flow and the transcript. Points to resources_servers/math_with_code, whose tests run the checker, as the server on main to compare with.
real-world-environment/resources-server-implementation.mdx The workplace toolkits are created and released through the hooks; tools answer a lost session with 404; the parent registers /close_session too. Notes that the shipped workplace_assistant still uses a cookie seed.
resources-server-apis.mdx Agent Server context (agent sessions; /run only behind a legacy_agent relay, not for new work); protocol table; Environment Server sequence; lifecycle API (typed seed, seed_request_model); who keeps the cookie; hooks-based state snippet; math_with_code instead of the MCP page as the hooks example; seed/verify YAML tab with single_agent_turn and a taskset; collating an example dataset; single_agent_turn_legacy for flat rows; Harbor task folders as an equal format; the Gymnasium tab names its legacy_agent relay, since no Environment Server drives that protocol yet.
single-step-environment.mdx Architecture includes the Environment Server; pseudocode of the episode; the config replaces the legacy_agent relay that gym env init generates with single_agent_turn and a taskset; the run steps collate the example taskset and drop --agent.
multi-step-environment.mdx Episode diagram and transcript show the Environment Server's seed, verify and close around simple_agent's loop.
integrate-external-environments.mdx Run the library inside an agent session driven by an Environment Server; Harbor task folders as an equal choice; no /run relay in new work.

The companion PR for the add-benchmark skill is #6032. The two were split to keep each diff reviewable.

No issue: these are corrections of docs that disagree with the code on main.

Validation

  • Ran the tutorial's counter server, copied from the page into a scratch module, against main at b02f8d0:
    • check_resources_session_contract(app, seed, keeps_state=True, holds_state=server.has_session_state, verify_body=...) passes.
    • A scripted episode: seed 200; repeated seed 200 with the counter kept; seed from another episode 409; invalid task_data 422; increment then get returns 5; verify reward 1.0 with live state released; verify retry reward 1.0 from the retained value; close 200; tool call after close 404 session_lost; verify after close masked (mask_sample: true, failure_kind: session_lost).
  • The single-step tutorial's YAML, with example_single_tool_call standing in for my_weather_tool: gym env validate reports "Config is valid" (only the model URL unset); gym dataset collate --mode example_validation writes rows with task_id.taskset == "my_weather_tool" and task_input.
  • pre-commit run --files on the six pages: passed.
  • cd fern && npm run check: 0 errors, 1 warning (the missing-redirects check is skipped without fern login; no page moved).
  • Every new internal link points to an existing page.

Rollout evidence

N/A: docs-only. No environment, agent, or verifier behavior changes, so no model run is needed.

Overlapping open PRs

Left unchanged

  • gym env init still generates a legacy_agent relay (nemo_gym/environment/scaffold.py); the single-step tutorial tells readers to replace it. Changing the scaffold is code and belongs in its own PR.
  • resources_servers/workplace_assistant and resources_servers/example_session_state_mgmt still override seed_session with a cookie seed. The tutorials no longer present them as the pattern.
  • No Environment Server drives the Gymnasium protocol, so gymnasium_agent still needs a relay; the page says so.

🤖 Generated with Claude Code

The environment tutorials taught the agent's /run path and a cookie seed
that overrides seed_session with flat row fields. Under an Environment
Server, single_agent_turn seeds each session with a typed
ResourcesSeedSessionRequest, requires resources_session_id in the reply,
keeps the session cookie, verifies, and closes the session.

- stateful-environment: implement has_session_state,
  initialize_session_state and release_session_state with
  seed_request_model; 404 for a lost session in tools; verifying() and
  lost_session_verification() in verify; check_resources_session_contract
  in tests; the Environment Server seeds, verifies and closes.
- real-world-environment/resources-server-implementation: the workplace
  toolkits move into the session hooks; tools answer a lost session with
  ResourcesSessionLostError.
- resources-server-apis: Environment Server and agent-session flow,
  seed_request_model for task_data, who keeps the cookie, hooks-based
  state snippet, math_with_code as the reference server,
  single_agent_turn with a taskset in the seed/verify YAML,
  single_agent_turn_legacy for flat rows, Harbor task folders as an
  equal choice, Gymnasium still behind a legacy_agent relay.
- single-step, multi-step, integrate-external: single_agent_turn is the
  default episode driver; a legacy_agent /run relay is not for new work.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33 yaoyu-33 added docs Documentation-only updates or documentation debt area:docs Generic documentation without another dominant domain labels Nov 12, 2026
@copy-pr-bot

copy-pr-bot Bot commented Nov 12, 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.

@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test dca2292

@github-actions

Copy link
Copy Markdown
Contributor

This branch had an error being deployed

1 failed deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:docs Generic documentation without another dominant domain docs Documentation-only updates or documentation debt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant