Manuscript Offprint

arXiv:2609.35333

Scalable In-Context Reinforcement Learning with Recurrent Algorithm Distillation

Yuanqing Ma, Zhenrui Zheng, Chenjun Xiao

ABSTRACT

Algorithm Distillation (AD) has demonstrated the remarkable ability of Transformers to perform in-context reinforcement learning without explicit weight updates. However, capturing long-term learning progress necessitates expansive context windows, which incur prohibitive memory costs and limit scalability in complex, long-horizon tasks. To address this bottleneck, we propose Recurrent Algorithm Distillation (RAD). RAD employs a dual-component architecture: a Compression Transformer that distills extended interaction histories into compact latent tokens, and an AD Transformer that auto-regressively generates actions using a hybrid context of these compressed memories and recent transitions. By maintaining a fixed-size latent buffer, RAD decouples the effective history length from computational complexity, functionally providing the model with a long-horizon memory. Empirical evaluations across diverse environments demonstrate that RAD matches the asymptotic performance of standard AD with significantly reduced context window sizes, offering a scalable solution for efficient in-context decision-making. Code is available at https://github.com/tommyma3/rad.

1 INTRODUCTION

In-Context Reinforcement Learning (ICRL) enables agents to adapt to new tasks during inference without parameter updates. A prominent example is Algorithm Distillation (AD) (Laskin et al., 2022), which frames RL as a sequence modeling problem. By training on across-episodic learning histories of source RL algorithms, AD distills the “improvement operator” itself, enabling agents to autoregressively predict actions and solve unseen tasks by attending to their own interaction history. Despite its promise, to capture the “improvement operator”, AD requires an expansive context window to encompass sufficient transitions, which is expensive to process due to Transformers’ quadratic complexity (Vaswani et al., 2017). Pratical implementations therefore truncate older history, which may potentially discard information essential for long-horizon adaptation.

In this work, we argue that this bottleneck arises from a “brute-force” approach to history. In many environments, transitions do not contribute equally to the learning signal; much of the interaction data is redundant, and the essential information can often be represented in a more compact form. We observe that an ideal ICRL agent should be able to maintain a fixed-size representation of the past information while remaining capable of simulating a long horizon. To realize this vision, we propose Recurrent Algorithm Distillation (RAD). As illustrated in Figure 1, RAD replaces the long context window of traditional AD with a dual-transformer architecture designed for recursive context compression. The system consists of: (1) a Compression Transformer that distills long interaction sequences into a fixed-length set of latent tokens stored in the long-term memory, and (2) an AD Transformer that generates actions by attending to a hybrid context of the latent long-term memories and recent transitions in the working memory. Crucially, as the context window fills, the system recursively recompresses its context to update the long-term memory, enabling the model to preserve information from the distant past while operating under a fixed memory budget.

We evaluate RAD across a diverse suite of RL benchmarks. Our results demonstrate that RAD generally matches or exceeds AD while using substantially shorter contexts, demonstrating that recurrent context compression provides an effective approach to scalable long-horizon ICRL.

(a) Autoregressive interaction

Figure

Repeat; compress when working memory reaches capacity K.

(b) Compress, update, and retain

Figure

Next policy context

Figure 1: RAD inference workflow: During evaluation, the AD Transformer πθ\pi_{\theta} is able to autoregressively rollout the policy by predicting actions conditioned on the long-term memory z and the working memory xt−k:tx_{t-k:t}. When working memory reaches its capacity K, the Compression Transformer qωq_{\omega} compresses the previous long-term memory (represented as L latent tokens) and the older working-memory context into candidate latent tokens. The update gate UϕU_{\phi} integrates these candidates with the previous latent state to form the new long-term memory z′z', while the most recent p steps remain in working memory. At the first compression, since no previous long-term memory exists, z is set directly to qω(x0:K)q_{\omega}(x_{0:K}), bypassing the update gate.

References (71)