Skip to content

Agent Lightning: Train ANY AI Agents with Reinforcement Learning

Skip →Agentic data scaling laws
Agents stage 2 #12corefrontierpaperrubric 10/122025 · ~60 min

Xufang Luo, Yuge Zhang, Zhiyuan He, …, Yuqing Yang

Read first: DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models

Status

TL;DR. Agent Lightning separates running an agent from training its LLM. The 2025 paper models any agent run as a list of LLM calls, each a transition (input, output, reward), and trains them with LightningRL: give every call the run’s final reward, then apply a single-turn RL algorithm such as GRPO (Group Relative Policy Optimization, which samples several outputs per prompt and uses their mean reward as the baseline instead of a learned critic). Agent Lightning v1.0 (tech report and MSR blog, 2026) is a complete rewrite in about 3,500 lines. It records calls through an API proxy while the agent’s own harness keeps control of the loop, and it works out what happens to merging, advantage baselines and loss normalisation when one rollout produces a variable number of training samples.

Why it matters now. Real search agents are not tidy ReAct loops written inside a trainer. They live in frameworks that summarise context, branch and call tools. If you want to RL-train the retrieval agent you already have, rather than re-implementing it inside verl, this is the design pattern, and v1.0 lists the traps you will hit. The v1.0 search-agent experiment follows the Search-R1 setup, close to what an IR group would run.

Which release says what. The 2025 paper (arXiv 2508.03680) introduced the transition interface, LightningRL, the server/client split and Automatic Intermediate Rewarding. The v1.0 tech report (arXiv 2608.17528) and the MSR v1.0 blog introduced harnessed agentic RL, the proxy-based design, best-effort merging, rollout-level advantage and normalisation, and the SWE-bench results. Read each claim below against its release.

2025: from agent runs to transitions. Whatever framework the agent uses, the trainer sees only the LLM calls. A run of T calls becomes (Eq. 6)

executionRL={(inputt, outputt, rt)}t=1T,outputt=πθ(inputt).\text{execution}^{\text{RL}} = \big\{(\text{input}_t,\ \text{output}_t,\ r_t)\big\}_{t=1}^{T},\qquad \text{output}_t=\pi_\theta(\text{input}_t).

LightningRL then works on two levels:

  1. Across calls. In the current implementation every call receives the run’s final return, which the paper calls identical assignment. A learned value function over calls is left as future work.
  2. Within a call. A standard single-turn algorithm (GRPO, PPO or REINFORCE++) trains the output tokens. With GRPO, calls from runs of the same task form the group.

Because each call keeps its own prompt, there is no need to concatenate the whole run and mask out tool tokens. The paper argues this gives shorter sequences, lets you train only selected agents in a multi-agent program, and avoids breaking the position continuity that rotary position encodings assume. A Training-Agent Disaggregation design puts a Lightning Server (wrapping verl, with an OpenAI-like API) on the GPUs and a Lightning Client (tracing via OpenTelemetry/AgentOps) next to the agent. Automatic Intermediate Rewarding (AIR) turns monitoring signals, such as whether a tool call returned an error, into intermediate rewards.

v1.0: harnessed agentic RL. The harness (tools, context management, control flow) owns the loop; the trainer sees the calls (pi,ai)(p_i, a_i) passing through a proxy. Two consecutive calls can be merged into one training sequence only if the new prompt extends the previous prompt and response. Text continuity (Eq. 8) is not enough; the token IDs must continue (Eq. 9):

(pitok, aitok)⪯pi+1tok.(p_i^{\text{tok}},\ a_i^{\text{tok}}) \preceq p_{i+1}^{\text{tok}} .

This fails in practice for three reasons:

  • Retokenization drift: “having” sampled as h + aving comes back as hav + ing.
  • Non-compositional chat templates: some templates drop earlier think blocks when a new turn is rendered.
  • Tool parsers: they rewrite the response text.

v1.0 uses best-effort merging: merge when Eq. 9 holds, otherwise start a new sample. It rejects buffered token replacement because the stitched prompt was never consumed during rollout. The result is that one rollout produces a variable number NρN_\rho of samples, all inheriting the rollout’s outcome reward. In the report’s coding runs only 36% of rollouts stayed a single row, averaging 2.41 samples per rollout (Fig. 10).

