AI State of the Art
SOTA/Alignement : instruction, RLHF, DPO et apprentissage par renforcement/35 min
Section 117

Training LLM Agents with RL: Rollouts, Environments, Off-Policyness

Listen as a podcast β†’

A story: a restaurant kitchen in the middle of a rush

Picture a kitchen. On one side, cooks (the generators) churning out dishes nonstop: each one is an attempt, a try of the day. On the other side, a chef (the learner) who tastes every dish, scores it, and adjusts the shared recipe. If the cooks wait for the chef after each dish, everyone keeps stopping: the kitchen sits idle. If the chef is slow to taste, the cooks keep cooking from the old recipe in the meantime, their dishes no longer reflect the latest adjustments.

This is exactly the engineering problem of training an agent with reinforcement learning (RL): learning by trial, reward and correction rather than by copying examples. The agent here is an LLM (large language model). The model must produce attempts (generate), we must score them, and we must adjust the model (update). Running this loop at scale, across hundreds of GPUs (graphics processing units, the accelerator cards these models run on), without anyone waiting on anyone, is as much a systems problem as an AI one.

This page is about that plumbing: the loop, why it's heavy, what a rollout is, what off-policyness is, what environments and verifiable rewards are, and why generated code runs in a sandbox.

Two neighbouring pages complete this one: Training an agent: why it isn't the same problem for what changes inside the algorithm, and Building the worlds for how environments get manufactured. The basics of reinforcement learning (state, action, reward) are laid out in Reinforcement learning: core principles.

The fundamental RL loop for LLMs

