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

Niklas Lauffer, Xiang Deng, Srivatsa Kundurthy, Brad Kenstler, Jeff Da · DOI

Introduction: The Challenge of Covariate Shift

Training language model (LM) agents for complex, multi-turn tasks like software engineering remains a significant hurdle. While standard Imitation Learning (IL)—where models are trained to mimic expert trajectories—works for short sequences, it often fails in long-horizon scenarios.

The primary failure mode is covariate shift. In a multi-turn environment, a single minor error by the student model alters the state of the environment. Because traditional training data only contains "perfect" expert paths, the student model encounters states it has never seen before. These errors compound, causing the agent to "drift" further from the expert distribution until it becomes hopelessly lost. Standard behavioral cloning teaches a model how to be perfect from the start, but it fails to teach the model how to recover once it has strayed.

On-Policy Expert Corrections (OEC)

To address this, the authors introduce On-Policy Expert Corrections (OEC). This method is designed to provide the model with training data specifically focused on recovery and correction.

The OEC workflow: A student model initiates a task, and an expert model takes over mid-trajectory to correct errors and complete the goal.

The OEC Workflow

  1. The Hand-off: A rollout begins with the student model (e.g., Qwen2.5-Coder 7B). At a randomly selected turn, an expert model (e.g., Claude-3.7-Sonnet) takes over.
  2. Context Rewriting: The trajectory history is reformatted to ensure the expert can seamlessly pick up from the student's current state.
  3. On-Policy Masking: During the fine-tuning phase, the student's initial actions are masked. The model only learns from the expert’s corrective actions, effectively learning how to navigate back to a successful resolution from an imperfect state.
  4. Repetition Filtering: To ensure data quality, the authors prune trajectories where models get stuck in infinite loops, a common issue with smaller open-source models.

Empirical Results and Performance

The OEC method was evaluated on the rigorous SWE-bench (Lite and Verified) benchmarks, which require agents to resolve real-world GitHub issues.

Performance comparison on SWE-bench Verified showing OEC consistently outperforming standard Behavioral Cloning and On-policy methods as sample size increases.

As shown in the scaling analysis, OEC provides a substantial performance boost over traditional behavioral cloning. The results highlight several key findings:

  • State-of-the-Art Performance: The OEC-trained 32B model achieved 40.0% on SWE-bench Verified, representing a 13% relative improvement over standard imitation learning. The 7B variant saw a similar 14% relative boost, reaching 20.8%.
  • The Hybrid Advantage: The most effective training strategy involved a mixture of standard Behavioral Cloning (learning the "golden path") and OEC (learning to recover).
  • Timing Matters: Interestingly, switching to the expert later in the trajectory (turns 16-30) proved more beneficial than early hand-offs. This suggests that learning to fix deep, complex errors is a more critical skill for agent robustness.

Key Insights and Conclusion

Beyond raw performance, the study provides empirical evidence for the severity of covariate shift. Using Frechet Distance (FD) on trajectory embeddings, the authors demonstrated that drift significantly accelerates after turn 30. Qualitatively, OEC-trained models are far less likely to succumb to "tool use errors" or get stuck in repetitive loops.

While OEC requires access to a high-performance expert model for data generation, it offers a clear path forward for making smaller, open-source agents more resilient in the face of real-world complexity. By teaching models not just how to act perfectly, but how to recover from their own mistakes, OEC bridges the gap between theoretical imitation and practical agentic performance.

Summary updated

BibTeX
@inproceedings{lauffer2026imitation,
  author = {Niklas Lauffer and Xiang Deng and Srivatsa 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