Applied Agents
Training agents and agentic RL
RLVR, GRPO, tool-use fine-tuning
Almost every agent you build should be prompted, not trained. But the reasoning models underneath them, o1 and DeepSeek-R1, were made by reinforcement learning. This lesson demystifies how: the training ladder, RLHF versus verifiable rewards, the GRPO algorithm behind R1, and what "agentic RL" adds when you optimize a whole tool-use trajectory instead of one reply.
First decision: train or prompt?
Training changes weights; prompting changes context. Both change behavior, but they are not interchangeable. Prompting, tools, and retrieval are cheap, instant, and endlessly revisable. is a bet that the task will not move. Make that bet only when the task is stable, high-volume, and well-specified, and you already have prompts that work and clean examples to learn from.
The rule of thumb
| Signal | Prefer prompting (+ tools, RAG, few-shot) | Prefer fine-tuning / RL |
|---|---|---|
| Task stability | Spec still moving, iterating fast | Task frozen, high volume |
| Data | Little or no labeled data | Enough clean examples / trajectories |
| What changes | Facts change often, use RAG | Behavior, format, or policy, not facts |
| The need | Flexibility, speed of iteration | Latency, cost per token, consistency at scale |
Meta deliberately post-trained Llama 3 with SFT plus rejection sampling plus DPO rather than full RL, calling RL "less stable and harder to scale" at the time.[7] Even frontier labs climb the cheap rungs first.
The training ladder
"Training" is not one thing. It is a ladder of techniques, roughly ordered by cost and instability. Frontier post-training pipelines chain several of them; you rarely pick just one.
- SFT / behavior cloning. Train on
(input, ideal output)pairs with cross-entropy loss. For agents, the "outputs" are high-quality . It is imitation: the model can only be as good as its demonstrations, and it never sees the consequences of its own mistakes. Coverage and quality of the data are the ceiling. - Rejection sampling (best-of-N). Generate N candidates per prompt from the current model, score them with a verifier or reward model, keep only the winners, and SFT on those. You distill the model's own best behavior back into itself: cheap, stable, and a pillar of real pipelines.[1]
- Preference optimization (DPO). Learn from pairs
(chosen, rejected)instead of a scalar reward. DPO reparameterizes the RLHF objective into a simple classification-style loss: no reward model, no sampling loop, no RL machinery. Stable and cheap, but limited to a static offline dataset. - Full RL (PPO, GRPO). The model generates, gets scored, and updates via policy gradient, a closed loop where it learns from the consequences of its own sampled behavior (on-policy). The only rung that can push behavior beyond the demonstration data, and the most expensive and least stable.
That last jump, from imitation to learning-from-consequences, is the whole story. Hold these two side by side, because everything below is a variation on the right-hand column.
Supervised fine-tuning (open-loop)
Reinforcement learning (closed-loop)
Aligning behavior: RLHF, RLAIF, reward models
The technique behind the ChatGPT-era chat revolution is , and it has three stages:
- SFT an instruction-following base model.
- Train a reward model. Collect human pairwise comparisons (is A or B better?) and fit a that outputs a scalar "how much a human would prefer this."
- RL (PPO). Optimize the policy to maximize reward-model score, with a KL penalty to the SFT reference so it cannot drift into gibberish that games the score.
Human preferences are slow and expensive to collect, so swaps the human labeler for a (usually stronger) model applying a written rubric: orders of magnitude cheaper, and consistent because the same principles apply every time. Anthropic's is the canonical recipe: the model critiques and revises its own answers against a written "constitution," then judges which of two answers better follows it, producing an AI-labeled preference dataset to train on.[6]
The weak point: reward hacking
RLVR: rewards you cannot fake
In domains where correctness is objectively checkable, you can throw the learned reward model away and reward the policy directly from a deterministic verifier. This is , RL with Verifiable Rewards, and it is the paradigm behind modern reasoning models.
What a verifier checks
Why it is powerful
check(answer) -> bool, you can run RLVR.The catch
GRPO: the workhorse algorithm
(Group Relative Policy Optimization) is the de-facto RLVR algorithm, introduced by DeepSeek. Its key move: delete PPO's critic/value network (which is often as large as the policy, doubling memory). Instead of a learned baseline, it uses the model's own peers.[5]
GRPO in one sentence: grade on a curve
Formally: for prompt q, sample a group of G outputs, score each with the verifier to get rewards r1 ... r_G, and compute each output's relative to its own group, then update with a PPO-style clipped objective:
A_i = ( r_i - mean(r_1 ... r_G) ) / std(r_1 ... r_G)Here it is worked by hand. Prompt: "Compute 17 x 23", the verifiable answer is 391. Sample a group of G = 4:
| Rollout | Model's final answer | Verifier reward | Advantage = (r - 0.5)/0.5 |
|---|---|---|---|
| o1 | "... = 391" | 1 | +1.0 push tokens up |
| o2 | "... = 381" | 0 | -1.0 push down |
| o3 | "... = 391" | 1 | +1.0 push up |
| o4 | "... = 401" | 0 | -1.0 push down |
Sampling G completions per prompt is the price you pay for skipping the critic. Now the full loop: the policy samples rollouts, the verifier scores them, group-relative advantages are computed, and the policy is updated, then it repeats.
Tap a node to see what it does.
Zero-gradient batches, the failure mode that explains the fixes
How reasoning models are actually made (o1, R1)
This is the payoff. Earlier lessons showed you what reasoning models do; here is how they are built. OpenAI o1 was trained with large-scale RL "to think before answering," to generate a long internal chain of thought, then answer. Through RL it learns to refine its reasoning, catch its own mistakes, decompose hard steps, and switch strategy when one is not working. The headline: accuracy improves with both more training-time RL compute and more test-time thinking, making inference compute a genuine new scaling axis.[3]
DeepSeek-R1 (Jan 2025) open-sourced a credible recipe and made two sharp points that demystify the whole thing:[1]
R1-Zero: pure RL, no SFT
R1: a multi-stage pipeline
V3 base --RL (GRPO, verifiable rewards)--> R1-Zero # proof: reasoning emerges from pure RL - but messy
V3 base --cold-start SFT (~k readable CoTs)--> ckptA
ckptA --reasoning RL (+ language-consistency reward)--> ckptB
ckptB --rejection sampling--> 600K reasoning + 200K general SFT data
V3 base --SFT on that 800K--> ckptC
ckptC --RL over ALL tasks (rule + preference rewards)--> R1
R1 --generate 800K samples --SFT--> distilled 1.5B / 7B / 8B / ... / 70B # no RL in the small modelsClassic RLHF gives one reward for a whole trajectory, so the model cannot tell which step was wrong. o1-style training is widely believed to lean on process reward models that score each reasoning step, plus searching over multiple candidate reasoning paths.[9]
Agentic RL: optimizing the whole trajectory
Everything so far optimizes a single response. optimizes the entire tool-use trajectory. The cleanest mental model reframes what the LLM is:[2]
Old view (RLHF)
Agentic RL
This shift, from imitation (SFT on trajectories) to outcome-driven optimization (closed-loop RL), is what lets an agent discover when, how, and which tool to use, self-correct faulty tool calls, and compose tools, rather than parroting demonstrated patterns. Here is one RLVR trajectory for a search agent:
s0 user: "What year did the author of <book> win the Nobel?"
a0 (text) reason: "find the author, then their Nobel year"
a1 (tool) search("author of <book>") -> obs: "<Author>"
a2 (text) reason: "now the Nobel year for <Author>"
a3 (tool) search("<Author> Nobel Prize year") -> obs: "1982"
a4 (text) answer: "1982"
verifier: exact-match vs gold "1982" -> reward = 1 # else 0Under SFT you would imitate one fixed gold trajectory. Under agentic RLVR you roll out many trajectories per question, reward only the final answer, and let GRPO raise the probability of whichever action sequences, which searches in which order, led to correct answers.
The central hard problem: credit assignment
+1 lands only at the end of a 10-turn trajectory. Which action deserves the credit, was a3's good query the load-bearing step, or a1? This is the . Naive credit propagation reward-hacks or punishes useful exploration. Emerging fixes: turn-level / step-level advantages (GiGPO), process rewards on intermediate steps, and hierarchical RL. This is explicitly an unsolved frontier of the field.[2]Distillation and the "does RL teach anything new?" debate
trains a small student on a stronger teacher's outputs. DeepSeek showed it is remarkably potent for reasoning: SFT'ing open models on 800K R1-generated samples produced strong reasoners with no RL at all, a distilled 7B hit 55.5% on AIME 2024, beating QwQ-32B-Preview.[1] Practically, distillation is often the cheapest way to get most of a big RL run's gains into a small, fast production model.[10]
A genuine, live scientific controversy
Check yourself
Match each training concept to what it does.
imitate demonstrated trajectories
reward from an automatic correctness check
baseline from a group, no value model
gaming the metric, missing the intent
What makes RLVR far harder to reward-hack than classic RLHF?
Which signal most justifies fine-tuning a model instead of prompting it?
In GRPO, why do prompts where all G rollouts get the same reward (all correct, or all wrong) produce zero gradient?
What is each advantage measured against? Try to state it, then check.
Lock it in
- Prompt by default, train by exception. Climb the ladder only when the rung below cannot deliver: prompt, tools/RAG, SFT, rejection sampling, DPO, full RL.
- RLVR replaces the learnable reward model with a deterministic verifier (math/code/proofs): ground truth is far harder to reward-hack, which is why it powers reasoning models.
- GRPO grades on a curve: sample G answers per prompt, score each versus its group mean, drop the critic. All-right or all-wrong groups yield zero gradient.
- Reasoning models emerged from RL on chain-of-thought, R1-Zero proved it needs no SFT, but shippable models interleave SFT, rejection sampling, RL, and distillation.
- Agentic RL optimizes whole tool-use trajectories (a POMDP, not a single reply); the central open problem is credit assignment across many turns.
Primary source
DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning (arXiv:2501.12948)The one paper to read here: it defines GRPO, proves reasoning emerges from pure RL (R1-Zero), documents the rule-based verifiable rewards, the "aha moment," the full multi-stage pipeline, and distillation to small models.
Sources
- 1.DeepSeek-AI, DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via RL
- 2.The Landscape of Agentic Reinforcement Learning for LLMs (survey)
- 3.OpenAI, Learning to Reason with LLMs (o1)
- 4.Does RL Really Incentivize Reasoning Capacity Beyond the Base Model?
- 5.Cameron R. Wolfe, GRPO Tricks
- 6.Bai et al., Constitutional AI: Harmlessness from AI Feedback
- 7.Meta, The Llama 3 Herd of Models
- 8.DAPO: An Open-Source LLM Reinforcement Learning System at Scale
- 9.Nathan Lambert, Reverse engineering OpenAI's o1 (Interconnects)
- 10.Nathan Lambert, RLHF Book: Synthetic Data & Distillation
- 11.ProRL: Prolonged Reinforcement Learning Expands Reasoning Boundaries