Agent Lightning v1.0: A 3,500-Line Lightweight Agentic RL Framework for Training Agents with Real Harnesses
https://www.microsoft.com/en-us/research/blog/agent-lightning-v1-0-a-3500-line-lightweight-agentic-rl-framework-for-training-agents-with-real-harnesses/📌 Agent Lightning v1.0:3500 行程式碼,讓真實 Agent Harness 直接參與強化學習
TL;charge:Microsoft 開源輕量 RL 框架,訓練時不用重寫 Agent,SWE-bench Verified 直接拉高 14.6 個百分點。
訓練一個 coding agent 做強化學習,過去的代價是:你得先把它在訓練框架裡重寫一遍。重寫完的那個 agent,跟你實際部署的那個,往往已經不是同一個東西了。Microsoft Research Asia 這次直接把這個假設打掉重練。
🤔 問題出在「訓練框架擁有互動迴圈」這個假設
傳統 agentic RL 假設訓練框架自己掌控與環境互動的迴圈:模型產生 action,環境回傳 observation,接到 context 裡,再產生下一個 action,整個 rollout 對應到一條連續的 token 軌跡。verl、AReaL、slime 這些早期系統都是這樣設計的,代價是:想訓練一個 agent,就得把它的迴圈在 RL 框架裡重建一次。
但現實中的 harness 早就不是這麼簡單了。mini-SWE-agent、OpenHands、OpenCode、Claude Code、Codex,每一個都有自己的 context 管理、工具協定、執行邏輯與依賴套件。重建一次成本很高,重建完的 agent 行為也未必跟部署版一致。
🧩 把 LLM Proxy 塞進 Agent 和模型之間
Agent Lightning 的做法是在 agent 與模型之間插一層 LLM proxy。Agent 的執行方式不變,只要把原本呼叫模型 API 的 endpoint 指向 Agent Lightning,訓練框架就能觀察並記錄每一次模型呼叫。v1.0 把這個做法正式定義為 Harnessed Agentic RL:部署時用的那個 harness,直接參與訓練時的強化學習。
這樣一來,訓練系統只能看到一連串 LLM 的 request/response pair,一次 rollout 可能被拆成數量不固定的訓練樣本,這帶來了幾個系統設計上的挑戰。
整個框架約 3,500 行程式碼,核心是三個元件:
- API Gateway:存放 rollout、模型與事件資訊,同時是一個 OpenAI 相容的 LLM proxy,把每次模型呼叫對應回所屬 rollout,並記錄訓練需要的 prompt、response 與 log probability。
- Rollout Controller:負責啟動與管理 agent 執行,可以是本地行程,也可以是標準 Kubernetes job,讓 agent 執行與 trainer 分離。
- Customized Trainer:基於 verl 建構,建立 rollout、等待完成、收集樣本,再透過 sample adapter 組出最終訓練樣本。
對既有的 agent harness 而言,通常只要把模型 endpoint 指向 Agent Lightning proxy,就能快速接上 RL 訓練。
📊 Collocated Async RL:少用 GPU,還快了近兩倍
不同 agent 的 rollout 時間差異很大。同步 RL 要等批次裡最慢的 agent,GPU 閒置;全非同步 RL 利用率高,但需要為 rollout 與訓練分別配置 GPU 池。Agent Lightning v1.0 提出 Collocated Async RL,讓 rollout 與模型更新共用同一組 GPU:收集到足夠 rollout 後,API Gateway 暫停接受新請求,等進行中的請求完成,更新結束後 rollout 再恢復,整個狀態轉換對外部 agent harness 是透明的。實驗中,這個做法比同步 RL 達到約 2 倍的端到端加速,同時用的 GPU 比傳統非同步 RL 更少。
此外,為了不依賴 Modal Sandbox、E2B 等商業沙盒服務(成本隨規模快速攀升),Agent Lightning v1.0 把大量平行執行的 agent 跑成標準 Kubernetes job,重用既有的自管叢集、雲端 Kubernetes 或本機基礎設施,讓整條 pipeline 保持開源可復現。
研究團隊基於 SWE-smith、mini-SWE-agent 與 Qwen3.5-9B,建了一套完整 pipeline,涵蓋資料清理、環境構建、reward-hacking 防護與 RL 訓練,訓練集約 6,000 筆樣本,不需要大規模運算。純 RL 訓練就讓 Qwen3.5-9B 在 SWE-bench Verified 上從 41.8% 提升到 56.4%,漲了 14.6 個百分點。
💡 Rollout 層級的 advantage 計算更穩定
實驗也驗證了之前提到的兩個挑戰:advantage 計算與 loss normalization。相較於樣本層級的處理方式,採用 rollout 層級的 advantage 搭配 rollout 層級的 normalization,能取得更高的驗證 reward,訓練過程中的 policy entropy 也更穩定。
🎯 對工程師的意義
如果你手上已經有一套在生產環境運作的 agent harness,Harnessed Agentic RL 的價值在於:不需要為了做 RL 另外維護一套「訓練專用版 agent」。只要把模型呼叫導到 proxy,就能讓部署版本直接參與訓練迴圈,降低了訓練與部署行為不一致的風險。
🔗 來源
- 標題:Agent Lightning v1.0: A 3,500-Line Lightweight Agentic RL Framework for Training Agents with Real Harnesses
- 作者/機構:Microsoft — Zhiyuan He, Yuqing Yang
- 連結:https://www.microsoft.com/en-us/research/blog/agent-lightning-v1-0-a-3500-line-lightweight-agentic-rl-framework-for-training-agents-with-real-harnesses/
#AgenticRL #ReinforcementLearning #Microsoft #LLM #CodingAgent #SWEBench #OpenSource #MachineLearning #Kubernetes #AgentHarness
原始資料 Microsoft Research · 收集於 2026-10-07
摘要原文
AI agents have evolved from single models to complex full-stack systems built from models, tools, and execution environments. Their capabilities increasingly depend on the agent harness that coordinates them from outside the model. Reinforcement learning (RL) is an approach where AI systems learn through trial and error, guided by rewards and penalties for their actions. RL can make those agents better, but most agent RL systems require developers to reimplement the agent inside the training framework. That is costly, and it means the agent being trained is not quite the agent that gets deployed. To address this, researchers at Microsoft Research Asia have introduced the Harnessed Agentic RL training paradigm and open-sourced a fully rebuilt Agent Lightning v1.0 (opens in new tab) . Compared with the original, Agent Lightning, v1.0 puts more emphasis on staying lightweight, on integrating with real harnesses, and on a complete, reproducible agent RL training pipeline. Agent Lightning v1.0 was rebuilt around Harnessed Agentic RL, with key improvements: Traditional agentic RL assumes the training framework owns the interaction loop with the environment. In a ReAct-style loop, the model generates an action, the environment returns an observation, the observation is appended to the context, and the model generates the next action, so the whole rollout maps onto one continuous token trajectory. Early RL systems such as verl, AReaL, and slime were built this way, which meant training an agent required rebuilding its loop inside the RL framework. Real harnesses have outgrown that assumption. Coding agents such as mini-SWE-agent, OpenHands, OpenCode, Claude Code, and Codex each bring their own context management, tool protocols, execution logic, and dependencies, as do general-purpose agent systems. Rebuilding one for training is expensive, and the rebuilt agent may no longer behave in the same way as the deployed agent. Agent Lightning takes a different route. It places an LLM proxy between the agent and the model. The agent continues to run as before: simply point the endpoint that previously called the model API at Agent Lightning, and the training framework can observe and record its model calls. In v1.0, the researchers go further and formally define this paradigm as Harnessed Agentic RL: whichever agent harness is used in deployment is the harness that takes part directly in reinforcement learning during training (Figure 1). A core difference between Harnessed Agentic RL and traditional agentic RL is that the environment interaction loop is handled by the agent harness rather than the training framework. The training system can only observe a series of LLM request and response pairs, so a single rollout may be split into a variable number of training samples. This brings four key challenges: In system design, Agent Lightning v1.0 treats simplicity as its first principle. The entire framework is about 3,500 lines of code, with three core components: the API Gateway, the Rollout Controller, and the Customized Trainer (Figure 2). The API gateway stores rollouts, models, and events, and serves as an OpenAI-compatible LLM proxy. It links every model call from the harness to its rollout and records the prompts, responses, and log probabilities that training needs. The rollout controller starts and manages agent execution, either as local processes or as standard Kubernetes jobs, keeping agent execution separate from the trainer. The customized trainer, built on verl, creates rollouts, waits for them to finish, collects samples, and assembles the final training samples through a sample adapter. As a result, for an existing agent harness, simply pointing the model endpoint at the Agent Lightning proxy is usually enough to connect quickly to RL training. Rollout times vary widely across agents. Synchronous RL waits for the slowest agent in a batch and leaves GPUs idle, while fully asynchronous RL raises utilization but needs separate GPU pools for rollout and training. In response, Agent Lightning v1.0 introduces Collocated Async RL, which lets rollout and model updates share the same set of GPUs. Once the system has collected enough rollouts, the update begins: the API Gateway pauses accepting new requests and waits for requests already in progress to finish, and rollout resumes after the update completes. The entire state transition is transparent to the external agent harness. In experiments, this approach achieved about a 2x end-to-end speedup over synchronous RL while using fewer GPUs than conventional asynchronous RL (Figure 3). Collecting enough rollouts means running many agents at once, which consumes substantial CPU, memory, and compute resources. Other Harnessed Agentic RL frameworks often host those agents on commercial sandbox services such as Modal Sandbox or E2B, where cost climbs quickly with scale. Instead, Agent Lightning v1.0 runs them as standard Kubernetes jobs, reusing existing self-managed clusters, cloud Kubernetes, or local infrastructure (Figure 4). Existing compute resources are used more efficiently, large rollouts cost less, and the whole pipeline stays open source and reproducible. To test the approach, researchers built a full pipeline on SWE-smith, mini-SWE-agent, and Qwen3.5-9B, covering data cleaning, environment construction, reward-hacking safeguards, and RL training. The training set holds about 6,000 samples and needs no large-scale compute. RL training alone raised Qwen3.5-9B from 41.8% to 56.4% on SWE-bench Verified, a gain of 14.6 percentage points. The coding agent experiments further confirm the earlier analysis of two challenges: advantage calculation and loss normalization. Compared with sample-level handling, rollout-level advantage combined with rollout-level normalization achieves a higher validation reward and keeps policy entropy more stable during training (Figure 5). The post Agent Lightning v1.0: A 3,500-Line Lightweight Agentic RL Framework for Training Agents with Real Harnesses appeared first on Microsoft Research .
由 claude-code/sonnet 自動生成