Summary (Overview)
- Introduces "harnessed agentic RL": A paradigm where the deploy-time agent harness (not the training engine) owns the environment interaction loop, with RL training observing only LLM request-response pairs across a service boundary.
- Identifies four key challenges: retokenization/sample merging, advantage calculation, loss normalization, and training backend scheduling under dynamic sample counts—all arising from the disconnect between harness-owned execution and token-based training.
- Presents Agent Lightning v1.0: A lightweight (~3,500 lines of code) framework built on a disaggregated architecture (API Gateway, Rollout Controller, Customized Trainer) that supports arbitrary agent harnesses with minimal integration effort.
- Demonstrates strong empirical results: On coding agents, RL alone improves Qwen3.5-9B on SWE-bench Verified from 41.8% to 56.4% (absolute +14.6%) using only ~6K training examples and modest compute.
- Releases complete reproducible pipeline: Includes data-cleaning pipeline, reward-hacking safeguards, and training scripts for coding agents—addressing a significant gap in existing RL frameworks.
Introduction and Theoretical Foundation
Background
Modern agents do not operate as standalone LLMs; they run inside agent harnesses that manage tools, execution environments, context, and control flow. Examples include mini-SWE-agent, OpenHands, OpenCode, Claude Code, and Codex for coding, and OpenClaw and Hermes for general purposes.
Problem with Traditional RL Frameworks
Early RL frameworks (verl, AReaL, slime) require the agent loop to be implemented inside the training framework. Integrating existing harnesses is difficult due to their complex implementations and dependencies.
The Proxy-Based Approach
The original Agent Lightning work introduced a disaggregated architecture connecting arbitrary agents to RL training through an LLM endpoint proxy. This approach has been adopted by verl Uni-Agent, AReaL 2.0, slime v0.3.0, and Polar.
Formal Distinction: Traditional vs. Harnessed Agentic RL
Both paradigms admit a POMDP formulation but differ fundamentally:
| Agentic RL | Harnessed Agentic RL | |
|---|---|---|
| State | Environment | Harness + environment |
| Model input | Continuous token history | Per-call prompts |
| Agents | Single ReAct agent | Multi-agent, subagents, handoffs |
Traditional agentic RL: The policy model interacts almost directly with the environment. The token history extends as:
Harnessed agentic RL: The harness owns context construction and control flow. A rollout is exposed at the model boundary as a sequence of request-response pairs:
The latent state is:
with the prompt constructed as:
Each policy decision is a call-level transition:
Methodology
System Architecture
Agent Lightning v1.0 bridges the training cluster and agent execution cluster through three components:
- API Gateway: Stores rollouts, models, and events; forwards LLM calls from agent harnesses to registered model endpoints.
- Rollout Controller: Manages agent execution on Kubernetes (or local processes), polling rollouts and launching agent tasks.
- Customized Trainer: Built on VERL; registers rollouts, waits for completion, retrieves events to assemble training samples.
Key Design Innovations
1. Collocated Async RL: Unlike synchronous RL (waits for slowest rollout) or asynchronous RL (requires separate GPU pools), collocated async RL time-shares the same GPUs between rollout and update phases. The API Gateway stops accepting new requests during updates and pauses incoming ones—making the switch invisible to the harness. Achieves ~2x end-to-end speedup over sync RL with fewer GPUs.
2. Network Reliability:
- Idempotent API Gateway endpoints for safe retries
- Deduplication of repeated LLM calls (keeping only the most recent when identical prompts appear)
3. Kubernetes Integration: Agents run as standard Kubernetes Jobs on self-hosted compute, avoiding commercial sandbox costs (vs. Modal Sandbox, E2B used by other frameworks).
Addressing the Four Challenges
Challenge 1: Retokenization and Sample Merging
Token-prefix continuity requires:
Even when text-level prefix holds, token-level prefix breaks due to:
- Chat-template non-compositionality:
- Decode-retokenize drift:
- Inference-time output transformation (tool-call parsing, reserialization)
Agent Lightning's approach: Best-effort sequence merging—merge calls only when token IDs satisfy the prefix condition; otherwise close the current sequence and start a new one. This preserves rollout prompts and works with standard dense causal kernels.
Challenge 2: Advantage Calculation
A rollout can produce a dynamic number of training samples . The paper argues for rollout-level advantage (rather than sample-level): retokenization and subagent spawning are incidental phenomena that should not change group baselines. Example: two rollouts with rewards 1 and 0; if Rollout 1 splits into 3 samples, rollout-level baseline is vs. sample-level .
Challenge 3: Loss Normalization
Three options compared:
- Token-mean (DAPO):
- Seq-mean-token-mean (GRPO):
- Rollout-level token-mean (slime):
Agent Lightning's choice: Rollout-level token-mean (Equation 16), as sample-level normalization gives disproportionate weight to rollouts with more samples, and token-mean is sensitive to long sequences.
Challenge 4: Training Backend Scheduling
The training batch must preserve statistical provenance:
Sequences from one rollout must remain in the same optimizer update to avoid within-rollout policy skew.
Empirical Validation / Results
Experiment Settings
| Setting | Model | Algorithm | Dataset | Result |
|---|---|---|---|---|
| Search Agent | Llama-3.2-3B-Instruct | GRPO | HotpotQA | Validation reward: 25.1% → 41.7% (+16.6%) |
| Instruction-Following | Qwen3-4B-Instruct-2507 | RLOO | Instruction Pre-Training | Validation reward: 51.9% → 70.2% (+18.3%) |
| Coding Agent | Qwen3.5-9B | GRPO | SWE-smith | SWE-bench Verified: 41.8% → 56.4% (+14.6%) |
Coding Agent Details
Dataset Pipeline (from 59,136 SWE-smith tasks):
- Removed 18,033 tasks with empty problem statements
- Removed 1,265 tasks with missing problem branches
- Removed tasks requiring >200 tests
- Applied model-based difficulty filter (Qwen3.5-9B run 4 times per task)
- Final: ~6,000 training examples, 400 test examples
Reward Hacking Prevention:
- Disabled Git commands and hid
.gitdirectory (prevented finding gold commits) - Enforced Kubernetes network policy blocking general outbound access (prevented fetching source from GitHub/pip)
Ablation Study on Design Choices
Three settings compared (all using GRPO objective):
| Setting | Validation Reward (step 128) |
|---|---|
| Sample-level Advantage + Token-mean Loss | 35.0% |
| Rollout-level Advantage + Token-mean Loss | 33.1% |
| Rollout-level Advantage + Rollout-level Norm | 38.2% |
The full variant (rollout-level advantage + rollout-level normalization) achieved the highest validation reward with more stable policy entropy.
Rollout Merging Statistics
- Only 36% of rollouts remain as a single training sample on average
- Each rollout yields 2.41 training samples on average
Theoretical and Practical Implications
Theoretical Contributions
- First systematic characterization of harnessed agentic RL challenges, providing formal definitions of retokenization drift, dynamic sample counts, and their consequences.
- Principled argument for rollout-level statistics: Sample counts are driven by incidental factors (retokenization, subagent spawning), so advantage and loss normalization should be computed at the rollout level to maintain algorithmic correctness.
- Formal distinction between traditional and harnessed agentic RL as POMDPs with different latent states and observations.
Practical Implications
- Reproducibility: Complete data pipeline and training scripts for coding agents—filling a major gap where existing frameworks lack data and complete training examples.
- Resource accessibility: Demonstrates strong results with only ~6K examples and modest compute, making agentic RL feasible for smaller teams.
- Cost reduction: Self-hosted Kubernetes execution avoids commercial sandbox costs; collocated async RL reduces GPU requirements vs. async RL.
- Harness-agnostic design: Any agent harness can connect by switching its LLM endpoint to the proxy, requiring almost no changes to the agent.
Conclusion
Agent Lightning v1.0 characterizes harnessed agentic RL—a paradigm where the deploy-time harness owns the environment interaction loop—and identifies four key challenges: retokenization/sample merging, advantage calculation, loss normalization, and training backend scheduling. The framework implements rollout-level design choices for these challenges in approximately 3,500 lines of code, supporting arbitrary agent harnesses.
Key results: RL alone improves Qwen3.5-9B on SWE-bench Verified from 41.8% to 56.4% (+14.6%) using ~6K examples; search agents improve +16.6%; instruction-following agents improve +18.3%.
Future directions:
- Better credit assignment across samples within a rollout
- Further study of tree-structured training for prefix reuse
- Extension to more complex multi-agent scenarios
The full codebase and scripts are released to facilitate reproducible harnessed agentic RL research (github.com/microsoft/agent-lightning).
Related papers
- EvoMem: Memory-Augmented Evolution for Code Optimization
EvoMem's persistent memory of successful mutation strategies yields a 6.40% average performance gain and 5.93x speedup in LLM-based evolutionary code search.
- HarnessOpt-Bench: Evaluating LLMs at Harness Optimization
HARNESSOPT-BENCH shows optimizer model choice matters 1.8x more than coding harness choice for agent improvement, with broader search driving gains and trace reading providing no benefit.
- Does RoPE Prevent or Degrade Retrieval Heads? A Mechanistic Analysis Across Model Families
RoPE's frequency axis, not dimension utility, is causally load-bearing for retrieval heads, with zeroing low-frequency dimensions collapsing recall across all model families tested.