Repository navigation
docs(architecture): describe Environment Server episode orchestration - #4711
Conversation
Add the Environment Server to the architecture page: a table row, an episode lifecycle (seed, agent loop, close and verify, clean up) with a sequence diagram, a server-type section, a sandbox-ownership note and a sandbox-transport note. Split from #3917 so the concept change can be reviewed on its own; the harness guide and agent-server pages follow. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
yaoyu-33
left a comment
There was a problem hiding this comment.
Team review of #4711 (docs only: about/architecture.mdx).
The native single_agent_turn flow on this page matches the code step for step: endpoint order, activation, close before verify, cleanup on failure, sandbox ownership for SWE-bench Pro and Terminal Bench 2.1, and the provider transports. Links and the new #environment-server anchor that #4712 and #4713 rely on resolve, the Mermaid diagram renders, and test_fern_docs_links.py and fern check pass.
The inline comments cover one issue: the page now presents the native Environment Server flow as the only one, while the legacy_agent relay is still the default path. The agent-owned flow is still described in system-design.mdx and resources-server-apis.mdx, but it is gone from this overview page, which tutorials link to for the full architecture.
Process
- CI has not run yet; copy-pr-bot is waiting for
/ok to test <sha>. - Two checklist boxes are unchecked: "read the contributing guidelines" and "the change is focused".
Not in this PR's scope: the unchanged "Retry logic with exponential backoff (3 attempts)" bullet (L106) is inaccurate for calls between Gym servers (fixed 0.5 s delay; ServerClient calls retry without the 3-attempt cap, server_utils.py L765-782). AGENTS.md repeats the claim, so it fits a separate small PR.
Reviewed by 4 agents (core-library expert, bug finder, test agent, devil's advocate) plus a stack-wide comment reviewer.
Generated by Claude Code
| E->>R: close_session | ||
| ``` | ||
|
|
||
| The Agent Server does not decide when to verify. The Environment Server orders the calls, so a different agent or a different benchmark can be swapped in through configuration, with no pair-specific launcher. The built-in `single_agent_turn` Environment Server runs one agent turn against one Resources Server. Other interaction patterns, such as a simulated user, define their own Environment Server. |
There was a problem hiding this comment.
[DOC] RISK. The new steps (L37-42) and this paragraph read as if every episode runs this way. Most shipped configurations still run through the legacy_agent Environment Server (about 515 YAML files, against 6 that use single_agent_turn or single_agent_turn_legacy), and Gym generates that relay for any agent that no Environment Server names (global_config.py#L1150-L1157). On that path the agent's own /run calls seed_session and verify (simple_agent/app.py#L811-L813, #L909), and calls /close_session only when checkpointing is on (#L944-L946). Tutorials such as single-step-environment.mdx send readers here for the full architecture, so could we scope this paragraph to native Environment Servers and keep a short description of the relay path? The same scoping is suggested at L37, L74, and L25.
| The Agent Server does not decide when to verify. The Environment Server orders the calls, so a different agent or a different benchmark can be swapped in through configuration, with no pair-specific launcher. The built-in `single_agent_turn` Environment Server runs one agent turn against one Resources Server. Other interaction patterns, such as a simulated user, define their own Environment Server. | |
| With a native Environment Server, the Agent Server does not decide when to verify. The Environment Server orders the calls, so a different agent or a different benchmark can be swapped in through configuration, with no pair-specific launcher. The built-in `single_agent_turn` Environment Server runs one agent turn against one Resources Server. Other interaction patterns, such as a simulated user, define their own Environment Server. | |
| Most shipped configurations still use the `legacy_agent` Environment Server, which Gym also generates by default for any agent that no Environment Server names. It relays `/run` to the agent, and the agent runs the whole episode itself, including any `seed_session` and `verify` calls. Cleanup then depends on the agent, so Resources Servers on this path usually release per-task state in `verify()` (see [Session Cleanup](/main/environment-tutorials/resources-server-apis#session-cleanup)). For that request flow, see [System Design](/main/infrastructure/engineering-notes/system-design). |
| │ → text, tool calls, │ │ my_tool(): execute action │ | ||
| │ or code │ │ verify(): evaluate → reward │ | ||
| └───────────────────────────┘ └────────────────────────────────────┘ | ||
| Each task attempt is an *episode*. An Environment Server runs it in order, and the resulting trajectory is called a *rollout*: |
There was a problem hiding this comment.
[DOC] RISK (same finding as L68). Scope the ordered steps to native Environment Servers, since legacy_agent relays /run and the agent orders the calls itself (legacy_agent/app.py#L110-L122).
| Each task attempt is an *episode*. An Environment Server runs it in order, and the resulting trajectory is called a *rollout*: | |
| Each task attempt is an *episode*. Rollout collection sends every episode to an Environment Server. A native Environment Server, such as `single_agent_turn`, runs it in this order, and the resulting trajectory is called a *rollout*: |
|
|
||
| ### Environment Server | ||
|
|
||
| Orchestrates one episode: it seeds the Resources Server and Agent Server sessions, activates the agent, closes the agent session, verifies, and cleans up, including on failure. It binds an agent and a resources server by reference and exposes a `/run` endpoint that rollout collection submits tasks to. It does not implement tools, agent logic, or scoring. |
There was a problem hiding this comment.
[DOC] RISK (same finding as L68). Only native Environment Servers bind an agent and a Resources Server and run the cleanup context. legacy_agent binds only agent_server (legacy_agent/app.py#L57-L62) and routes /run straight to its relay, bypassing run_request and its cleanup (#L88-L92, base_environment_server.py#L238-L249).
| Orchestrates one episode: it seeds the Resources Server and Agent Server sessions, activates the agent, closes the agent session, verifies, and cleans up, including on failure. It binds an agent and a resources server by reference and exposes a `/run` endpoint that rollout collection submits tasks to. It does not implement tools, agent logic, or scoring. | |
| Is the entry point for each episode: rollout collection submits tasks to its `/run` endpoint. A native Environment Server, such as `single_agent_turn`, binds an agent and a Resources Server by reference and orchestrates the episode: it seeds the Resources Server and Agent Server sessions, activates the agent, closes the agent session, verifies, and cleans up, including on failure. The `legacy_agent` Environment Server binds only an agent and relays `/run` to it, so that agent runs the episode. An Environment Server does not implement tools, agent logic, or scoring. |
| | Agent Harness | FastAPI Agent Server | | ||
| | Verifier + State | FastAPI Resources Server | | ||
| | Model | FastAPI Model Server or managed by your own agent harness | | ||
| | Episode orchestration | FastAPI Environment Server, which binds an agent and a Resources Server and runs one episode | |
There was a problem hiding this comment.
[DOC] RISK (same finding as L68). The table row has the same scope; this wording mirrors new-environment.mdx.
| | Episode orchestration | FastAPI Environment Server, which binds an agent and a Resources Server and runs one episode | | |
| | Episode orchestration | FastAPI Environment Server, the entry point for each episode. A native one binds an agent and a Resources Server and runs the episode; `legacy_agent` relays it to an agent that runs it | |
… Servers Most shipped configurations still run through the legacy_agent relay, where the agent seeds and verifies itself. Scope the ordered steps, the component table row, the Environment Server section, and the sandbox-ownership note to native Environment Servers, describe the legacy_agent path, and stop saying that agent harnesses orchestrate rollouts. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
|
Looks good to me overall. One question before approving, about the Communication section: The unchanged bullet "Retry logic with exponential backoff (3 attempts)" doesn't match Either order works, but both PRs touch neighbouring lines in |
|
/ok to test efc52a6 |
Signed-off-by: yaoyu-33 <[email protected]>
|
/ok to test f648c49 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/39487822094 |
What does this PR do?
Describe the Environment Server on the architecture page. The page still shows the agent calling
seed_sessionandverifyitself; with a native Environment Server, such assingle_agent_turn, it orders those calls.legacy_agentrelay, which most shipped configurations still use: the agent runs the whole episode itself, includingseed_sessionandverify.This is the architecture-only part of draft #3917, split out so the concept change can be reviewed on its own. It is the bottom of a three-PR stack:
Tracks GYM-1011.
Validation
October 20 main sync (
f648c4987fb7313ef0ef7579da3f7aa8db311a7f)Synchronized the stack with main
1266a119a7606124f7f6c367a78d9b2e191eddf6using signed-off merge commits. Main already contains the mini-SWE dependency/runtime isolation fixes in #4733 and #4735 for the required shard-2 failure observed on #4711. The approved documentation is byte-for-byte unchanged from the preceding source commit, and the diff against the updated stack base remains documentation-only.Validation on this synchronized tree:
tests/unit_tests/test_fern_docs_links.py: 24 passed, 21 subtests passed.npm run checkinfern/: 0 errors, 1 warning.pre-commit run --all-files: all applicable hooks passed.git diff --check: passed; no runtime changes relative to the updated base.Final diff
e0a18be3d:pre-commit run --all-files: all applicable hooks passed.python -m pytest tests/unit_tests/test_fern_docs_links.py: 24 passed.fern check --warningswith a cached Fern CLI: 0 errors, 1 warning (redirect validation is skipped without Fern authentication).Review fixes (
efc52a63f) scope the episode steps, the table row, the Environment Server section, and the sandbox note to native Environment Servers, and add thelegacy_agentparagraph. After them:python -m pytest tests/unit_tests/test_fern_docs_links.py: 24 passed.pre-commit run --files fern/versions/latest/pages/about/architecture.mdx: passed.fern checkand the Mermaid render (the diagram is unchanged).Not done: a full-page Fern preview.
Rollouts
N/A: documentation only; no runtime behavior changed.
Compatibility and benchmark impact
None. Compared with the architecture changes in #3917, the sandbox-ownership note no longer links to the harness guide, which lands in the next PR.
Checklist
pre-commit run --all-files) (so CI lint/format checks pass).git commit -s) (so the DCO check passes).🤖 Generated with Claude Code