Once a rollout can become several samples, three separate design choices follow. They are easy to conflate, so take them in order:

  1. Which samples inherit the reward. In v1.0 every sample of a rollout inherits that rollout’s outcome reward (there is no per-sample reward).
  2. Which units define the baseline. The advantage baseline can average over samples or over rollouts.
  3. Which units get equal loss weight. The loss can give equal weight to every token, every sample or every rollout.

Choice 1 is fixed; choices 2 and 3 are the two weighting questions v1.0 studies:

  • Advantage baseline (choice 2). In the report’s example (Fig. 4), rollout 1 (reward 1) splits into three samples and rollout 2 (reward 0) stays one sample. The sample-level baseline is (1+1+1+0)/4=3/4(1+1+1+0)/4 = 3/4; the rollout-level baseline is (1+0)/2=1/2(1+0)/2 = 1/2. v1.0 argues for the rollout level, so that splitting does not shift the baseline.
  • Loss normalisation (choice 3). Token-mean (Eq. 14) weights rollouts by length; seq-mean-token-mean (Eq. 15) weights them by how many samples they split into. Token-mean and rollout-level token-mean are both unchanged if the same tokens are repartitioned into more samples; only seq-mean-token-mean rewards splitting. v1.0 uses a rollout-level token-mean (Eq. 16), which also gives each rollout equal total weight:
Lrollout=1∣R∣∑ρ∈R1∑j=1Nρ∣aρ,j∣∑j=1Nρ∑k=1∣aρ,j∣ℓρ,j,k.\mathcal{L}_{\text{rollout}} = \frac{1}{|\mathcal{R}|}\sum_{\rho\in\mathcal{R}} \frac{1}{\sum_{j=1}^{N_\rho}|a_{\rho,j}|}\sum_{j=1}^{N_\rho}\sum_{k=1}^{|a_{\rho,j}|}\ell_{\rho,j,k}.

The backend must also keep a rollout’s samples in the same optimiser update. Otherwise parts of one rollout are trained under different policy versions.

Agent Lightning v1.0: harness, proxy, merging and rollout-level training Top row: the agent harness, which owns tools, context and control flow, sends LLM calls to an API gateway proxy that logs prompts and token IDs and forwards them to the policy server. Bottom left: one rollout makes three calls; calls one and two satisfy the token-prefix condition and are merged into sample one, while call three breaks the prefix and starts sample two. Bottom right: the trainer makes three separate, numbered choices: first, every sample inherits the rollout reward; second, the advantage baseline is computed over rollouts; third, the loss weights each rollout equally with a rollout-level token-mean, then sends new weights to the policy server. Footer: the sample-level baseline in the report's example is three quarters, while the rollout-level baseline is one half. agent harness tools · context · flow calls API gateway proxy logs (pᵢ, aᵢ) token IDs policy server π_θ generates aᵢ Best-effort merging of one rollout call 1 call 2 call 3 sample 1 (calls 1 + 2) sample 2 token prefix holds 1 → 2, breaks 2 → 3, so a new sample starts trainer (verl) 1. reward: R → every sample 2. baseline unit: rollout 3. loss: rollout token-mean one rollout, one update new weights Fig. 4 example: sample baseline (1+1+1+0)/4 = 3/4 vs rollout baseline (1+0)/2 = 1/2
Original sketch. The agent harness keeps its own loop and calls the policy through a proxy that records prompts and token IDs. Calls whose token IDs continue are merged; otherwise a new sample starts. The trainer box lists three separate choices: (1) every sample inherits the rollout reward, (2) the advantage baseline is computed over rollouts, (3) the loss gives each rollout equal weight.

2025 paper (paper-reported). It trains Llama-3.2-3B on three agents:

  • Spider text-to-SQL with LangChain (three agents, two trained);
  • MuSiQue retrieval QA with the OpenAI Agents SDK, over a 21M-document Wikipedia index with BGE embeddings and reward 0.9·F1 + 0.1·format;
  • Calc-X maths with AutoGen.

Results are shown as rising train and test reward curves (§5); there are no final-accuracy tables or comparisons with other trainers.

