Training LLM Agents with RL: Rollouts, Environments, Off-Policyness
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:
- 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.
- Scoring / reward. We evaluate the rollout. The reward 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?".
- 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 ββββββββββββββββββββββββββ
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:
| Item | Role | Status |
|---|---|---|
| The policy weights | what we are trying to improve | learned, they change at every update |
| The reference model | a copy of the policy taken before training, used to measure how far we have drifted | frozen, never updated |
| The verifier | observes success (runs the tests, compares the answer) | plain code, nothing to learn |
| Rollouts and their rewards | the attempts and their scores | recomputed 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.

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.
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.

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:
- Bounding staleness. We set a limit: only accept rollouts produced by a policy at most updates behind. Too old β discard. This trades throughput (rollouts produced per hour) against the correctness of each update.
- Importance sampling. We mathematically correct the gap by reweighting each sample with the importance ratio:
Symbol by symbol:
- (the Greek letter rho) is the weight we will give to sample number ;
- is the policy being trained, the Greek letter pi conventionally denotes a policy, and its parameters, i.e. the weights that move;
- is the earlier version of that same policy, the one that actually produced the rollout;
- is the task we handed over, the action or answer produced;
- reads "the probability that this policy produces when given ".
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.
- 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 of : the ratio is therefore held between and . That is a knob, not a law of nature; it is the "proximal" in PPO's name.
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.

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.
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
| Component | Role | Main difficulty |
|---|---|---|
| Generators (actors) | Produce rollouts continuously | Slow inference, underused GPUs |
| Learners | Update the weights | Want saturated GPUs, large batches |
| Environments | Provide tasks + observe outcome | Producing many, diverse, verifiable |
| Verifiers | Compute an exact reward | Avoid false positives and reward hacking |
| Sandbox | Run untrusted code safely | Speed, isolation, massive parallelism |
| Freshness control | Bound off-policyness | Throughput β stability trade-off |
| Observability | Watch stability and behavior | Detect 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
- The RL loop = generate rollouts (the agent's trajectories) β score them β update the policy β repeat.
- Generation and training fight over the GPUs, hence asynchronous/distributed architectures that separate generators from learners so nobody waits.
- 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.
- Verifiable-reward environments (code, math, SQL queries: success observed automatically) make it possible to generate tasks at scale without human annotators.
- The sandbox runs generated code in an isolated, limited, disposable way, an infrastructure component as critical as the GPUs.
- 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.
- 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.
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?