Skip to content

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

Prompting suits exploration; fine-tuning suits exploitation. Fine-tuning buys reliability, lower latency, and cheaper inference (you can drop long prompts), but only after the task is frozen. A classic anti-pattern is training to fix something a better prompt, one more tool, or retrieval would have solved for a fraction of the cost.
SignalPrefer prompting (+ tools, RAG, few-shot)Prefer fine-tuning / RL
Task stabilitySpec still moving, iterating fastTask frozen, high volume
DataLittle or no labeled dataEnough clean examples / trajectories
What changesFacts change often, use RAGBehavior, format, or policy, not facts
The needFlexibility, speed of iterationLatency, cost per token, consistency at scale
When to reach past prompting for training. Fine-tuning is a bet the task stays put.

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.

  1. 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.
  2. 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]
  3. 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.
  4. 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)

A gold trajectory (a human's ideal answer) is imitated with cross-entropy on the tokens, so the model clones the demonstration. It never sees its own mistakes.

Reinforcement learning (closed-loop)

The model generates its own rollouts, a verifier scores the outcome, and the policy update raises winners and lowers losers. It learns from consequences, and is the only rung that can exceed the training data.

Aligning behavior: RLHF, RLAIF, reward models

The technique behind the ChatGPT-era chat revolution is , and it has three stages:

  1. SFT an instruction-following base model.
  2. 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."
  3. 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

A learned reward model is a proxy for what you actually want. Optimize hard against a proxy and you get (Goodhart's law): outputs that score high but are genuinely bad. This is the deepest reason the next idea is so attractive: a verifier is not a learned proxy, it is ground truth.

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

Math: does the final answer match the reference? Code: do the unit tests pass, does it compile? Proofs: does the theorem prover accept it? Format: is the reasoning inside the required tags?

Why it is powerful

The reward is rule-based and usually binary (1 correct, 0 wrong). Because the verifier is not a learnable model, it is far harder to hack: DeepSeek explicitly chose rule-based rewards over a neural reward model to avoid reward hacking at scale.[1] If you can write check(answer) -> bool, you can run RLVR.

The catch

RLVR only works where a cheap, reliable verifier exists. Extending it to open-ended domains, writing, research, multi-turn web agents, is the frontier, which is why interest is shifting to rubric-based and process rewards, and to generative "LLM-as-judge" verifiers that blur back toward RLAIF.

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

For each question, sample a group of answers. Reward each answer by how much better or worse it is than the class average for that same question. Push the above-average ones up, the below-average ones down. No critic needed: the group is the baseline.

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)
Each output's advantage is its reward normalised against its own group. The group supplies the baseline, so no critic is trained.

Here it is worked by hand. Prompt: "Compute 17 x 23", the verifiable answer is 391. Sample a group of G = 4:

RolloutModel's final answerVerifier rewardAdvantage = (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
Group mean = 0.5, std approx 0.5. The four peers supplied the baseline; no critic network was trained.

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.

The RLVR loop. Sample rollouts, verify, reward, group-relative advantage, policy update, then repeat. The verifier is ground truth, so there is no reward model to hack.

Zero-gradient batches, the failure mode that explains the fixes

If all four rollouts were correct, the mean is 1 and every advantage is 0: zero gradient (nothing learned). Same if all four fail. GRPO learns only from questions the model gets sometimes right. DAPO's dynamic sampling over-samples and discards these all-correct / all-wrong groups so the batch stays full of informative examples, one of four fixes that pushed AIME from around 30% (vanilla GRPO) to around 50% in half the steps.[8] The rest of the GRPO literature (Dr.GRPO, DAPO) is largely a catalog of patches for entropy collapse, length bias, and reward hacking.

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

Starting straight from the DeepSeek-V3 base model, apply GRPO with rule-based verifiable rewards (accuracy plus format), zero reasoning demonstrations. Self-verification, reflection, long chains of thought, and exploring alternatives emerge on their own. AIME 2024 pass@1 climbed 15.6% to 71.0% through RL alone, and an intermediate checkpoint spontaneously wrote "Wait, wait. Wait." and re-evaluated, a literal "aha moment." Weakness: messy, unreadable output.

R1: a multi-stage pipeline

To fix readability and generality, R1 interleaves techniques: cold-start SFT on a few thousand readable long-CoT examples, then reasoning RL (with a language-consistency reward), then rejection sampling into ~800K SFT examples, then a final RL stage across all task types. Final R1: AIME 2024 79.8%, MATH-500 97.3%, Codeforces ~2029 Elo, on par with o1.
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 models
DeepSeek-R1 post-training pipeline. A production reasoning model is not one RL run: it interleaves SFT, rejection sampling, RL, and distillation, each stage fixing what the previous one broke.

Classic 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)

A single-step MDP, horizon T = 1. One prompt, one response, one scalar reward. The LLM is a static conditional generator. Full observability, no environment.

Agentic RL

A POMDP with T > 1. The agent takes many steps in an environment it only partially observes. Each action is text or a structured tool call; rewards are spread over the trajectory (often just +1 at the very end). The LLM is a learnable policy in a decision loop.

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 0
An agentic RLVR trajectory for a search agent, rewarded only on the final answer.

Under 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

The +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

Measuring : at small k, RLVR models beat their base models, RL makes the model sample the right answer more reliably. But at large k, base models catch up or overtake. The claim: current RLVR mostly sharpens the base model's existing distribution (better pass@1) rather than teaching genuinely new reasoning, while distillation can introduce new patterns from the teacher.[4] Counterpoint: ProRL argues that with enough training, entropy control, and reference resets, prolonged RL can expand the boundary.[11] Treat it as open: it directly shapes whether a team invests in RL or distillation.

Check yourself

Match each training concept to what it does.

drop here

imitate demonstrated trajectories

drop here

reward from an automatic correctness check

drop here

baseline from a group, no value model

drop here

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. 1.DeepSeek-AI, DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via RL
  2. 2.The Landscape of Agentic Reinforcement Learning for LLMs (survey)
  3. 3.OpenAI, Learning to Reason with LLMs (o1)
  4. 4.Does RL Really Incentivize Reasoning Capacity Beyond the Base Model?
  5. 5.Cameron R. Wolfe, GRPO Tricks
  6. 6.Bai et al., Constitutional AI: Harmlessness from AI Feedback
  7. 7.Meta, The Llama 3 Herd of Models
  8. 8.DAPO: An Open-Source LLM Reinforcement Learning System at Scale
  9. 9.Nathan Lambert, Reverse engineering OpenAI's o1 (Interconnects)
  10. 10.Nathan Lambert, RLHF Book: Synthetic Data & Distillation
  11. 11.ProRL: Prolonged Reinforcement Learning Expands Reasoning Boundaries