TL;DR
Long-horizon LLM agents suffer from context bloat, but pruning history safely is tricky because the harm of deleting multiple pieces of information is non-additive. This paper introduces Direct Relational Set-Risk Pruning (DRSR), a method that trains a lightweight scorer to predict the collective risk of deleting sets of history blocks rather than scoring them independently. By optimizing for maximum token savings under a learned risk constraint, DRSR reduces token usage by up to 35% while significantly boosting agent success rates.
What Problem Does This Paper Address?
As LLM agents tackle long-horizon tasks, they accumulate massive histories of reasoning traces, tool calls, and environment observations. While keeping this full history prevents information loss, it forces the model to repeatedly process an ever-growing context. This drastically increases inference costs and causes models to choke on long contexts—a phenomenon known as the "lost in the middle" effect.
Existing prompt compression and memory management methods typically score historical units independently (singleton scoring). However, history pruning is inherently a set-level problem. Two historical blocks might look safe to delete in isolation because they contain redundant evidence, but removing both eliminates the only remaining copy of that evidence. Furthermore, multiple small, individually acceptable deletion harms can accumulate into substantial harm. DRSR addresses this gap by directly modeling the risk of joint deletion actions.
Methods
DRSR formulates history compression as a risk-constrained selection problem over deletion sets. The pipeline consists of three main phases:
- Offline Counterfactual Supervision: Using completed trajectories, DRSR constructs exact training labels. It jointly removes candidate history blocks and measures the change in the teacher-forced likelihood of the same recorded next output. This isolates the exact harm of the deletion action without the noise of newly sampled continuations.
- Relational Set-Risk Prediction: Instead of assigning a static importance score to a block, DRSR extracts features based on how a block relates to the current decision state (using attention mass, hidden-state cosine similarities, and fixed random semantic projections). A lightweight, cardinality-aware scorer then processes these features to predict both continuous harm and a binary "unsafe" score for the entire candidate deletion set.
- Risk-Gated Online Selection & Abstention: At deployment time, DRSR generates a small pool of structurally valid deletion subsets. The lightweight scorer evaluates them in a single batch with zero extra LLM generation calls. DRSR executes the deletion set that saves the most tokens, provided it passes a learned risk threshold ($\tau$). If no candidate set is deemed safe, the system abstains and retains the full history.
Datasets
- Training: The offline scorer was trained on 566 external trajectories containing 1,698 decision states and approximately 24,122 jointly measured deletion-set labels.
- Evaluation: The authors evaluated end-to-end agent performance on WorkBuddyBench Full260 (80 Code, 50 Office, 60 Security, and 70 Web tasks) and a controlled Eval40 subset to benchmark against existing context-management methods.
Key Insights and Ideas
- Singleton Aggregation Fails: Summing or averaging independent block scores cannot reliably predict the risk of deleting them together. As shown in the paper's analysis, even the strongest simple aggregation rule (summation) only achieves 58.94% pair accuracy in ranking deletion harms.
- Interaction Grows with Set Size: The non-compositional interaction effect (the discrepancy between joint harm and the sum of singleton harms) increases significantly as more blocks are deleted together. At three or four blocks, this interaction magnitude frequently crosses the threshold of what constitutes an unsafe deletion.
- Relevance is Decision-Conditioned: A piece of history isn't inherently useless; its value depends entirely on the agent's current state. For instance, an error trace is vital while diagnosing a bug but becomes redundant once the root cause is identified and logged elsewhere.
- Abstention is a Safety Net: The ability to say "no, it's not safe to prune anything right now" is critical. Ablation studies showed that removing the abstention gate drastically harms agent performance, especially in complex domains like Security.
Key Results
- WorkBuddyBench Full260: DRSR boosted the agent's mean reward from 0.699 to 0.802 while cutting total model tokens by 20.82%. The improvement was most dramatic in the Security domain, where the baseline agent frequently failed due to massive context lengths (reward jumped from 0.478 to 0.756).
- Eval40 Benchmark: DRSR achieved a 0.794 reward using 35.85% fewer tokens than the uncompressed baseline agent. It comfortably outperformed competitive context-management baselines like PACE, LLMLingua-2, CoMem, and SelfCompact.
- Efficiency: Because the candidate space is small and evaluated via a lightweight network, online pruning requires zero extra LLM generation calls for counterfactual evaluation.
Limitations and Future Work
- Local Overhead: DRSR requires two local representation forward passes over the intact causal prefix at each eligible decision step to extract attention and hidden-state features. While much cheaper than full LLM generation, it still adds a local computational footprint.
- Combinatorial Scaling: To avoid a combinatorial explosion of candidate subsets, DRSR restricts online evaluation to a maximum deletion cardinality of $K=3$ from a pool of 4 candidates (14 subsets total). Scaling this approach to handle massive histories with dozens of potential deletion candidates remains an open challenge for future search algorithms.
Summary updated