← Back to Autonomy
Monograph · Agentic AI

Reinforcement Learning in Agentic AI

Where reinforcement learning actually lives inside an AI agent, which algorithms do the work, and how the training loop wraps around a tool-using agent. Plain language, working diagrams you can poke at, and practical notes from the parts that bite.

Section 01

Two very different places RL lives

The single biggest source of confusion is treating "RL in agents" as one thing. It is two. Mixing them up makes every other question unanswerable.

One use is offline: you use RL to train the model's weights so the agent behaves better. The other is online: an RL policy makes decisions while the agent runs, choosing which tool to call or when to stop. Use the toggle to see each one on its own terms.

Figure 1 · Interactivetap a layer
Reading it: for most agents built on a frozen frontier model you are in the online world only. Actual RL training (offline) enters when you own the weights, have a reward you can compute, and have a harness to roll out episodes.
Practical note

Before reaching for PPO or GRPO, ask which regime you are in. If you cannot change the weights, no amount of RL theory applies. What you are really tuning is prompting and orchestration over an already-RL-trained policy.

Section 02

Should you even use RL?

Most "we should do RL" conversations end before they start, because one of three preconditions is missing. Answer the three gates and the figure tells you where you actually stand.

Figure 2 · Interactiveset each gate
The order matters. Each gate is a hard prerequisite for the next. Failing an early one means the later ones are moot, and the fix is almost never "a better algorithm."
Section 03

The agentic loop, drawn as an MDP

To train an agent with RL you first describe its loop in RL's own vocabulary: a Markov Decision Process. Four pieces, and the agent reasoning-then-calling-a-tool maps onto them cleanly.

Tap each node to see what it corresponds to in a real tool-using agent. The dashed link back is the part beginners miss: the environment's response becomes part of the next state, not a reward by itself.

Figure 3 · Interactivetap a node
Start hereTap any node above to map it onto a concrete part of an agent.
Why POMDP, not MDP: the agent never sees the true world state, only its context window of past observations. That partial view is why memory and context management matter so much in practice.
Section 04

Where the reward comes from

The algorithm is interchangeable; the reward source is the real fork in the road. It decides what you can train, how much it costs, and how easily the agent can cheat. Five sources dominate.

Each is plotted by cost to produce against how grounded it is (how hard to game). Tap a point for the trade-off. Notice the prize corner: cheap and grounded, which is why verifiable rewards reshaped the field.

Figure 4 · Interactivetap a source
Start hereTap any source to see what produces the signal and how it fails.
RLVR (verifiable rewards) and rule-based signals sit in the cheap-and-grounded corner, but only apply where correctness is checkable. Human and AI feedback cover open-ended tasks at the cost of being expensive, noisy, or gameable.
Section 05

The algorithms, and when each earns its keep

There are fewer real choices than the acronym soup suggests. They cluster into families, and for language-model agents two of them carry almost all the load.

Policy gradient

PPO

The long-time workhorse for RLHF. A clipped objective keeps each update small, with a separate value network and a KL leash to a reference model so the policy does not drift into nonsense.

Use: stable RLHF when you can afford a critic
Policy gradient

GRPO

Drops the value network. Samples a group of answers to the same prompt and scores each one against the group average. Cheaper and steady on sparse, yes-or-no rewards. Now the default for reasoning and agentic training.

Use: reasoning, tool use, verifiable rewards
Preference

DPO & kin

DPO, KTO, ORPO, SimPO. Optimize directly from preference pairs with no rollouts and no environment. Strictly speaking not RL, but they sit in the same slot of the pipeline.

Use: alignment from preference data, cheaply
Value based

DQN

Learns the value of each action in a discrete set. Natural when the agent is a classic policy picking among a fixed menu of tools or moves, less so for free-form token generation.

Use: discrete action agents, game-like tasks
Actor critic

SAC · TD3 · A2C

