LEGO-RL: Harness-Native Reinforcement Learning for Coding Agents

Yiming Du, Yuxin Jiang, Tao Yuan, Jianbo Dai, Shaowei Wang, Jierun Chen, Chaofan Tao, Xianzhi Yu, Lifeng Shang, Kam-Fai Wong, Xiaohui Li, Haoli Bai

arXiv:2608.17393 · 2026-08-20 공개 · arXiv · PDF

reinforcement-learning swe-bench coding-agents reward-hacking policy-gradient gspo sandbox-orchestration llm-proxying

Abstract

Reinforcement learning for coding agents increasingly relies on long-running agent harnesses to manage tool integration, repository contexts, and execution feedback. However, the native execution environments of these harnesses are inherently misaligned with policy-gradient training: environmental crashes and reward hacking corrupt outcome signals, while train-inference discrepancies decouple rollout behavior from policy updates. To address this, we present LEGO-RL, a framework that bridges native coding-agent harnesses with scalable policy-gradient optimization without modifying their internal control flow. LEGO-RL is built upon three pillars: (1) faithful optimization via in-process LLM proxying that captures raw generation streams for token-level alignment and robust trainer-side log-probability recomputation, even under harness-side compaction or re-serialization; (2) reliable execution via scalable sandbox orchestration featuring image caching and stage-wise defenses to mitigate reward hacking; and (3) observable training through an integrated plugin that automates validation and monitoring, paired with a Live UI for granular trajectory diagnostics. We evaluate LEGO-RL by training the sparse MoE model Qwen3.5-35B-A3B with GSPO across three native coding-agent harnesses. LEGO-RL improves Qwen3.5-35B-A3B across OpenHands SDK (64.0% to 70.4%), Claude Code (62.4% to 68.2%), and OpenCode (57.2% to 66.6%) on SWE-bench Verified, while maintaining a rollout-training probability correlation above 0.99.

한국어 요약

한 줄 요약

LEGO-RL은 기존 코드 에이전트 허네스를 수정하지 않고 정책 기울기 최적화를 연결하는 프레임워크로, SWE-bench Verified에서 6~9% 성능 향상을 달성했다.

핵심 기여도

핵심 아이디어

기존 코드 에이전트 허네스는 정책 기울기 최적화와 호환되지 않는데, 이는 실행 환경의 불안정성과 훈련-추론 불일치로 인해 발생한다. LEGO-RL은 허네스 내부 제어 흐름을 변경하지 않고도 정책 최적화를 가능하게 하기 위해 세 가지 핵심 기술을 결합한다. 첫째, **in-process LLM proxying**은 토큰 스트림을 직접 캡처하여 훈련 측에서 로그 확률을 재계산할 수 있도록 하며, 특히 **mixture-of-experts 모델**의 라우팅 결정을 훈련 시 재현한다. 둘째, **scalable sandbox orchestration**은 샌드박스 실패나 보상 조작을 방지하고, **stage-wise defenses**를 통해 트레이젝토리의 신뢰성을 유지한다. 셋째, **Live UI**와 **트레이젝토리 레벨 진단**을 통한 관측 가능성(Observable training)을 제공하여 실패 원인을 정확히 파악할 수 있다.

기술적 접근법

주요 결과

의의 및 한계

LEGO-RL은 기존 코드 에이전트 허네스를 수정하지 않고도 정책 기울기 최적화를 가능하게 하여, **SWE-bench Verified**에서 6~9%의 성능 향상을 달성하며, **Qwen3.5-35B-A3B** 모델의 훈련 안정성과 신뢰성을 높였다. 특히, **mixture-of-experts 모델**의 라우팅 재현과 **샌드박스 실행의 신뢰성**을 강화한 점이 학술적·실용적 가치를 제공한다. 그러나, **새로운 허네스 지원**을 위해서는 **lightweight adapter** 개발이 필요하며, **모델 크기나 복잡도가 증가할 경우** 성능 향상 폭이 줄어들 수 있다는 한계가 있다.

실용적 활용

LEGO-RL은 코드 생성 에이전트를 기반으로 한 소프트웨어 개발 자동화, 코드 리뷰, 버그 수정 등에 활용 가능하다. 특히, **OpenHands SDK**, **Claude Code**, **OpenCode**와 같은 기존 허네스를 기반으로 한 에이전트 개발자들이 정책 기울기 최적화를 쉽게 적용할 수 있도록 지원한다.