After studying this material, you should be able to:
Reinforcement Learning (RL) teaches AI systems through trial and error:
Traditional RL Loop:
Model โ Action โ Environment โ Observation โ back to Model
A harness is the external system that coordinates the AI model with tools and environments. Think of it as the "wrapper" around the model that handles:
Real-world examples: mini-SWE-agent, OpenHands, Claude Code, Codex
Traditional RL frameworks own the interaction loop โ meaning they control every step between the model and environment.
| Traditional Approach | The Problem |
|---|---|
| Developer must rebuild the agent inside the RL framework | Expensive and time-consuming |
| The rebuilt agent handles context differently | Trained agent โ deployed agent |
| Each new harness requires a new reimplementation | Not scalable |
Key Insight: You train one agent but deploy a different one. This gap undermines the entire purpose of training.
Instead of rebuilding the agent inside the training framework, place an LLM proxy between the agent and the model.
Traditional Agentic RL:
Environment โ [Tokenizer] โ Policy Model
Harnessed Agentic RL:
Environment โ [Agent Harness] โ [OpenAI-like API Proxy] โ Policy Model
Practical implication: To connect an existing agent to RL training, you only need to change the API endpoint URL. No code rewriting required.
| Harnessed Agentic RL | Benefit |
|---|---|
| Same harness in training and deployment | No behavior gap |
| No reimplementation needed | Saves development cost |
| Works with any OpenAI-compatible harness | Broadly applicable |
Because the harness controls the interaction loop, the training system only sees a series of LLM request/response pairs โ not a clean, continuous token trajectory. This creates four specific problems:
The problem:
Analogy: Imagine recording a conversation by summarizing it, then trying to reconstruct the exact words. The meaning may be preserved, but the precise wording changes.
The problem:
Correct approach: Calculate advantages at the rollout level, not the sample level.
Wrong: Advantage per sample โ rollouts with 5 samples weighted 5x more
Right: Advantage per rollout โ each rollout weighted equally
The problem:
Correct approach: Normalize loss at the rollout level to avoid this distortion.
The problem:
This requires dynamic scheduling logic that can handle unpredictable batch sizes.
Agent Lightning v1.0 is built from ~3,500 lines of code organized into three components:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ AGENT LIGHTNING v1.0 โ
โ โ
โ [Agent Harnesses] โ [API Gateway] โ
โ mini-SWE-agent Rollout API โ
โ OpenHands LLM API Proxy โ
โ OpenClaw โ โ
โ [Rollout Controller] โ
โ Local Reconciler โ
โ Kubernetes Reconciler โ
โ โ โ
โ [Customized Trainer] โ
โ Sample Adapter โ
โ Monitoring โ
โ โ โ
โ [Inference + Training Engine] โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Role: The central hub and LLM proxy
Functions:
Role: Manages agent execution
Functions:
Role: Orchestrates the training process
Functions:
Running many agents simultaneously is resource-intensive. There are three approaches:
| Approach | GPU Usage | Efficiency | Problem |
|---|---|---|---|
| Synchronous RL | Low (4 GPUs) | Low | Waits for slowest agent; GPUs sit idle |
| Asynchronous RL | High (8 GPUs) | High | Requires separate GPU pools; expensive |
| Collocated Async RL | Low (4 GPUs) | High | โ Best of both worlds |
Timeline:
[Rollout] [Rollout] [UPDATE] [Rollout] [Rollout] [UPDATE]
โ โ โ
Agents Agents GPUs switch to training
running running (API Gateway pauses new requests)
Step-by-step process:
Result: ~2x end-to-end speedup over synchronous RL, using fewer GPUs than asynchronous RL
Running many agents requires substantial CPU, memory, and compute. Other frameworks solve this by using paid commercial sandbox services (Modal Sandbox, E2B), which become expensive at scale.
Agents run as standard Kubernetes jobs on:
Flow:
API Gateway (holds rollout queue)
โ polls
Rollout Controller
โ creates
Kubernetes Jobs (agents run here)
โ status updates
API Gateway
Benefits:
| Component | Choice |
|---|---|
| Base model | Qwen3.5-9B |
| Agent harness | mini-SWE-agent |
| Training data source | SWE-smith (open source) |
| Training samples | ~6,000 |
| Benchmark | SWE-bench Verified |
Before RL training: 41.8% Pass@1
After RL training: 56.4% Pass@1
โโโโโโโโโโโโโ
Improvement: +14.6 percentage points
Significance: A 14.6-point gain using only ~6,000 samples and no large-scale compute demonstrates that Harnessed Agentic RL is both effective and accessible.
The experiments validated the advantage calculation and loss normalization decisions:
| Configuration | Validation Reward | Policy Entropy |
|---|---|---|
| Sample-level advantage | Lower | Unstable |
| Rollout-level advantage only | Medium | Climbs steeply (unstable) |
| Rollout-level advantage + rollout-level normalization | Highest (~0.37) | Stable and low |
Takeaway: Both rollout-level advantage AND rollout-level normalization are necessary together for best results.
| Concept | One-Line Definition |
|---|---|
| Agent Harness | External system coordinating model, tools, and environment |
| Harnessed Agentic RL | RL paradigm where the deployment harness participates directly in training |
| LLM Proxy | Intercepts model calls to record training data without modifying the harness |
| Rollout | One complete agent episode from start to finish |
| Collocated Async RL | Sharing GPUs between rollout and training with smart pause/resume logic |
| Rollout-level advantage | Computing RL advantage per episode rather than per individual sample |