NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Training Long-Context, Multi-Turn Software Engineering Agents with Reinforcement Learning

Alexander Golubev, Maria Trofimova, Sergei Polezhaev, Ibragim Badertdinov, Maksim Nekrashevich, Anton Shevtsov, Simon Karasik, Sergey Abramov, Andrei Andriushchenko, Filipp Fisin, Sergei Skvortsov, Boris Yangel · DOI

Overview

This research introduces a sophisticated two-phase training pipeline designed to evolve open-weight Large Language Models (LLMs) into autonomous software engineering (SWE) agents. By transitioning from single-turn reinforcement learning (RL) to multi-turn interactions with long contexts (up to 131k tokens), the study demonstrates that a 72B-parameter model can rival the performance of significantly larger proprietary models. The proposed pipeline improved the Qwen2.5-72B-Instruct model's performance on the SWE-bench Verified benchmark from 11.4% to 39.0%.

The Challenge: Modeling Software Engineering as a POMDP

Traditional RL for LLMs often treats tasks as "bandit" problems—single-turn scenarios like mathematical reasoning where a model takes one action and receives an immediate reward. However, real-world software engineering is fundamentally a Partially Observable Markov Decision Process (POMDP). It requires agents to interact with stateful environments—terminals, file systems, and test suites—over dozens of turns. Each action generates an observation that must be integrated into the agent's long-term context to inform subsequent steps.

The difference between bandit-style tasks (top) and multi-turn POMDPs like software engineering (bottom).

Methodology

The authors employ a two-phase approach to bridge the gap between simple generation and complex interaction:

Phase 1: Rejection Fine-Tuning (RFT)

To initialize the model's capabilities, the researchers generated multiple trajectories for training tasks, retaining only those that successfully passed the associated test suites. During supervised fine-tuning, they implemented a critical masking strategy: turns containing formatting or tool-use errors were excluded from the loss calculation. This ensured the model learned exclusively from valid, successful interaction patterns.

Phase 2: Multi-Turn RL with DAPO

The second phase utilizes Direct Advantage Policy Optimization (DAPO), a variant of Group-Relative Policy Optimization (GRPO). DAPO calculates advantages relative to a group of trajectories sampled from the same prompt, removing the need for a separate, computationally expensive critic model. This RL stage was executed in two steps:

  1. Stage 1: Training with a 65k token context window.
  2. Stage 2: Scaling to a 131k token context window and doubling the maximum turn count to accommodate long-horizon tasks.

Key Insights for Agentic Training

  • Retaining Long Trajectories: Contrary to common practices that discard long, noisy trajectories, the authors found that keeping them provides a necessary negative signal. Long trajectories often indicate an agent stuck in a loop; RL helps the model learn to break these cycles.
  • Unbiased Sampling: The study highlights that using decoding filters like top-k during RL rollout generation can lead to training instability due to distribution mismatch. Maintaining unbiased sampling (temperature only) is essential for stable gradients.
  • Efficiency Penalties: To prevent infinite loops and encourage concise problem-solving, a linear penalty was introduced for trajectories exceeding a specific turn threshold.

Results and Performance

The training pipeline yielded substantial improvements across all evaluated benchmarks. The base Qwen2.5-72B-Instruct model, which initially scored 11.4% on SWE-bench Verified, reached 20.5% after RFT and peaked at 39.0% following the final RL stage.

Comparison of model performance across SWE-bench and SWE-rebench splits.

As shown in the performance table, the final model is competitive with DeepSeek-V3-0324 (39.6%) and significantly outperforms other open-weight alternatives such as Llama-4 Maverick.

Conclusion and Future Directions

While the results are promising, the authors identify several areas for future research. The "sparse reward" problem remains a challenge, as agents only receive feedback at the end of long sequences; reward shaping for intermediate steps could improve credit assignment. Additionally, developing "risk-aware" agents that can output confidence scores or abstain from tasks when uncertain could improve reliability in production environments. Finally, the high computational cost of unrolling long-context trajectories necessitates more efficient inference and evaluation frameworks.

Summary updated

BibTeX
@misc{golubev2025training,
  author = {Alexander Golubev and Maria Trofimova and Sergei Polezhaev and Ibragim Badertdinov and Maksim Nekrashevich and Anton Shevtsov and Simon Karasik and Sergey Abramov and Andrei Andriushchenko and Filipp Fisin and Sergei Skvortsov and Boris Yangel},
  title = {{Training Long-Context, Multi-Turn Software Engineering Agents with Reinforcement Learning}},
  year = {2025},
  eprint = {2508.03501},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2508.03501},
}
Figure