TL;DR
This paper introduces a framework for In-Context Reinforcement Learning (ICRL) that intelligently prunes an agent's interaction history to save tokens without sacrificing performance. By training a lightweight predictor to estimate the "downstream effect" of removing specific memories, the system adaptively selects a context budget that reduces token usage by up to 52% while maintaining or even improving task success.
What Problem Does This Paper Address?
In-Context Reinforcement Learning (ICRL) allows Large Language Model (LLM) agents to adapt to new tasks by including their past interactions (states, actions, and rewards) directly in the prompt. While powerful, this approach has a major scaling problem: as the agent interacts more, the history grows, leading to massive token costs and increased latency.
Existing solutions often use a fixed-size "sliding window" (keeping only the most recent $N$ steps) or retrieve memories based on semantic similarity. However, these heuristics are "downstream-blind"—they don't account for whether a specific past interaction actually helps the LLM make a better decision right now. A similar-looking past state might be irrelevant, while a distant, unique failure might be crucial for current adaptation.
Methods
The authors propose a downstream-aware context selection framework that treats context management as a predictive task.
- Decision Gap Predictor: Instead of relying on similarity, they train a lightweight, one-layer Transformer ensemble to predict the "Decision Gap." This gap measures how much the agent's behavior (action distribution) or the final task outcome would change if a specific subset of history were removed.
- Adaptive Selection (Algorithm 1): At each decision step, the framework ranks history items using the predictor to create a "deletion ordering." It then iteratively tests smaller subsets of history until it finds the smallest context that stays below a "feasibility threshold" (i.e., the predicted impact on the decision is negligible).
- Order-Guided Redundancy Compression (LORC): Beyond just selecting which steps to keep, the framework identifies repeated information across interactions (like static environment descriptions). It keeps one full copy and replaces others with lightweight references, further shrinking the prompt.
Datasets
The method was evaluated in two distinct environments:
- SUMO (via LimSim++): A closed-loop autonomous driving simulator. The agent was tested on held-out in-distribution episodes, out-of-distribution (OOD) traffic density (Severe-3x), and entirely unseen routes.
- ScienceWorld: A complex, text-based environment for scientific discovery tasks. This was used to test the framework under a continual ICRL protocol where the agent must learn and adapt over 40 interaction rounds.
Key Insights and Ideas
- Downstream Impact > Semantic Similarity: The core "aha moment" is that the utility of a memory is best defined by its effect on the agent's future policy, not its similarity to the current state.
- Context Budgets Should Be Elastic: As shown in Figure 1, the optimal amount of history isn't constant. The framework naturally allocates more "memory" when the agent encounters difficult or novel situations (like unseen routes) and prunes more aggressively during routine tasks.
- Efficiency Matters: Unlike general prompt compressors (like LongLLMLingua) that can be computationally expensive, this framework uses a tiny predictor that adds minimal latency (1.24s vs. 27.7s for baselines), making it viable for real-time "online" use.
Key Results
- Autonomous Driving: The method reduced total token usage by 23.2% to 25.8% across all settings while maintaining safety, comfort, and efficiency scores comparable to using the full 20-step history.
- ScienceWorld: The gains were even more dramatic, with a 52.1% reduction in total tokens compared to the full-context baseline. Surprisingly, the pruned context achieved a slightly higher return (96.06) than the full context (95.50), suggesting that removing irrelevant history can actually reduce "noise" for the LLM.
- Superiority over Heuristics: The method consistently outperformed "Recent" (last $N$ steps) and "Similarity" baselines, proving that learned, task-specific selection is more effective than simple recency or distance metrics.
Limitations and Future Work
The authors note that their current "marginal deletion ranking" evaluates history items somewhat independently. This means the framework might miss higher-order dependencies—for example, interaction A might only be useful if interaction B is also present in the context.
Future work could involve extending the selector to capture these complex interactions between memories and exploring how this framework scales to even longer horizons where the initial "rolling window" is much larger than 20 steps.
Summary updated