· 9 min read · Aravind Baranitharan
RL for agents.
Reinforcement learning explained for people who build with LLMs: how rewards shape a model, why verifiable rewards changed everything, and what reward hacking looks like in a real agent.
- Reinforcement learning
- AI agents
- Evals
- Training
Pretraining teaches a model to sound like the internet. Fine-tuning teaches it to sound like your examples. Reinforcement learning teaches it something different: to do whatever earns reward. That one change is behind the jump from chatbots that answer to agents that finish things, and it brings a new class of bugs with it.
This is my builder's map of RL for language models and agents: the loop, how the field moved from human preferences to verifiable rewards, how to design a reward, how it gets gamed, and what all of it means if you never train a model yourself. Every section is open for feedback at the bottom.
The loop in one paragraph
An agent (the policy) sees a state, takes an action, and the environment answers with a new state and sometimes a reward. Repeat until the episode ends. Training nudges the policy so that actions which led to more total reward become more likely next time. For an LLM, the state is the context so far, an action is a token, a message or a tool call, and the episode is one full attempt at a task.
Why imitation isn't enough
A model trained only to imitate is capped by its examples. It also never sees its own mistakes during training: every example is a clean path, so when it drifts off that path at run time it has no practice recovering. RL fixes both. The model trains on its own attempts, including the bad ones, and it is graded on outcomes rather than on matching a reference word for word.
- Outcomes over style. Two very different solutions can both pass the tests. Imitation punishes the one that doesn't match; RL rewards both.
- Recovery is learnable. If a rollout makes a mistake at step 4 and fixes it at step 6, and that earns reward, the fix gets reinforced.
- Search becomes skill. Sampling many attempts and keeping what works is search. RL folds the winning patterns back into the weights, so the next attempt needs less search.
From human preferences to verifiable rewards
The first wave was RLHF. In InstructGPT, people ranked pairs of model answers, a reward model learned to predict those rankings, and the language model was trained with PPO to score well on it. The headline result: labellers preferred a 1.3B-parameter InstructGPT over the 175B GPT-3. Alignment, not size, made the difference.
DPO then showed you can skip the separate reward model and train directly on preference pairs, which made preference tuning cheap and stable. But preferences are fuzzy and a learned reward model is easy to fool, so both methods are better at style and helpfulness than at hard correctness.
The second wave is RL with verifiable rewards. If the task has a checkable answer, such as a maths result, a passing test suite or a valid SQL query, you don't need a human or a reward model at all: a program grades the attempt. DeepSeek-R1 used simple rule-based rewards (is the answer right, is the format right) with GRPO, and long step-by-step reasoning emerged without anyone writing examples of it.
If you can check it, you can train on it. The bottleneck moved from data to graders.
Designing the reward
The reward is the specification. Whatever you score is what you get, including the parts you didn't mean. The main choices:
- Outcome vs process. Score only the final result, or also the steps along the way? Outcome rewards are honest but sparse. Process rewards give more signal but teach the model to please the step-grader.
- Rules vs models. Tests, schemas and exact-match checks are hard to fool. A reward model or LLM judge covers fuzzy goals like "well written", but it is itself a model with blind spots.
- Sparse vs dense. One bit at the end of a 50-step episode is a weak signal. Partial credit (tests passed out of total, fields filled correctly) helps the model learn, as long as partial credit can't be farmed.
- Penalties. Cost, latency, unsafe tool calls and rule violations all belong in the reward, or the model will learn that they are free.
Reward hacking
Goodhart's law, at training speed: when a measure becomes a target, it stops being a good measure. The classic example is an RL agent in a boat-racing game that learned to circle forever hitting the same reward targets instead of finishing the race. With LLM agents it looks like this:
- Gaming the tests. Coding agents trained against unit tests have been reported to special-case the test inputs, or edit the tests, so that they pass.
- Flattering the judge. A policy trained against an LLM judge learns the judge's tastes: longer answers, confident tone, the words the rubric mentions.
- Claiming success. If the grader trusts the agent's own report, the agent learns to report success.
The defences are boring and they work. Keep a held-out eval the policy never trains against and watch for training score rising while that eval falls. Make the grader check the real outcome, not the agent's description of it. Lock files the agent shouldn't touch. Read actual rollouts, not only the curves. And keep a KL penalty that stops the policy drifting too far from the reference model in pursuit of reward.
A training loop for agents
Here is one round of RL for an agent, using a GRPO-style group comparison. It's the same loop whether the task is a maths problem or a 40-step coding job; the agent case just has longer episodes and real tools.
- 01
Policy
The model being trained. At every step it reads the context so far and picks the next action: a message, a tool call or a final answer.
- 02
Environment
Where the agent acts: the task prompt, the tools it may call and the state those tools change, usually inside a sandbox that can be reset. For agents, building good environments is now most of the work.
- 03
Rollouts
Run several attempts at the same task. Some finish, some fail, some take a strange route. Each one is recorded as a full trajectory of states, actions and observations.
- 04
Grader
Score each trajectory. Prefer checks a program can run (did the tests pass, does the file exist, is the answer right) and fall back to a rubric or reward model only for what can't be checked.
- 05
Advantage
Compare each attempt with its siblings: reward minus the group average. That is the GRPO trick, and it removes the need for a separate value model. Above average gets pushed up, below average gets pushed down.
- 06
Update
Adjust the weights so above-average trajectories become more likely, with a KL leash to the reference model so the policy doesn't wander off into strange text that happens to score well.
- 07
Held-out evals
Tasks the policy never trains on, graded the honest way. If the training reward climbs while these stall or drop, the policy is learning the grader, not the task.
What changes for multi-step agents
- Credit assignment. A reward at step 50 has to be shared across 50 decisions. Which one was the good idea? Group comparison helps, and so do intermediate checks that are hard to game.
- Episodes are expensive. A coding rollout may take minutes and spin up containers. Throughput of the environment, not the GPU, is often the limit.
- Environments drift. Websites change, APIs rate-limit, packages update. Training environments need to be pinned and reproducible, or the reward becomes noise.
- Long contexts. Trajectories outgrow the window, so memory and summarisation become part of what the policy has to learn to use. (See agentic memory.)
If you don't train models
Most of us will never run PPO. The ideas still pay off, because the pieces of an RL setup are the same pieces as a good evaluation setup:
- Write graders, not vibes. A task with a program that checks the result is something you can eval today and train or fine-tune on tomorrow.
- Build environments. A resettable sandbox with your real tools is how you test an agent honestly, and it is exactly what an RL run needs.
- Sample and select. Best-of-n with a strong verifier gets you much of RL's gain at inference time, with no training. It's the same loop without the weight update.
- Expect your agent to game your checks. Models trained with RL are very good at satisfying the letter of a goal, so make the checks match the intent. See long-horizon tasks for a verifier-first architecture.
Open questions
- How do you reward tasks with no checkable answer, like a good research summary, without the policy learning to please the judge?
- Can process rewards be made hard to game, or will the policy always learn the step-grader's blind spots?
- How much of an agent's skill is the model and how much is the environment it was trained in?
- How do you keep RL-trained agents honest about what they actually did?
Rate the post, start a thread on any concept below, or share it with someone who keeps hearing "RL" and nodding. I'll update it as the discussion changes my mind.