Manuscript Offprint

arXiv:2609.35750

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 Lajoie

Emiliano Penaloza◇*1,2,5, Dane Malenfant◇1,3,

Dheeraj Vattikonda1,4^{1,4}, Roger Creus Castanyer1^{1}, Siddarth Venkatraman1,5^{1,5}, Abhay Puri6^{6}, Jonathan Light7^{7}, Matthew James Sargent8^{8}, Augustine N. Mavor-Parker9^{9}, Massimo Caccia13^{13}, Lucas Caccia13^{13}, Glen Berseth1,5^{1,5}, Esmeralda S. Whitammer10^{10}, Alessandro Sordoni1,11^{1,11}, Minseon Kim2^{2}, Marc-Alexandre Côté2^{2}, Laurent Charlin†1,12^{\dagger 1,12}, Guillaume Lajoie†1,5^{\dagger 1,5}

1^{1}Mila 2^{2}Microsoft 3^{3}McGill University 4^{4}Polytechnique Montréal 5^{5}Université de Montréal 6^{6}ServiceNow Inc 7^{7}Rensselaer Polytechnic Institute 8^{8}University College London, University of London 9^{9}Vmax 10^{10}Edinburgh University 11^{11}Microsoft Research 12^{12}HEC Montréal 13^{13}Cohere

◇Core contributors †Equal advising *Corresponding author: emilianopp550@gmail.com

Abstract

Scaling the horizon of agentic LLMs is bottlenecked by the need to fit ever longer context traces in GPU memory. Context compaction has been the most popular mechanism to alleviate this issue, keeping GPU memory constant for a given trace. Unfortunately, most compaction strategies rely on prefilling the LLM context many times over, hindering training throughput. To alleviate this bottleneck and enable efficient trainable compaction, we propose KV-streams, a plug-and-play strategy compatible with any compaction strategy that substantially increases throughput while showing no evidence of hindering performance. KV-streams enable scalable compaction by streaming the KV cache forward rather than flushing it after each compaction. We show that KV-streams enable three different compaction strategies, achieving a 2.6 to 5× wall-clock speedup in training. Beyond efficiency, we find that the streamed KV cache can act as a recurrent state, carrying forward information that has long since disappeared from the context. Specifically, in a controlled setting we show that, contrary to prior work, RL alone is all that is needed for this behavior to emerge. Overall, we show KV-streams to be an efficient and lightweight plug-and-play addition to any post-training pipeline.

Code Repository: github.com/Emilianopp/KV-streams

SGLang Fork: github.com/Emilianopp/sglang

Figure

Summary

Sliding-Window

Markovian Thinker

Markovian Picker

Full context

Re-prefill compaction

KV-streams

Figure

Figure

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.

1 Introduction

Reinforcement learning on long-horizon agentic tasks requires generating many concurrent rollouts, each having key-value (KV) caches growing linearly with length. Under a fixed GPU memory budget, the longest-running rollouts

A Prefill-Compaction

Figure

Training

Figure

KV-streams

Inference

Figure

Training

B Compaction strategies

Figure 2: Compaction strategies and their training costs. (A) re-prefill compaction recomputes retained tokens and creates separate training traces. KV-streams preserves retained KVs and trains on a continuous trace with an attention mask that reproduces eviction. (B) context transformations under each strategy (P: prompt; S: summary).

quickly become the bottleneck, monopolizing memory that shorter rollouts could otherwise use. Reducing the memory footprint of long traces can therefore substantially increase training throughput, enabling more optimizer steps and larger batch sizes (Kwon et al., 2023; Chen et al., 2026).

To stop memory from growing, a variety of compaction techniques can be used. They remove a portion of the context once a fixed token budget is exceeded (e.g. replacing older context with a summary) (Wu et al., 2026b; Li et al., 2026b). Compaction lets a trace extend indefinitely (in principle) without growing its memory footprint, but increases training compute. This is due to the retained context being prefilled each time following a compaction, so the model performs repeated forward passes over the same tokens (Cim et al., 2026).

In this work, we propose KV-streams to alleviate the computational bottleneck of compaction. Specifically, KV-streams evicts KV entries directly in the inference engine yielding the memory benefits of compaction while maintaining a single continuous stream of KVs, thus avoiding any repeated prefill cost. On the trainer side, KV-streams reproduce the eviction pattern with a custom attention mask, so no tokens are re-processed. Through this simple plugin, KV-streams substantially increase both training and inference throughput on the four compaction strategies we tested, and are compatible with others. Figure 2 summarizes those four strategies and the mechanism behind the speedup.

We evaluate KV-streams combined with various compaction strategies on long-horizon agentic tasks, using Qwen3-4B-Instruct-2507 and Qwen3.5-4B, obtaining a 5×5\times speedup on TextWorld (Côté et al., 2019) and a 1.3×1.3\times speedup on ALFWorld (Shridhar et al., 2021). Interestingly, while early in training both KV-streams and re-prefill compaction can hinder performance compared to the use of full context, with sufficient training, KV-streams can close this gap and even surpass the performance of full context. Further, we find that models trained with KV-streams also generalize better to unseen text-based games (Cui et al., 2025; Hausknecht et al., 2020; Wang et al., 2022; Jansen et al., 2024). We then carry these results over to agentic software-engineering tasks, where KV-streams reach peak performance 3×3\times faster than full context while maintaining comparable performance.

Prior work (Kontonis et al., 2026) showed that preserving KVs across compactions lets the KV cache act as a "pseudo-recurrent" state, but found that this behaviour requires a preliminary SFT stage in their training setup. We test whether that requirement holds in our approach. Empirically, the additional wall-clock time spent on SFT does not improve performance, and synthetic experiments show that pseudo-recurrence can emerge in the KV cache without this preliminary SFT stage. This is a significant improvement for RL post training pipelines, with up to a 5×5\times speedup.

Overall, KV-streams is a simple plug-and-play addition to any compaction strategy that greatly reduces training wall-clock, matches or exceeds the performance of re-prefill compaction, generalizes effectively, and requires no expensive SFT stage for initialization. We make our inference and training code public at https://github.com/Emilianopp/KV-streams for a subset of the experiments.

References (80)