How Gym's four server kinds fit together, and what the new environment server adds

Background for NVIDIA-NeMo/RL #5340. All Gym links pin 9e2e5d0a, the Gym version RL pins. Read from the code, not run.

Before
Gym had three server kinds: model, agent, resources. An agent's /run owned the whole episode: set up the task, loop the model and tools, ask for the reward.
Now
A fourth kind, the environment server (added to Gym in late September 2026), owns the episode instead. The agent only runs the model-and-tool loop.
Status
Background only, no change. PR #5340 lets turn recovery run through these environment servers. The other two pages cover that change.

Three pages on this PR, one question each. This one: what each Gym server does and how the classes relate.

Server kindCommon pictureWhat the code says
Modela proxy to vLLMRight. VLLMModel serves /v1/responses and forwards each call to vLLM's base_url. The policy is one model server; a judge LLM is another.
Agentlike Claude CodeRight. It is the harness that talks to the model. ClaudeCodeAgent is literally one; SimpleAgent is a plain model + tool loop.
Resourcesa judge modelNot quite. It holds the task's tools and the grader: /verify returns the reward. A judge is one kind of grader: e.g. equivalence_llm_judge calls a model server as the judge (here). Others grade with code, like string_match.
Environment new—Owns one episode: sets up the resources and agent sessions, starts the agent, asks for the reward, cleans up. It also enforces per-episode limits (timeout, max_concurrent_episodes) and saves the episode at a checkpoint.

One episode, before and now: the same objects, the steps move

How to read the figure. It is a composition diagram: the "what holds what" half of a UML class diagram. Both columns run the same string_match task with the same five processes, in the same rows. A dashed box is one OS process. A solid box is the object that serves it. field ──▶ X means the object holds a reference to X, and ▷ Base means it subclasses Base. An episode is six steps, ① to ⑥, numbered the same in both columns. The orange lines show which object runs each step. Compare where the orange sits: in A it is in the agent row, and in B it is in the environment row. Green boxes are the same class in both columns, and the hatched boxes are the one row whose class changes. Hover or tap a box to light up its twin.