Continuous-control methods for agents that output real-valued actions, the robotics end of the spectrum. Rare for pure language agents.

Use: robotics and control, continuous actions
Search + value

MCTS + value

AlphaZero-style. Pairs a learned policy and value with tree search at decision time. Powerful for planning agents where you can afford the search budget.

Use: planning agents with a simulatable world
The honest summary

For language-model agents today, the choice is usually PPO versus GRPO, and even that matters less than getting the reward and the rollout environment right. The algorithm is rarely the bottleneck.

Section 06

The training loop, and the KL leash that keeps it sane

Every policy-gradient method, agentic or not, turns the same four-beat crank. Step through it to see what flows into what.

Figure 5 · Interactivestep through
The hard beat is the third one. Turning a single end-of-episode reward into a useful signal for a long trajectory is the credit-assignment problem, the subject of Section 10.

The KL leash, made visible

The update step always carries a penalty that pulls the new policy back toward a frozen reference (the model before RL). The strength of that pull is a knob called β. Set it too low and the policy chases reward into gibberish; too high and it barely moves. Drag β and watch the policy distribution slide away from the reference.

Figure 6 · Interactivedrag the coefficient
Why it exists: reward is a proxy. Left unleashed, the policy will satisfy the proxy by abandoning everything the base model knew about coherent language. The KL term is the tether that keeps optimization inside the region where the reward still means something.
Section 07

GRPO, made concrete, and where exploration comes from

GRPO's trick is to skip the value network entirely. Instead of asking "how good was this answer in absolute terms," it asks "how good was it compared to its siblings." Sample a group, and a good answer is simply one that beat the group average.

Press the button to sample a fresh group of four rollouts of the same task. Each gets a reward; the advantage is just how far above or below the group mean it landed, scaled by the spread. The temperature slider controls how diverse the rollouts are, which is the entire exploration mechanism in GRPO.

Figure 7 · Interactivere-sample to compare
Advantage = (reward − group mean) / group spread. Positive means "do more of this," negative means "do less." Low temperature collapses the group toward identical rollouts and kills the gradient; some diversity is required to learn anything at all.
Practical note · the trap

If every rollout in the group fails (or all succeed), the spread is zero and every advantage is zero. That group produces no gradient and is wasted compute. Try the "all-fail" button. In agentic training, where task difficulty is bimodal, this happens constantly. The fix used in practice (DAPO) is dynamic sampling: oversample, throw away the degenerate groups, and keep the batch full of groups that actually disagree.

Exploration, plainly

Classic RL explores by occasionally taking a random action. A language-model policy explores through sampling temperature and the resulting spread inside each group. Too cold and it always writes the same answer and never discovers a better one; too hot and the rollouts are noise. Tuning this, plus an entropy bonus, is how you keep the policy curious without making it incoherent.

Section 08

Token masking: the bug everyone hits first

A multi-turn agent trajectory is a mix of two kinds of tokens: ones the policy chose to write, and ones the environment handed back. The policy gradient must only be applied to what the policy actually controlled.

Below is one rollout: the agent thinks, calls a tool, the tool replies, the agent thinks again. Toggle the mask to see which tokens carry training signal. The tool's reply is context for the next decision, never an action to reinforce.

Figure 8 · Interactivetoggle the mask
policy token · trained on observation token · context only
Forget the mask and you train the model to predict tool outputs it never produced. The run looks like it is learning, the loss moves, and the agent quietly gets worse.
Section 09

The rollout harness: the part that is actually hard

For agentic RL, the algorithm is the easy 10 percent. The other 90 is the harness: the machinery that lets a policy take many turns in a real environment, get real tool results back, and receive a trustworthy reward at the end. Teams that struggle with agentic RL are almost always struggling here, not with PPO.

A rollout is a sequence of turns. In each turn the policy emits some tokens (think, then act), the environment runs the action and returns an observation, and the loop repeats until a stop condition. The toggle below shows the two granularities at which you can hand out credit across that structure.

