Background for NVIDIA-NeMo/RL #5340. All Gym links pin 9e2e5d0a, the Gym version RL pins. Read from the code, not run.
/run owned the whole episode: set up the task, loop the model and tools, ask for the reward.Three pages on this PR, one question each. This one: what each Gym server does and how the classes relate.
| Server kind | Common picture | What the code says |
|---|---|---|
| Model | a proxy to vLLM | Right. VLLMModel serves /v1/responses and forwards each call to vLLM's base_url. The policy is one model server; a judge LLM is another. |
| Agent | like Claude Code | Right. It is the harness that talks to the model. ClaudeCodeAgent is literally one; SimpleAgent is a plain model + tool loop. |
| Resources | a judge model | Not 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. |
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.
| Step | A · before: who runs it | B · now: who runs it |
|---|---|---|
RL sends one flat row to /run | Same in both: NemoGym → Gym's run_examples → the environment server's /run. RL code and data don't change. | |
| Read the row | Nobody. 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 session | SimpleAgent.run | environment server |
| ② open an agent session | — (the agent is the one running) | environment server → agent /v1/agent_sessions new step |
| ③ model + tool loop | SimpleAgent.responses, called by the agent's own run | SimpleAgent.responses, the same method, now called by the environment server |
| ④ close the agent session | — | environment server new step |
| ⑤ verify → reward | SimpleAgent.run | environment server |
| ⑥ close the task session | SimpleAgent.run | environment server (cleanup after run) |
| Save the episode at a checkpoint | SimpleAgent.run, step by step | environment 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".
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 type | Class line in Gym | Kind | What its /run does |
|---|---|---|---|
single_agent_turn | BaseEnvironmentServer[SingleAgentTurnRequest, SingleAgentTurnResponse] | typed | runs steps ①–⑥ (column B) |
single_agent_turn_legacy | SingleAgentTurnEnvironmentServer subclass | typed, despite the name | turns a flat row into an episode request, then the same run() |
harbor, swe_together, nemo_user_sim | harbor, swe_together, nemo_user_sim: BaseEnvironmentServer[XRequest, XResponse] | typed | their own episode steps |
legacy_agent | BaseEnvironmentServer, no types | untyped relay | forwards the bytes to the agent's /run; its run() just raises (column A) |
misalignment_monitored | LegacyAgentEnvironmentServer subclass | untyped relay | same 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 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 field | Filled 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_id | the 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_input | every 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).
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.