Imitation Learning for Multi-turn LM Agents via On-policy Expert Corrections

Niklas Lauffer, Xiang Deng, Srivatsa R Kundurthy, Brad Kenstler, Jeff Da

Training Large Language Model (LLM) agents to handle complex, multi-turn tasks—such as navigating a codebase to fix a bug—is notoriously difficult. While imitation learning from expert demonstrations is the standard starting point, it often falls short in real-world deployments. This paper introduces a novel data generation strategy designed to bridge the gap between "watching an expert" and "learning to recover from your own errors." By implementing On-policy Expert Corrections (OECs), the authors mitigate covariate shift, achieving state-of-the-art performance for 7B and 32B model classes on the SWE-bench Verified benchmark.

The Challenge: Covariate Shift in Multi-Turn Tasks

The core limitation of traditional imitation learning (Behavioral Cloning) is covariate shift. Models are typically trained on gold-standard expert trajectories. However, during deployment, the student model will inevitably make a small mistake. Because it was only trained on perfect paths, it lacks the knowledge to handle the imperfect state it just created.

In multi-turn agentic tasks like software engineering, these errors compound. A student might look at the wrong file or misinterpret a compiler error, causing the environment state to diverge completely from anything seen in the expert training data. The model drifts off the path and enters a spiral of confusion.

Methodology: On-Policy Expert Corrections (OEC)

Taking inspiration from the classic robotics algorithm DAgger (Dataset Aggregation), the authors adapt the concept for the high-compute world of LLMs. Their method, OEC, operates through a four-step process:

  1. The Roll-in: A student model (e.g., Qwen2.5-Coder-7B) begins a trajectory on a software bug-fixing task.
  2. The Switch: At a randomly selected turn, the system swaps the student for an "expert" model (e.g., Claude-3.7-Sonnet).
  3. The Correction: The expert continues from the student’s current, potentially messy state to successfully resolve the bug.
  4. Fine-tuning: The student is fine-tuned only on the expert’s portion of that trajectory. This teaches the student how to recover and get back on track when it finds itself in a suboptimal state.

Crucially, the authors implement Repetition Filtering to remove trajectories where the student gets stuck in infinite loops (like repeatedly reading the same file), and On-policy Masking to ensure the model doesn't accidentally learn to replicate the student's initial mistakes.

Datasets and Evaluation

The study focuses on the SWE-bench (Software Engineering Benchmark), specifically the Lite and Verified versions. Training data utilized SWE-smith, a collection of approximately 5,000 problem instances derived from real GitHub issues known to be solvable by LLMs. Performance was measured by the resolution rate—the percentage of software bugs the agent successfully patched and verified via unit tests.

Key Insights

  • Quantifying the Drift: Using Fréchet Distance and KL-Divergence, the authors proved that even after imitation learning, student models diverge sharply from experts as a trajectory progresses. This drift is a measurable phenomenon that worsens over time.
  • The "Mixed" Strategy Wins: The best-performing models were trained on a mixture of pure expert trajectories and OEC trajectories, rather than OEC data alone. This suggests models need to see both "what perfect looks like" and "how to fix mistakes."
  • Efficiency over DAgger: Traditional DAgger requires the expert to label every single step the student takes, which is computationally ruinous for LLMs ($O(T^2)$ complexity due to KV cache recomputation). OEC operates at $O(T)$ complexity because the expert only takes over once per trajectory, allowing for efficient KV cache reuse.
  • Rejection Sampling is Insufficient: Simply filtering for successful trajectories isn't enough. If a model solves a problem through a repetitive, "loopy" 80-turn process, training on that data actually degrades its reasoning capabilities.

Results

The OEC method yielded significant performance boosts across the board:

  • 32B Model: The OEC-SWE-32B model achieved a 40.0% resolution rate on SWE-bench Verified, outperforming previous models in its class (like SWE-smith and Skywork), which hovered around 36-38%.
  • 7B Model: The OEC-SWE-7B achieved 20.8%, a massive jump over the 15.2% achieved by standard imitation learning (SWE-smith-7B).
  • Relative Gains: Overall, OEC provided a 13-14% relative improvement over traditional behavioral cloning.

Limitations and Future Directions

While highly effective, the authors note a few limitations to the OEC approach:

  • Expert Dependency: The method requires access to a significantly stronger expert model (or human experts) to provide the corrections.
  • Static On-policy Data: As the student model improves, the OEC data generated at the start of training becomes less "on-policy." Iterative rounds of OEC generation (generating new data with the newly improved student) could yield even higher gains.
  • Domain Specificity: While highly effective for software engineering, the effectiveness of OEC should be tested in other long-horizon agentic domains, such as web navigation or multi-step mathematical reasoning.

Summary updated

BibTeX
@inproceedings{lauffer2026imitation,
  author = {Niklas Lauffer and Xiang Deng and Srivatsa R Kundurthy and Brad Kenstler and Jeff Da},
  title = {{Imitation Learning for Multi-turn LM Agents via On-policy Expert Corrections}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=l0LA4SUA50},
}
Figure