KV-streams for Efficient Compaction in Agentic Reinforcement Learning

Emiliano Penaloza, Dane Malenfant, Dheeraj Vattikonda, Roger Creus Castanyer, Siddarth Venkatraman, Abhay Puri, Jonathan Light, Matthew James Sargent, Augustine N. Mavor-Parker, Massimo Caccia, Lucas Caccia, Glen Berseth, Esmeralda S. Whitammer, Alessandro Sordoni, Minseon Kim, Marc-Alexandre Côté, Laurent Charlin, Guillaume LajoiearXiv 2026

TL;DR

KV-streams is a plug-and-play strategy for training LLM agents that eliminates the massive "prefill tax" associated with context compaction. By streaming the Key-Value (KV) cache forward instead of flushing and re-processing it, the authors achieve up to a 5× training speedup while enabling the KV cache to act as a "pseudo-recurrent" state that retains information even after it has been evicted from the explicit context.

What Problem Does This Paper Address?

Scaling Large Language Model (LLM) agents to long-horizon tasks—like complex software engineering or multi-turn games—is fundamentally limited by GPU memory. As the conversation history grows, the KV cache (the model's "memory" of past tokens) eventually exceeds the GPU's capacity.

To fix this, researchers use context compaction: they summarize old turns or simply delete them (e.g., using a sliding window) to keep the memory footprint constant. However, standard compaction methods suffer from a hidden "prefill tax." Every time the context is compacted, the inference engine flushes the KV cache and re-processes the retained tokens to rebuild it. This redundant computation makes training incredibly slow and compute-expensive, especially when you want to keep a large portion of the recent context.

Methods

The authors propose KV-streams, a drop-in modification for LLM inference and training pipelines.

  • Streaming vs. Flushing: Instead of rebuilding the context from scratch after compaction, KV-streams evicts specific entries directly from the KV cache in the inference engine. This maintains a single, continuous stream of KVs.
  • Custom Attention Masking: On the training side, rather than creating separate training traces for each compaction step, KV-streams uses a custom attention mask. This mask blocks attention to deleted spans within a single forward pass, perfectly replicating the eviction pattern without re-processing a single token.
  • Compatibility: The authors tested this with four common compaction strategies: Summary (replacing old turns with a summary), Markovian Thinker (deleting the oldest half), Markovian Pick (letting the model choose what to keep), and Sliding Window (keeping only the most recent tokens).
Comparison of standard re-prefill compaction vs. KV-streams and different compaction strategies.

Datasets

The researchers evaluated KV-streams across a diverse set of long-horizon benchmarks:

  • TextWorld: Procedurally generated text-based adventure games.
  • ALFWorld: A household simulator where agents complete tasks via text commands.
  • SWE-bench Verified: A challenging benchmark requiring agents to fix real-world GitHub issues in Python.
  • Transfer Tasks: To test generalization, they evaluated models on ScienceWorld, Jericho, and DiscoveryWorld.

Key Insights and Ideas

  • Eliminating the "Prefill Tax": Standard compaction costs grow exponentially as the retained context approaches the memory budget. KV-streams brings this extra token cost down to zero (see Figure 3).
  • Emergent Pseudo-Recurrence: The most striking finding is that the streamed KV cache acts as a recurrent state. Even when a specific piece of information (like a fruit name in a synthetic task) is evicted from the explicit context, the model can still "remember" it because the information was encoded into the KV entries of subsequent tokens that were not evicted.
  • RL is All You Need: Prior research suggested that this "pseudo-recurrence" required a Supervised Fine-Tuning (SFT) stage to emerge. This paper proves that Reinforcement Learning (RL) alone is sufficient for the model to learn how to leak and retrieve information through the KV cache, significantly simplifying the training pipeline.
Extra tokens prefilled vs. tokens kept per compaction. KV-streams eliminates this cost entirely.

Key Results

  • Massive Speedups: KV-streams achieved a 5× wall-clock speedup on TextWorld and a 3× speedup on SWE-bench Verified compared to full-context training.
  • Performance Parity: Despite the speedup, models trained with KV-streams matched or even exceeded the success rates of full-context and re-prefill baselines. On ALFWorld, KV-streams reached the same final success rate as re-prefill compaction at a fraction of the compute.
  • Better Generalization: Models trained with KV-streams generalized better to unseen text-based games than those trained with full context, likely because compaction forces the model to focus on the most relevant information.
Figure 1: Final evaluation score against total training compute for every run on TextWorld, ALFWorld and SWE-bench Verified. Axis ticks give GPU hours and wall-clock hours. Colour denotes the compaction strategy, circles are KV- streams and squares re-prefill compaction, with full context as the reference. Error bars give the standard deviation over three seeds on SWE-bench Verified, and the standard error over seeds, or over evaluation episodes for single-seed runs, on the text-based games. KV-streams reaches the same final score as re-prefill compaction at a fraction of the compute.

Limitations and Future Work

  • Turn-Wise vs. Token-Wise: The authors found that evicting individual tokens (rather than whole turns) led to degenerate text in early experiments. They stuck to turn-wise compaction for stability, but suggest that finer-grained token-level eviction is a promising future direction.
  • Inference Engine Overhead: While KV-streams is faster, current engines like vLLM use 16-token blocks, requiring some padding that adds slight overhead. Optimizing inference engines for single-token block sizes (as seen in their SGLang experiments) would further maximize efficiency.
  • Scaling: Future work could explore how these findings scale to even larger models (e.g., 70B+ parameters) and even longer context horizons.

Summary updated

BibTeX
@misc{penaloza2026kv,
  author = {Emiliano Penaloza and Dane Malenfant and Dheeraj Vattikonda and Roger Creus Castanyer and Siddarth Venkatraman and Abhay Puri and Jonathan Light and Matthew James Sargent and Augustine N. Mavor-Parker and Massimo Caccia and Lucas Caccia and Glen Berseth and Esmeralda S. Whitammer and Alessandro Sordoni and Minseon Kim and Marc-Alexandre Côté and Laurent Charlin and Guillaume Lajoie},
  title = {{KV-streams for Efficient Compaction in Agentic Reinforcement Learning}},
  year = {2026},
  eprint = {2609.35750},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2609.35750},
}
Figure