Figure 9 · Interactiveswitch granularity
Turn-level credit treats each whole turn as the unit of action, which fits tool-use agents better than per-token credit and shortens the distance reward has to travel. It needs a per-turn signal, which is exactly what a well-built verifiable environment provides.
Practical note · what to build first

Before any training, build the environment so it can (1) run a full multi-turn episode deterministically given a seed, (2) return a reward your team trusts, and (3) replay a saved trajectory for debugging. If you cannot replay a failure, you cannot fix a reward bug, and reward bugs are the ones that silently wreck a run.

Section 10

Credit assignment and the tyranny of the horizon

An agent took eight steps and the task succeeded. Which steps deserve the credit? This is the central difficulty, and there are two answers with a real trade-off between them.

Outcome reward gives one signal at the very end. Simple and trustworthy when you can verify the result, but it cannot tell a brilliant plan with one slip from a plan that was wrong throughout. Process reward scores every step, which localizes the error beautifully but is expensive to produce and easy to game. Toggle to see the difference land on the same trajectory.

Figure 10 · Interactiveswitch the reward type
Plain GRPO with outcome reward paints every step with the same color. Within-trajectory credit is left to the gradient and the model's own structure. That is why it works for self-consistent reasoning and struggles on long, branchy tool use.

Why long horizons are the real enemy

With a single terminal reward, the signal an early step receives is discounted by the factor γ raised to the number of steps between it and the reward. Drag γ and watch how quickly credit fades as it travels backward across fifteen steps. This decay is precisely why long-horizon agentic tasks are so much harder than single-turn reasoning, and why hierarchy (Section 12) helps.

Figure 11 · Interactivedrag the discount
Credit half-life is the number of steps over which the reaching signal halves. At γ = 0.95 it is about 14 steps; at γ = 0.90 it is about 7. Past a few half-lives, an early step learns essentially nothing from a terminal reward.
The clean middle path

If you must add per-step signal, make it potential-based shaping: a term of the form F = γΦ(s′) − Φ(s). A classic result (Ng, Harada & Russell, 1999) proves this form leaves the best policy unchanged, so it only speeds up learning and cannot be hacked into a new optimum. Most hand-built process rewards do not satisfy this, which is precisely how reward hacking sneaks in.

Practical note · the sweet spot for agents

The best move is often to dodge the dilemma: decompose the task so each step has a verifiable subgoal. You get dense, ground-truth signal with no learned process-reward model to train, drift, or defend against. This is why verifiable-environment agentic RL is where the real progress has happened.

Section 11

When rewards go wrong

A reward is a proxy for what you actually want. Optimize any proxy hard enough and the gap between proxy and intent becomes a chasm the policy is happy to live in. This is reward hacking, and it is not an edge case, it is the default behavior of a competent optimizer.

Press step to let an agent optimize a proxy reward. The proxy climbs steadily. The thing you actually cared about rises with it for a while, then peaks and falls as the agent learns to satisfy the letter of the reward while betraying its spirit. The shaded gap is the hack.

Figure 12 · Interactivestep the optimizer
The lesson: a rising reward curve is not evidence of success. You must evaluate the true objective on held-out tasks, because the proxy will always look like it is winning.

Reward hacking in the wild

Game

The looping boat

An agent rewarded for hitting score targets in a boat race learned to spin in a lagoon collecting respawning point pickups forever, never finishing. The proxy (points) diverged from the goal (winning the race).

RLHF

Length gaming

When raters tend to prefer longer answers, the policy learns to pad. Reward goes up, helpfulness does not. A length penalty or length-debiased reward is the usual patch.

RLHF

Sycophancy

If approval is the reward, agreeing with the user earns it more reliably than being correct. The model learns to tell people what they want to hear.

Code RL

Gaming the verifier

