# Counterfactual Distillation: Internalizing Reflective Experience into LLM Agent

*Rui Ge, Yichao Fu, Yu-Yang Qian, Junda Su, Yiming Zhao, Hao Zhang*

[NeurIPS page](https://neurips.cc/virtual/2026/poster/154297) · [OpenReview](https://openreview.net/forum?id=Eme3GC4jGU) · [alphaXiv](https://www.alphaxiv.org/abs/2603.16843) · [Open on the map](../papers.html#p154297)

Category: [LLM Post-Training: RL & Distillation](../pcat/18.md) › [Reward-Driven Agentic RL with LLMs](../pgroup/578.md) · Type: new method · Keywords: LLM agents, counterfactual distillation, exploration, policy supervision, reinforcement learning, Pass@k

Areas: [LLM Reasoning](../areas/reasoning.md) › Reasoning Optimization › Credit Assignment in Reasoning; [AI Agents](../areas/agents.md) › Agent Optimization and Evaluation › Agentic Reinforcement Learning; [RL for LLMs & Agents](../areas/llm-rl.md) › Language Model Agents › World Models for Agents

## Summary
Counterfactual Distillation introduces a tree-structured exploration and distillation framework that converts reflective experience into policy supervision, improving agent performance on interactive coding and long-horizon tasks.

## Explained to a 5-year-old
A computer brain called a large language model works like a smart robot that makes decisions over many steps. It gets lots of feedback from its actions, but the feedback is often unclear. To get better, the brain makes a tree of possible choices, thinks about what could have happened, and creates new ideas. It then learns to guess the best action from the original situation without seeing the new ideas. This helps the robot solve more difficult problems and try many different solutions.

## Explained to a 5-year-old, longer
A big computer brain called a large language model can act like a robot that does many things over time. It learns from what happens after it makes choices, but the feedback is often not clear. Traditional methods only look at whether the final result was good, missing the details of the experience. This can cause the brain to only repeat the actions that already worked, missing other possibilities. The paper introduces a way to use the detailed experience by imagining different choices. First, the brain builds a tree of possible actions, like a map of what could happen at each step. It looks back at past decisions and thinks about what other actions could have been taken. These imagined alternative actions become "counterfactual" examples that show what could have happened. The brain is trained to predict the better action from the original situation without being shown the imagined alternatives directly. This teaches the brain to consider new strategies and explore more diverse behaviors. As a result, the robot can solve harder problems and get better at tasks like writing code or playing games. The method also works well when combined with other learning techniques, boosting performance even further.

## For a technical reader
Counterfactual Distillation builds a tree-structured search over an agent’s interaction history, generating alternative action branches that reflect on past decisions. These counterfactual branches are distilled as training targets, allowing the model to learn improved actions from the original history without explicit exposure to the new experiences. This mechanism injects out-of-distribution behavior, expanding exploration beyond the narrow set reinforced by outcome-driven methods. When interleaved with RL updates, the approach consistently lifts Pass@k scores, delivering up to 14% gains on Pass@128 and over 10% on Pass@1 across coding and agentic benchmarks.

## Problem
Optimizing policies from heterogeneous interaction feedback in sparse-reward, long-horizon tasks is challenging because existing outcome-driven methods underutilize rich experience, leading to distribution sharpening and limited exploration.

## Method
The approach organizes exploration as a tree-structured search, where the agent reflects on past decision points and generates alternative experience-guided branches. These alternative actions are distilled as counterfactual targets, training the model to predict revised actions from the original history without exposing the experience, thereby injecting out-of-distribution behavior and expanding exploration.

## Results
The approach achieves up to 14% improvement on Pass@128 over baselines such as GRPO and Early Experience, and when combined with reinforcement learning updates yields over 10% gain in Pass@1.

## Contributions
It introduces a framework for converting reflective exploration experience into trainable policy supervision via tree-structured search and counterfactual distillation, and demonstrates substantial gains on interactive coding and agentic tasks.

## Research questions this paper is counted under

- [How can reinforcement learning agents effectively learn from sparse, delayed rewards in long-horizon tasks?](../q/1.md)

This page was written by language models from the title and abstract of each paper, and the answers were checked by two other models. It can be wrong: check the paper itself. [Suggest a correction](../feedback/?on=p/154297)