Every name is a link to the code.
A · before: the agent owns the episodelegacy_agent relay → SimpleAgent.run (Gym 9e2e5d0a)4 calls RL→model: relay, agent /run, agent’s own /v1/responses, modelB · now: the environment server owns the episodesingle_agent_turn_legacy (Gym 9e2e5d0a; what #5340’s test runs)3 calls RL→model: env /run, agent /v1/responses, modelNeMo-RL training process · Ray actorNemoGymNeMo-RLRL’s Gym client (Ray actor); one per training runrchDeploymentRolloutCollectionHelperRolloutCollectionHelperrun_examples() → POST /run (one flat row per call){responses_create_params:…, expected_answer:"Paris", _ng_task_index:7}NeMo-RL training process · Ray actorNemoGymNeMo-RLRL’s Gym client (Ray actor); one per training runrchDeploymentRolloutCollectionHelperRolloutCollectionHelperrun_examples() → POST /run (one flat row per call){responses_create_params:…, expected_answer:"Paris", _ng_task_index:7}environment server process · legacy_agentLegacyAgentEnvironmentServerGymBaseEnvironmentServer (no [Req, Resp]: untyped)a relay: forwards /run bytes, reads neither sideconfig.agent_serversimple_agentrun_legacy(): POST agent /run with the same bytesrun(): raises — a relay has no episode stepsrow passes through unread; saves nothing at a checkpointenvironment server process · single_agent_turn_legacySingleAgentTurnLegacyEnvironmentServerGymSingleAgentTurnEnvironmentServerBaseEnvironmentServer[SingleAgentTurnRequest, …Response] (typed)config.agent_serversimple_agentconfig.resources_serverstring_match/run → run_legacy(): flat row → episode request{episode_id:{rollout_id:"r7"}, task:{task_id:"7", task_input:…}}run(): owns the episode, saves it at a checkpoint① seed: resources POST /seed_session② open: agent POST /v1/agent_sessions③ loop: agent POST /v1/responses (one call)④ close: agent POST /v1/agent_sessions/close⑤ verify: resources POST /verify → reward⑥ close: resources POST /close_session (cleanup)agent server process · simple_agentSimpleAgentGymSimpleResponsesAPIAgentthe harness; here it also runs the whole episodeconfig.resources_serverstring_matchconfig.model_serverpolicy_model/run → run() owns the episode, saves it at a checkpoint① seed: resources POST /seed_session② open agent session: — (not needed, it is the agent)③ loop: POST its own /v1/responses → responses()④ close agent session: —⑤ verify: resources POST /verify → reward⑥ close: resources POST /close_sessionresponses(): model/tool loop (step ③ body)agent server process · simple_agentSimpleAgentGymSimpleResponsesAPIAgentthe harness; now only the model/tool loopconfig.resources_serverstring_match (tools only)config.model_serverpolicy_model/v1/agent_sessions ← step ② (holds the session)responses(): model/tool loop ← step ③/v1/agent_sessions/close ← step ④/run → run(): not called any moreresources server process · string_matchStringMatchResourcesServerGymSimpleResourcesServertools + grader: /verify returns the reward/seed_session ← step ①/verify ← step ⑤ → {reward: 1.0}/close_session ← step ⑥① ⑤ ⑥ called by: SimpleAgent.runresources server process · string_matchStringMatchResourcesServerGymSimpleResourcesServertools + grader: /verify returns the reward/seed_session ← step ①/verify ← step ⑤ → {reward: 1.0}/close_session ← step ⑥① ⑤ ⑥ called by: the environment servermodel server process · policy_modelVLLMModelGymSimpleResponsesAPIModelserves /v1/responses; forwards each call to vLLMconfig.base_urlvLLM http server(s)called by: SimpleAgent.responses (step ③, same in both)model server process · policy_modelVLLMModelGymSimpleResponsesAPIModelserves /v1/responses; forwards each call to vLLMconfig.base_urlvLLM http server(s)called by: SimpleAgent.responses (step ③, same in both)POST /run (flat row)POST /run (same bytes)① ⑤ ⑥ + tool calls③ (agent → model)POST /run (flat row)② ③ ④tool calls only③ (agent → model)① ⑤ ⑥ skip the agentsame class in both columnssame role, different classorange border + orange lines = runs the episode steps ①–⑥dashed box = one OS process · solid box = one object · field ─▶ X = holds X (has-a) · ▷ Base = subclass of Base (is-a) · struck-out gray = not done here · every name is a link
StepA · before: who runs itB · now: who runs it
RL sends one flat row to /runSame in both: NemoGym → Gym's run_examples → the environment server's /run. RL code and data don't change.
Read the rowNobody. legacy_agent forwards the bytes to the agent's /run.The environment server turns it into an episode request (task_id "7" from _ng_task_index).
① seed the task sessionSimpleAgent.runenvironment server
② open an agent session— (the agent is the one running)environment server → agent /v1/agent_sessions new step
③ model + tool loopSimpleAgent.responses, called by the agent's own runSimpleAgent.responses, the same method, now called by the environment server
④ close the agent session—environment server new step
⑤ verify → rewardSimpleAgent.runenvironment server
⑥ close the task sessionSimpleAgent.runenvironment server (cleanup after run)
Save the episode at a checkpointSimpleAgent.run, step by stepenvironment server, step by step. The agent saves only its loop session.

So what maps from A to B is simple: the loop (③) stays in SimpleAgent.responses, and everything around it moves up one row, out of SimpleAgent.run and into SingleAgentTurnEnvironmentServer.run. The resources and model servers don't change at all. Only who calls them for ①⑤⑥ changes. The row that changes class is the environment server: A's is a relay that reads nothing, B's runs the steps. That is the "typed" difference, explained under the class tree below. Gym's own comment lists B's steps: "seed → invoke the agent → close the agent → verify → return", and A's: "seed → turn loop → verify".

The class tree, and what “typed” means

BaseServer reachable through ServerClient SimpleServer runs the FastAPI app modelagentresourcesenvironment (new) BaseResponsesAPIModel BaseResponsesAPIAgent BaseResourcesServer BaseEnvironmentServer[Req, Resp] SimpleResponsesAPIModel + SimpleServer SimpleResponsesAPIAgent + SimpleServer SimpleResourcesServer + SimpleServer SingleAgentTurnEnvironmentServer typed: takes an episode request VLLMModel policy, or a judge LLM SimpleAgent ClaudeCodeAgent StringMatchResourcesServer LLMJudgeResourcesServer SingleAgentTurnLegacyEnvironmentServer same server, also takes a flat row LegacyAgentEnvironmentServer untyped relay: no [Req, Resp] base class concrete server (examples) environment server Arrow with a hollow head = "is a subclass of". Other typed servers: harbor, swe_together, nemo_user_sim. misalignment_monitored is a relay.

Every server is a BaseServer, a pydantic object other servers reach by name through Gym's HTTP client. The three older kinds each have a Base… class (what the server is) and a Simple… class that adds SimpleServer (the web app). BaseEnvironmentServer extends SimpleServer directly. It is generic over its request and response types: that is what "typed" means. Each kind serves different routes. Model: /v1/responses. Agent: /run plus the newer /v1/agent_sessions. Resources: /seed_session, tools, /verify. Environment: /run with an episode request.

“Typed” is not a class or a setting in Gym. There is one base class, BaseEnvironmentServer, and every environment server subclasses it. It takes two type parameters, [Req, Resp]: the request model and the response model (its docstring: “Expose a typed episode protocol”). A subclass that fills them in and writes run() is typed. Gym checks each request against Req and runs run(), the episode steps. A subclass that leaves them out is untyped, and today that is only the relay:

Config typeClass line in GymKindWhat its /run does
single_agent_turnBaseEnvironmentServer[SingleAgentTurnRequest, SingleAgentTurnResponse]typedruns steps ①–⑥ (column B)
single_agent_turn_legacySingleAgentTurnEnvironmentServer subclasstyped, despite the nameturns a flat row into an episode request, then the same run()
harbor, swe_together, nemo_user_simharbor, swe_together, nemo_user_sim: BaseEnvironmentServer[XRequest, XResponse]typedtheir own episode steps
legacy_agentBaseEnvironmentServer, no typesuntyped relayforwards the bytes to the agent's /run; its run() just raises (column A)
misalignment_monitoredLegacyAgentEnvironmentServer subclassuntyped relaysame relay, then posts the result to a monitor

So yes, an untyped kind exists, but it is only the relay, a bridge for agents that still run the whole episode themselves. New environment servers are typed. Which kind you get is decided by which server type the config names, not by a flag. The word in #5340 comes from RL's old setup check. It refused turn recovery for every environment server whose config type was not legacy_agent, and this PR deletes it (_reject_typed_environment_servers). Watch the name: single_agent_turn_legacy is typed. Its “legacy” is about the input it accepts (next section), not about being a relay.

“Legacy” in single_agent_turn_legacy: the input is what differs

"Legacy" in single_agent_turn_legacy is about the request shape, not the server. It is the same typed server, plus run_legacy, which accepts the old flat dataset row and converts it into an episode request (_episode_request_from_row). Then it runs the exact same run(). NeMo-RL sends flat rows today, so that is the server RL talks to.

Flat row (what RL sends; legacy)

{
  "responses_create_params": {"input": [
     {"role": "user", "content": "What is the capital
      of France? Put your final answer in \\boxed{}."}]},
  "expected_answer": "Paris",
  "extraction_mode": "boxed",
  "_ng_task_index": 7,      # RL adds the _ng_ keys
  "_ng_rollout_index": 0,
  "_ng_rollout_id": "r7",
  "_ng_model_sampling": {…}
}

Episode request (typed)

{
  "episode_id": {"rollout_id": "r7", "attempt": 0},
  "task": {
    "task_id": {"taskset": "string_match",
                "task_id": "7"},   # from _ng_task_index
    "task_input": {
      "responses_create_params": {…},
      "task_data": {"expected_answer": "Paris",
                    "extraction_mode": "boxed"}
    }
  },
  "model_sampling": {…}
}
Typed fieldFilled from the flat row by
episode_id_ng_rollout_id (a restored attempt arrives as r7-a1 and is split into id + attempt), else "<task_index>-<rollout_index>". L102
task.task_idthe row's task_id / problem_id / instance_id, else str(_ng_task_index). string_match rows have none of these, so the number RL sends is the task ID. This is why #5340 must re-send the same number. materialize_task
task.task_inputevery key not starting with _ng_. Extra fields go into task_data, which the resources server's /verify reads. SingleAgentTurnTaskInput
model_sampling_ng_model_sampling: RL's temperature, top-p and so on, put into the agent's model URL.

The reply is shaped to match: a flat row gets a flat result dict back (_legacy_result), and an episode request gets a typed {episode_id, task_id, result | failure}.

The other "legacy" server, legacy_agent, converts nothing. It forwards the flat row to an agent that still runs the whole episode itself, the left column above (its docstring).

So what for #5340. Turn recovery used to work only with the left column: the agent owned the episode, and legacy_agent saved nothing. The PR lets it run through the right column. There the environment server owns and saves the episode, and it checks that a resumed episode has the same task_id. Because string_match's task_id comes from _ng_task_index, RL must re-send the same number. The environment server is also where max_concurrent_episodes lives, which is the open problem on the third page.