At the core, three steps run in a circle:

  1. Rollout generation. The model (the policy, i.e. the model's current strategy, the set of its weights) is given a task and produces a trajectory: its answer, its reasoning, and, for an agent, the whole sequence of actions it took (call a tool, read a file, run code, retry). That complete trajectory is the rollout.
  2. Scoring / reward. We evaluate the rollout. The reward rr is a single number saying "how successful was it". For an agent, it isn't just one correct word: it's "was the task actually accomplished?".
  3. Policy update. An RL algorithm (PPO (Proximal Policy Optimization), GRPO (Group Relative Policy Optimization)) uses these rewards to adjust the weights: reinforce what worked, dampen what failed. Then repeat.
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚                                                β”‚
        β–Ό                                                β”‚
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”    rollouts    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    rewards    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚  POLICY  β”‚ ─────────────▢ β”‚  SCORING β”‚ ────────────▢ β”‚  UPDATE  β”‚
   β”‚ (the LLM)β”‚ (trajectories) β”‚ (verifierβ”‚   r ∈ [0,1]   β”‚(PPO/GRPO)β”‚
   β”‚          β”‚                β”‚ /reward) β”‚               β”‚          β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β–²                                                      β”‚
        └──────────────  new weights  β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Rollout: the word to remember

A rollout is a game played to the end. For a chatbot, it's one answer. For an agent, it's the whole session: think, call tools, observe results, course-correct, all the way to the final verdict. An agent rollout can therefore be very long and expensive to produce, and that is precisely where the engineering difficulty lies.

What is learned, what stays frozen, what is recomputed

Not everything in this loop has the same status, and that is the first thing readers conflate. Three categories, worth keeping in mind throughout:

ItemRoleStatus
The policy weightswhat we are trying to improvelearned, they change at every update
The reference modela copy of the policy taken before training, used to measure how far we have driftedfrozen, never updated
The verifierobserves success (runs the tests, compares the answer)plain code, nothing to learn
Rollouts and their rewardsthe attempts and their scoresrecomputed every iteration, then discarded

In other words: exactly one object learns, and the trajectories it learns from are consumables. When the algorithm is PPO there are in fact four models in memory (trained policy, trained critic, frozen reference, frozen reward model); the exact count, with the memory arithmetic, is done in RLHF in practice and is not repeated here.

Layered diagram of an agentic RL system. At the top, a Training layer with the veRL framework. Below it, a Serving layer with three vLLM instances and a Replay Buffer. In the middle, three services: Agent Scheduler, Proxy Server and Agent Tracer. Below that, an Agent Rollout layer with two custom agents each running four tasks. At the bottom, an Other Service layer containing an MCP service and a tool service.
What the plumbing described on this page actually looks like. The two worlds are clearly separated: at the top the side that trains (veRL, a reinforcement-learning training library) and the side that generates (the vLLM servers, an inference engine specialised in emitting text fast), and at the bottom the agent rollouts, each running tasks and calling external tools. The middle components do nothing but schedule and trace those round trips; MCP there is the Model Context Protocol, the convention by which an agent discovers and calls tools.Source : Jiachen Liu, blog, When LLMs Grow Hands and Feet, How to Design our Agentic RL Systems?

The flaw in the synchronous loop that decoupling fixes

In one sentence: in a synchronous loop, generating and training take turns on the same cards, so each side waits for the other and the most expensive hardware in the system sits half idle; decoupling removes the waiting, at the cost of a lag that then has to be corrected.

Generation and training fight over the same cards

The subtlety is that the two compute-hungry phases (generating (running inference) and training (running backpropagation)) are two very different uses of the same expensive hardware.

  • Generating an agent rollout is slow: the model emits tokens one at a time, waits for a tool's result, emits more. Meanwhile the GPUs spend a lot of time waiting.
  • Training wants GPUs saturated at 100 %, in large batches, to be efficient.

If we do everything on the same GPUs by taking turns (generate, then stop, then train, then stop), we waste enormous amounts of capacity. Hence the asynchronous, distributed architecture: we physically separate generators (often called actors or rollout workers) that do nothing but produce trajectories continuously, from learners that do nothing but consume them to update the weights. The new weights are then shipped back to the generators.

The key idea: decouple so nobody waits

Rather than a synchronous loop where each side waits for the other, we let the generators run nonstop and the learners consume a stream of rollouts. Nobody sits idle. It's the same principle as an assembly line: you don't stop the entire conveyor belt to tune one machine.

Two diagrams side by side. On the left, synchronous RL: a single loop alternates between an inference engine (vLLM, SGLang) and a training engine (FSDP, Megatron, Torchtitan), linked by a weight sync and a training batch, with all arrows synchronous. On the right, decoupled asynchronous RL: the inference engine samples trajectories continuously into a Trajectory Buffer; the training engine pulls batches from it, updates the weights and publishes them through a Checkpoint Engine that syncs them back to the inference engine, these exchanges being asynchronous (dashed arrows).
On the left, the synchronous loop: generation and training hand off to each other, so each side waits. On the right, the decoupled version: a trajectory buffer sits between them, so the generators never stop and new weights arrive whenever they arrive. vLLM and SGLang are inference engines; FSDP, Megatron and Torchtitan are libraries for spreading training across many cards. Those dashed arrows are exactly where the off-policyness described below comes from.Source : Luke J. Huang, Is Frontier Asynchronous RL Solved?

On-policy vs off-policy, and the off-policyness problem

This decoupling creates a conceptual problem. Let's define things cleanly first:

  • On-policy : we train the model on data it just produced itself, in its current version. Recipe and cook are in sync.
  • Off-policy : we train the model on data produced by a different (usually slightly older) version of itself.

In an asynchronous system, by the time a long agent rollout has been generated and scored, the learner has already updated the weights several times. The rollout was therefore produced by a slightly stale policy. That's off-policyness: a gap between the policy that generated the data and the policy currently being trained.

Why does it matter? Because RL algorithms in theory assume you learn from your own current actions. If the gap is large, updates point in the wrong direction and training becomes unstable, or even diverges.

How off-policyness is mitigated

Several levers, often combined:

  1. Bounding staleness. We set a limit: only accept rollouts produced by a policy at most kk updates behind. Too old β†’ discard. This trades throughput (rollouts produced per hour) against the correctness of each update.
  2. Importance sampling. We mathematically correct the gap by reweighting each sample with the importance ratio:

ρi=πθ(yi∣x)Ο€old(yi∣x)\rho_i = \frac{\pi_\theta(y_i \mid x)}{\pi_{\text{old}}(y_i \mid x)}

Symbol by symbol:

  • ρi\rho_i (the Greek letter rho) is the weight we will give to sample number ii;
  • πθ\pi_\theta is the policy being trained, the Greek letter pi conventionally denotes a policy, and ΞΈ\theta its parameters, i.e. the weights that move;
  • Ο€old\pi_{\text{old}} is the earlier version of that same policy, the one that actually produced the rollout;
  • xx is the task we handed over, yiy_i the action or answer produced;
  • Ο€(y∣x)\pi(y \mid x) reads "the probability that this policy produces yy when given xx".

In one sentence: the numerator says how likely today's policy would have been to produce this action, the denominator how likely yesterday's policy was to produce it, and their ratio corrects the discrepancy. An action that is now unlikely counts for less; one that is now likely counts for more. It's the very term you find in PPO and GRPO.

  1. Clipping and a proximity constraint. We bound that ratio to stop an overly off-policy sample from triggering a brutal update. The usual bound comes straight from PPO, which allows a relative deviation Ξ΅\varepsilon of 0.20.2: the ratio is therefore held between 1βˆ’0.2=0.81 - 0.2 = 0.8 and 1+0.2=1.21 + 0.2 = 1.2. That Ξ΅\varepsilon is a knob, not a law of nature; it is the "proximal" in PPO's name.
The throughput ⇄ freshness trade-off

The more stale rollouts you tolerate, the faster the system runs (generators never stop) but the more training risks instability. The fresher you require rollouts to be, the cleaner training is (closer to on-policy) but the more generators wait for new weights. Tuning this dial is one of the central crafts of RL engineering for agents. What breaks when you run RL on an LLM describes what you see when the dial is set wrong.

Environments and verifiable rewards

To train an agent you need an environment: the playground where it acts and that reacts to its actions. An environment is a task plus a way to observe the outcome. For example: "here is a code repository with a bug and a test suite; fix the bug", the environment is the repo, the tests, and the machine that runs them.

The crucial piece is the verifiable reward. For many domains, success can be observed automatically and objectively, with no human judge and no learned reward model:

  • Code: does the program pass the test suite? Yes / no.
  • Math: does the final answer equal (numerically or symbolically) the solution? Yes / no.
  • Databases: does the query, written in the standard query language SQL (Structured Query Language), return exactly the right result? Yes / no.

This is the RLVR principle (Reinforcement Learning with Verifiable Rewards, see Reward modeling and RLVR), carried over to agents: the reward is exact, automatic, and hard to game. Where RLHF trains a reward model to learn what humans prefer, here there is nothing to learn: the score is computed by a piece of code.

Diagram of the RLVR system. A Training data block sends prompts s_i to an Agent block representing the policy pi_theta. The agent produces completions a_i that feed back into a Verifiable Reward block, which returns a scalar reward r_i equal to gamma if the answer is correct and zero otherwise. Below the agent is the policy update rule by gradient ascent.
The RLVR loop in its barest form. What sets it apart from classic RLHF sits in the top box: the reward is not a model trained to imitate human preferences, but a plain binary rule, correct or not. Nothing is hand-annotated, so nothing stops you from producing millions of them.Source : RLHF Book, Nathan Lambert (Reasoning chapter)
Why this is a turning point for agents

A verifiable reward is computed by a machine, not a human. So you can have millions of them. And above all: you can automatically generate the environments themselves (create code, math, or SQL problems with their verifier built in) to manufacture tasks at scale. The scarce resource is no longer hand-annotated data, but the quality and diversity of environments.

Generating environments at scale

Since a verifiable environment boils down to "a task + an automatic verifier", their creation can be industrialized, with no humans in the annotation loop. That has become a subject in its own right: Building the worlds: generating training environments covers it in full, the automatic production pipelines, the verifiers, and what an environment actually costs.

The sandbox: running dangerous code safely

If the agent writes and runs code during training, that code is by nature untrusted: it may loop forever, exhaust all the memory, try to reach the network, delete files. You cannot let it run on the training machine.

Hence the sandbox: an isolated execution environment (a container, or a micro-VM (virtual machine: a simulated computer inside the computer, walled off from everything else)) that:

  • cuts off or limits network and filesystem access,
  • imposes time and memory limits (a looping program is killed),
  • is disposable: destroyed after each rollout to start clean.

For agent RL, the sandbox must additionally be fast to start and massively parallel: thousands run at once, one per rollout. It is an infrastructure component in its own right, often as decisive for throughput as the GPUs themselves.

Reward design, reward hacking, and difficulty filtering

A verifiable reward reduces the risk of cheating, but doesn't eliminate it. If the signal is poorly designed, the agent will find shortcuts: passing the tests without solving the real problem, exploiting a flaw in the verifier, hard-coding the expected answer. This is reward hacking, covered in detail in What breaks when you run RL on an LLM, the rule is: the reward must reward real success, not a proxy that's easy to game.

Another essential lever is filtering tasks by difficulty. A problem that is too easy (the agent succeeds every time) gives no learning signal, all trajectories look equally good. A problem that is too hard (the agent always fails) gives none either, there is never a success to reinforce. With group-based methods like GRPO, where a response's advantage is its gap from the average of the group of responses drawn on the same task, a problem whose responses all get the same score yields zero advantage: zero gradient, zero learning. That isn't a teaching preference, it is arithmetic.

Keeping problems neither too easy nor too hard

We want tasks where the agent succeeds sometimes, typically a success rate neither near 0 % nor near 100 %. Those are the ones carrying the most information. It's an automatic form of curriculum, the progressive ordering of examples described in Curriculum learning and data ordering: concentrate training on the zone where the model still has something to learn, and drop (or upgrade) tasks that have become trivial as it improves.

Observability: monitoring a living training run

An agent RL run is a distributed system that runs for days and can drift silently. Hence the need for observability: instrument and monitor continuously to catch problems early. We watch in particular:

  • Learning stability: the loss (the number training is trying to push down), the KL penalty against the frozen reference model (KL stands for Kullback-Leibler, after the two authors of the measure; it quantifies how far apart two probability distributions are, here how far the policy has drifted from where it started) and the gradient norm. A KL that blows up signals the model is drifting too fast, often a precursor to collapse.
  • Policy behavior: response length, success rate, trajectory diversity. Length ballooning without a gain in success can betray reward hacking or format collapse.
  • Failure modes: sandbox crashes, timeouts, verifiers returning a false positive, off-policyness climbing because generators are falling behind.

Without this telemetry, you discover that a multi-day run was broken… several days too late. Observability is the dashboard that lets you stop, fix, and understand why the policy behaves as it does. The catalogue of drifts and their symptoms is in What breaks when you run RL on an LLM.

Summary table

ComponentRoleMain difficulty
Generators (actors)Produce rollouts continuouslySlow inference, underused GPUs
LearnersUpdate the weightsWant saturated GPUs, large batches
EnvironmentsProvide tasks + observe outcomeProducing many, diverse, verifiable
VerifiersCompute an exact rewardAvoid false positives and reward hacking
SandboxRun untrusted code safelySpeed, isolation, massive parallelism
Freshness controlBound off-policynessThroughput ⇄ stability trade-off
ObservabilityWatch stability and behaviorDetect drift in time

Why it matters

The most impressive agent capabilities of recent models (solving end-to-end coding tasks, chaining tools, persevering on long problems) come not only from a better algorithm: they come from the ability to run this RL loop at very large scale, stably. The bottleneck has shifted from "which algorithm?" to "which infrastructure for rollouts, environments, and verification?". Understanding this plumbing means understanding where much of today's performance (and intellectual property) of LLM agents is actually decided.

Key takeaways

  1. The RL loop = generate rollouts (the agent's trajectories) β†’ score them β†’ update the policy β†’ repeat.
  2. Generation and training fight over the GPUs, hence asynchronous/distributed architectures that separate generators from learners so nobody waits.
  3. Off-policyness is the gap between the policy that generated the data and the one being trained; it's mitigated by bounding rollout staleness, by importance sampling (reweighting each attempt by the importance ratio), and by clipping that ratio.
  4. Verifiable-reward environments (code, math, SQL queries: success observed automatically) make it possible to generate tasks at scale without human annotators.
  5. The sandbox runs generated code in an isolated, limited, disposable way, an infrastructure component as critical as the GPUs.
  6. Reward design (avoiding reward hacking) and difficulty filtering (keeping tasks neither too easy nor too hard, the only ones that yield a non-zero advantage) concentrate learning where there is signal; observability catches drift before it ruins a multi-day run.
  7. Exactly one thing learns in all this machinery: the policy weights. The reference model is frozen, the verifier is plain code, the rollouts are recomputed and then thrown away.
Check your understanding0 / 5

1. Why are the generators, which produce rollouts, physically separated from the learners, which update the weights?

2. An asynchronous system tolerates rollouts produced by a policy several updates behind. What do you gain and what do you risk by raising that tolerance?

3. What is the fundamental difference between a verifiable reward and the RLHF reward model?

4. With a group-based method like GRPO, why do we discard tasks the agent always succeeds at, and also those it always fails?

5. In all the machinery described (policy, reference model, verifier, rollouts) what actually learns?