v1.0 report (paper-reported; the MSR blog repeats the same numbers).

  • Search agent (Search-R1 setup). Llama-3.2-3B-Instruct with GRPO, trained on HotpotQA and validated on 50 questions each from six QA sets. Validation EM rose from 25.1% to 41.7% (Fig. 7).
  • Instruction-following agent (LLM-in-Sandbox setup). 51.9% → 70.2% (Fig. 8).
  • Coding agent (mini-SWE-agent harness). Qwen3.5-9B on about 6K cleaned SWE-smith tasks went from 41.8% to 56.4% on SWE-bench Verified.
  • Fig. 9 ablation, at step 128:
    • sample-level advantage 35.0%;
    • rollout-level advantage only 33.1%;
    • rollout-level advantage plus rollout-level normalisation 38.2%, with steadier policy entropy.
  • System. Collocated asynchronous training gave roughly 2× end-to-end speedup over synchronous RL, using fewer GPUs than fully asynchronous training.

All v1.0 curves are single runs as presented.

  • “ANY” is a title, not a guarantee. The 2025 evidence is three small agents with curves. v1.0 shows that compatibility needs merging rules, network-retry handling and environment sandboxing. The blog presents pointing the agent at the proxy as usually sufficient, not always.
  • Credit assignment remains coarse. Identical assignment gives a wasted search call the same credit as the decisive one. AIR and value functions are proposed but not evaluated in depth.
  • The ablations are thin. One run per setting, validation reward only, and no combination of sample-level advantage with rollout-level normalisation.
  • Best-effort merging trades compute for exactness. Unmerged calls recompute long shared prefixes. Tree-packed attention is discussed as an alternative that needs heavy backend support.

Questions to think through