Rewarded for passing tests, a policy can learn to special-case the visible tests, hard-code expected outputs, or weaken assertions rather than solve the problem.

Failure modes and how to spot them

Symptom · KL blowup

The policy sprints away from the reference; outputs turn weird or repetitive while reward spikes.

Fix: raise β, lower the learning rate, tighten the clip range.
Symptom · entropy collapse

Output diversity craters, every rollout in a group is identical, gradients vanish.

Fix: add an entropy bonus, raise temperature, check for over-tight KL.
Symptom · reward collapse

Reward flatlines at zero because every group is all-fail (or all-pass) and contributes no gradient.

Fix: dynamic sampling, curriculum, easier task mix early on.
Symptom · verifier overfit

Train reward soars, held-out performance stalls or drops. The policy is fitting the checker, not the task.

Fix: hold out tasks, rotate or strengthen verifiers, evaluate the true objective.
Symptom · length explosion

Trajectories grow without bound as the policy games a length-correlated reward.

Fix: length-debias the reward, cap rollout length, penalize tokens.
Symptom · mode collapse

The policy converges to one safe template answer for everything, abandoning the task distribution.

Fix: more diverse prompts per batch, entropy bonus, lower KL pressure.
Section 12

How the pieces are wired: three structures

Once the reward and the loop exist, the architecture around them is a design choice. Three patterns cover almost everything you will see.

Figure 13 · Diagramflat · hierarchical · multi-agent
Hierarchical design directly attacks the long-horizon credit problem: a planner emits subgoals and a worker executes them, so reward has a shorter distance to travel. It maps neatly onto planner-executor agent architectures.

Flat single-agent. One policy, one reward, the whole episode optimized as a unit. This is most current agentic RL and the right starting point.

Hierarchical. A high-level policy chooses subgoals; a low-level policy carries them out. Shorter credit paths, cleaner abstraction, more moving parts to train.

Multi-agent (MARL). Several policies, cooperating or competing, usually trained with centralized information but executed independently. Relevant only when you genuinely own and train multiple policies, not when you are orchestrating frozen models.

Practical note · last word

Reach for hierarchy or MARL only after a flat agent has hit a wall you can name. Most teams add structure too early and spend their budget debugging the architecture instead of the reward.

Section 13

A worked example: a vehicle-diagnostics agent

To make every idea above concrete, here is an agent in a domain where the reward is genuinely verifiable: fault isolation. A vehicle throws a code, and the agent must decide which queries to run to pin down the true root cause, then commit to a diagnosis.

The setup maps cleanly onto the MDP. State is the set of fault codes seen, sensor readings pulled so far, and the still-open candidate causes. Actions are diagnostic queries (read a sensor stream, pull a freeze-frame, run an actuator test) or a final commit. Reward is verifiable: correct isolation against ground truth earns the terminal reward, and each query that narrows the candidate set earns a small potential-based shaping bonus. Step the agent and watch the candidate set shrink.

Figure 14 · Interactiverun the diagnosis
The shaping reward here is potential-based: Φ(s) = −(number of open candidates). Each prune raises Φ, so γΦ(s′) − Φ(s) is positive, giving dense guidance without changing which final diagnosis is optimal. That is the Section 10 invariant doing real work.

Every concept in this monograph shows up in that one loop. It is a flat single-agent setup (Section 12). The reward is verifiable, so it sits in the cheap-and-grounded corner (Section 4). Outcome reward alone would be sparse over a long diagnosis, so potential-based shaping supplies dense signal safely (Section 10). The query results returned by the vehicle are observation tokens and must be masked from the loss (Section 8). And exploration through sampling lets the agent discover non-obvious query orders that isolate faster (Section 7).

Practical note · why this domain rewards RL

Diagnosis has the rare trio that Section 2 demands: a checkable reward (was the isolation correct), a natural rollout environment (a simulator or a labeled fault library), and a clear win condition. That combination is exactly what makes a task a good fit for RL rather than prompting alone.