These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.

  1. Derive / compute

    A GRPO group has three rollouts. Rollout A was split into two samples of 50 and 100 response tokens, rollout B into three samples of 30 tokens each, and rollout C stayed one sample of 40 tokens. Compute the weight each token gets, and the total weight each rollout gets, under token-mean (Eq. 14), seq-mean-token-mean (Eq. 15) and rollout-level token-mean (Eq. 16). Which scheme lets a rollout gain influence just by being split?

    What a strong answer covers
    • Token-mean: 280 tokens in total, so every token gets 1/280. Rollout totals are A = 150/280 ≈ 0.54, B = 90/280 ≈ 0.32, C = 40/280 ≈ 0.14, so long rollouts dominate.
    • Seq-mean-token-mean: six samples at 1/6 each, then averaged within a sample. Per-token weights are A1 1/300, A2 1/600, B 1/180, C 1/240. Rollout totals are A = 1/3, B = 1/2, C = 1/6.
    • Rollout-level token-mean: each rollout gets 1/3, spread over its own tokens. Per-token weights are A 1/450, B 1/270, C 1/120.
    • Seq-mean-token-mean rewards splitting: B has fewer tokens than A (90 vs 150) but gets the most weight because it became three samples. Both token-mean and rollout-level token-mean are invariant to repartitioning unchanged tokens into samples; only rollout-level token-mean also gives every rollout equal total weight.
  2. Mechanism

    Explain why two consecutive LLM calls whose text satisfies the prefix condition (Eq. 8) can still fail the token-prefix condition (Eq. 9). Give the retokenization example and one template-level cause, and say what v1.0 does when the token condition fails and why it does not use buffered token replacement.

    What a strong answer covers
    • The harness stores text, not token IDs. When call i+1 re-tokenizes the history, the previously sampled response can get different token boundaries: having sampled as h + aving comes back as hav + ing.
    • Chat templates are not compositional: some templates (for example Qwen-style reasoning templates) drop earlier think blocks when a new turn is rendered, so the next prompt is not an extension of the previous one even in text.
    • v1.0 uses best-effort merging: if the observed token IDs satisfy Eq. 9 it appends only the new suffix and action to the current sample; otherwise it closes the sample and starts a new one.
    • Buffered replacement (used by some other frameworks) splices the originally sampled tokens into the new prompt. That produces a prompt the model never consumed during rollout, so the training data become slightly off-policy; best-effort merging keeps the exact prompts at the cost of more, shorter samples.
  3. What if…

    Figure 9 of the v1.0 report compares three coding-agent runs at step 128: sample-level advantage (35.0%), rollout-level advantage only (33.1%), and rollout-level advantage plus rollout-level normalisation (38.2%). What does each comparison isolate, why might the advantage fix alone hurt, and what further runs would you want before trusting the conclusion?

    What a strong answer covers
    • Baseline versus advantage-only isolates the advantage baseline: computing the group mean over rollouts rather than samples stops split rollouts from shifting the baseline.
    • Advantage-only versus both fixes isolates loss normalisation. The report attributes the gain to controlling the entropy growth seen in the advantage-only run; with token-mean, many long negative samples can dominate the update.
    • The advantage fix alone can hurt because it changes the per-sample signal while the loss still weights rollouts by token count, so the two choices interact.
    • Before trusting it: multiple seeds and confidence intervals, full curves rather than one step, held-out evaluation beyond the validation reward, and the fourth combination (sample-level advantage with rollout-level normalisation).
  4. Mechanism

    In the 2025 paper's LightningRL, a multi-call agent run becomes a list of transitions (input_t, output_t, r_t). Explain how the final reward is assigned to transitions, how a single-turn algorithm such as GRPO then trains them, and two advantages the paper claims over concatenating the whole run and masking non-policy tokens.

    What a strong answer covers
    • Each LLM call is one transition: the input is the full prompt the agent built (instructions, history, tool results) and the output is the sampled response.
    • Credit assignment over actions in the current implementation is identical: every transition in the run receives the run's final return R. A learned high-level value function is mentioned as a future option.
    • A single-turn RL algorithm then handles tokens inside each output; with GRPO, transitions from runs of the same task x form the group used for the baseline.
    • Claimed advantages: each call keeps its own context (no ever-growing concatenation, so shorter sequences), the trainer can optimise only selected agents in a multi-agent program, and position continuity is preserved, whereas masking removes tokens from a sequence whose rotary position encoding assumes continuity.
  5. Design

    You have a working retrieval agent built in a third-party framework: it calls BM25, reranks, reads documents and answers. You want to RL-train its 7B policy with Agent Lightning v1.0 for BrowseComp-Plus-style questions. Describe what you change in the agent, where the reward comes from, which advantage and loss settings you choose, and how you guard against reward hacking.

    What a strong answer covers
    • Change: point the agent's LLM endpoint at the v1.0 API gateway proxy, which records each call's prompt and token IDs; the harness keeps owning tools, context management and control flow.
    • Reward: an outcome reward on the final answer (exact match or an LLM judge against gold answers), assigned to every sample of the rollout; optionally a small retrieval-quality signal from judged documents.
    • Settings: rollout-level advantage and rollout-level token-mean loss, so a rollout whose context was summarised or branched into several samples does not get extra weight; keep a rollout's samples in one optimiser update.
    • Hacking guards: the training corpus must not contain the gold answers in easily copyable form, block outbound network access (the coding runs found agents fetching solutions with wget or pip), and audit high-reward trajectories by hand.
  6. Critique

    The 2025 title promises to train "ANY" agent with "almost zero code modification". Using what each release actually demonstrates, critique this claim. What evidence does the 2025 paper give, what did v1.0 have to add, and which kinds of agent would still be hard to train?

    What a strong answer covers
    • The 2025 paper shows three agents (LangChain text-to-SQL on Spider, OpenAI Agents SDK retrieval on MuSiQue, AutoGen maths on Calc-X) with Llama-3.2-3B, reporting reward curves only: evidence of compatibility, not of competitive final accuracy.
    • v1.0 shows that intercepting calls is the easy part. Real harnesses summarise and branch their context, so calls cannot always be merged, and the trainer must then fix advantage and loss weighting for a variable number of samples per rollout.
    • v1.0 also needed network reliability handling, Kubernetes rollout control, and environment sandboxing against reward hacks: integration work outside the agent's own code.
    • Still hard: agents that call closed-model APIs for the policy step, agents whose reward cannot be computed automatically, very long or non-terminating runs, and harnesses that rewrite the context in ways that break the token-prefix condition at almost every call.

Done with this page?

Status