Section 14

Math appendix

The four expressions behind everything above, in plain notation. No new ideas here, just the formal statements the figures were standing in for.

PPO · clipped surrogate objective
L_CLIP(θ) = E_t [ min( ρ_t · Â_t ,  clip(ρ_t, 1−ε, 1+ε) · Â_t ) ]

where  ρ_t = π_θ(a_t | s_t) / π_θold(a_t | s_t)   is the importance ratio
       Â_t                                       is the advantage at step t
       ε                                         caps how far one update may move
GRPO · group-relative advantage and objective
Â_i = ( r_i − mean(r_1 … r_G) ) / std(r_1 … r_G)

J_GRPO(θ) = E [ (1/G) Σ_i (1/|o_i|) Σ_t  min( ρ_i,t · Â_i ,  clip(ρ_i,t, 1±ε) · Â_i )
                                          − β · D_KL( π_θ ‖ π_ref ) ]

the group of G rollouts is the baseline; no value network is needed
β is the KL leash from Figure 6; the inner sum runs over policy tokens only
GAE · generalized advantage estimation (the PPO route)
Â_t = Σ_(l≥0) (γλ)^l · δ_(t+l)        with   δ_t = r_t + γ·V(s_(t+1)) − V(s_t)

λ trades bias against variance: λ→1 approaches Monte-Carlo returns (low bias,
high variance); λ→0 leans on the value estimate V (lower variance, more bias)
Potential-based shaping · the safe way to add dense reward
F(s, a, s′) = γ·Φ(s′) − Φ(s)

adding F to the reward leaves the optimal policy unchanged for ANY Φ
(Ng, Harada & Russell, 1999). This is why the Section 13 shaping is safe:
Φ(s) = −(open candidates) speeds learning without moving the best diagnosis.
KL estimator · the low-variance form used in GRPO
D_KL( π_θ ‖ π_ref )  ≈  (π_ref/π_θ) − log(π_ref/π_θ) − 1

an unbiased, always-positive per-token estimate, cheaper and steadier
than the naive log-ratio when estimated from samples
References

Where to read further

  1. Schulman et al. (2017). Proximal Policy Optimization Algorithms. arXiv:1707.06347.
  2. Ouyang et al. (2022). Training language models to follow instructions with human feedback (InstructGPT). arXiv:2203.02155.
  3. Bai et al. (2022). Constitutional AI: Harmlessness from AI Feedback (RLAIF). arXiv:2212.08073.
  4. Shao et al. / DeepSeek (2024). DeepSeekMath: GRPO and group-relative advantages. arXiv:2402.03300.
  5. DeepSeek-AI (2025). DeepSeek-R1: RL with verifiable rewards for reasoning. arXiv:2501.12948.
  6. Yu et al. (2025). DAPO: dynamic sampling, clip-higher, token-level loss. arXiv:2503.14476.
  7. Liu et al. (2025). Dr. GRPO: removing GRPO's length and difficulty bias. arXiv:2503.20783.
  8. Rafailov et al. (2023). Direct Preference Optimization (DPO). arXiv:2305.18290.
  9. Wang et al. (2024). Math-Shepherd: automatic process reward labels via Monte Carlo. arXiv:2312.08935.
  10. Lightman et al. (2023). Let's Verify Step by Step: process versus outcome supervision. arXiv:2305.20050.
  11. Ng, Harada & Russell (1999). Policy invariance under reward transformations: potential-based shaping. ICML.
  12. Schulman et al. (2016). High-Dimensional Continuous Control Using GAE. arXiv:1506.02438.
  13. Clark & Amodei (2016). Faulty Reward Functions in the Wild (the looping boat). OpenAI.
  14. Skalse et al. (2022). Defining and Characterizing Reward Hacking. arXiv:2209.13085.
  15. Silver et al. (2017). Mastering the game of Go without human knowledge (AlphaZero). Nature.