Exploring Lifelong Adaptation: In-Context Reinforcement Learning in Non-Stationary Environments

Ye Wang, Kaiqian Cui, Xinrun Xu, Tao Zhang, Qin JinNeurIPS 2026

TL;DR

AI agents using In-Context Reinforcement Learning (ICRL) can learn new tasks on the fly without updating their neural weights, but they typically assume the rules of the world stay frozen once a trial begins. This paper breaks that illusion by introducing Lifelong ICRL, testing how frozen-weight sequence models survive when gravity drifts or logical rules suddenly flip mid-lifetime without warning. Through massive-scale experiments, the authors show what it takes—in terms of training curricula, modern recurrent architectures, and data scale—to build agents that actively choose what to remember and what to forget.

What Problem Does This Paper Address?

Standard Deep Reinforcement Learning is notoriously slow to adapt, usually requiring expensive gradient updates every time a task changes. In-Context RL (ICRL) bypassed this by treating decision-making as a sequence modeling problem: feed an agent its past interaction history, and it figures out the task purely through forward passes, keeping its weights completely frozen.

There’s a catch, though: existing ICRL relies on the Episodic Stationarity Assumption. While tasks might change between separate trials, the underlying rules or physics remain static across all episodes within a single trial. The real world isn’t so polite—motors wear down gradually, and operating rules shift abruptly. Under standard ICRL, when the world changes mid-stream without an explicit reset button, an agent's past memory turns from a helpful guide into toxic interference. How do you get a frozen network to continuously track shifting realities, discard obsolete history, and still exploit recurring patterns?

Methods

The authors formalize Lifelong ICRL as a procedurally evolving Latent Markov Decision Process. Instead of sampling one static task per lifetime, they sample a dynamics evolution function that dictates how tasks shift across hundreds of episodes—with no change signals, no memory resets, and frozen policy weights.

Figure 1: Environments and evaluation protocols for Lifelong ICRL. XLand-Minigrid varies symbolic task rules, while Kinetix varies scene layouts and physical parameters. Across episodes within a lifetime, task configurations remain fixed (Stationary), switch independently (Random Switching), or follow periodic, drifting, or locally perturbed sequences (Structured Non-Stationarity). Task changes neither trigger a memory reset nor provide a change signal, and policy weights remain frozen.

Using standard PPO (reinforcement learning from rewards alone, no expert demonstrations), they systematically probe three dimensions:

  1. Training Regimes: Comparing standard Stationary training and Domain Randomization (DR, changing tasks every episode) against novel Non-Stationary (NS) and Composite Non-Stationary (CNS) curricula—where CNS mixes random switches with periodic recurrences—plus staged curricula (e.g., DR followed by NS).
  2. Sequence Architectures: Moving beyond standard quadratic-cost Transformers to test bounded-memory Sliding Window Attention (SWA) against modern linear-time recurrent models: Gated DeltaNet (fast-weight linear attention), Mamba2 (state-space model), and a Hybrid alternating Gated DeltaNet with local SWA.
  3. New Decoupled Metrics: Beyond raw returns, they measure Switch Resilience ($\Delta_{\text{Switch}}$, performance right after a rule change) and Stationary Adaptation ($\Delta_{\text{Static}}$, learning efficiency during stable periods) relative to a zero-shot baseline.

Datasets

In RL, environments are the datasets. Rather than static offline logs, the authors build a new Lifelong ICRL evaluation suite by extending two existing procedural benchmarks with intra-lifetime non-stationarity and Out-of-Distribution (OOD) test splits:

  • XLand-Minigrid (Symbolic Reasoning): Agents navigate grid-worlds governed by hidden logical rules (up to 10B training steps; evaluated over 200-episode lifetimes on unseen, deeper depth-3 compositional rules).
  • Kinetix (Physics Control): Agents control 2D rigid bodies, joints, and thrusters (1B training steps on chaotic procedural layouts; evaluated over 100-episode lifetimes on human-designed mechanical tasks with shifting gravity and friction).

Agents face three evaluation protocols: Stationarity, Random Switching, and Structured Non-Stationarity (Periodic Recurrence, Linear Drift, and Noisy Fluctuation).

Key Insights and Ideas

  • Knowing how to remember doesn't mean knowing how to forget: Agents trained in stationary worlds learn to use context well, but completely crumble when rules switch mid-lifetime—performing significantly worse than if they had zero memory at all because they cling to obsolete rules.
  • Early habits die hard ("forgetting bias"): You might think pre-training with Domain Randomization (new task every episode) before Non-Stationary fine-tuning is a smart curriculum. Surprisingly, it underperforms. Inspecting Gated DeltaNet's memory gates shows DR teaches the bottom layer to wipe its memory at episode boundaries—a reflex that stubbornly persists even after fine-tuning (clearing memory 58% of the time vs. 20% when trained on NS from scratch).
  • Active memory revision shows up in hidden states: Measuring cosine similarity in hidden layers reveals that Stationary-trained agents barely budge their internal representations when tasks switch ($\Delta \approx 0$), whereas NS and CNS agents trigger sharp state shifts in middle and upper layers to flush out old context.
  • Bounded attention hits a wall; recurrence shines: Sliding Window Attention (512-token window) struggles to even fit the meta-training distribution, whereas recurrent fast-weight/state-space models (Mamba2, Gated DeltaNet) and Hybrid designs effortlessly bridge dependencies across 200 episodes.

Key Results

Per-episode returns across training paradigms

Figure 2: Per-episode returns of different training paradigms. CNS demonstrates the most robust adaptation across both symbolic and physics-based OOD task sequences.
  • Training Regimes: On XLand Random Switch, Stationary training collapses to a sequence return ($R_{\text{Seq}}$) of 0.048 (with a painful $\Delta_{\text{Switch}}$ of -0.112), while CNS hits 0.153. Because CNS exposes agents to both switches and cycles, it generalizes best—even beating all baselines on unseen Drift protocols (0.214 in XLand; 0.028 in Kinetix).
  • Architectures: Under XLand Random Switch, Hybrid (0.153) and Mamba2 (0.147) crush Sliding Window Attention (0.048). In Kinetix, Mamba2 leads across the board (0.088 on Random Switch vs. 0.046 for SWA).
  • Scale Coupling: Simply stacking more layers (from 6 to 24) at a fixed 10B-step budget doesn't monotonically improve performance; the 24-layer model needs 20B interaction steps to unlock higher returns (0.155 vs. 0.146).
  • Crushing Gradient Updates: Compared against online gradient-based adaptation (Online PPO and PPO+EWC) on XLand Random Switch, Frozen LICRL achieves positive stationary adaptation (+0.011 vs. -0.085 for PPO) and 240x lower variance across runs ($\sigma = 0.001$ vs. $\sigma \approx 0.24$).

Limitations and Future Work

While the main text does not feature a standalone limitations section (the provided excerpt concludes at Section 6 before the appendices), a few boundaries and future directions are noted in the text:

  • Pure RL vs. Supervised Pretraining: The study focuses strictly on online RL from reward feedback without expert action labels. However, the authors suggest their non-stationary curricula could directly guide dataset construction for supervised pretraining approaches (like Decision-Pretrained Transformers or Algorithm Distillation) as a complementary future route.
  • Finite Context & Compute Budgets: Persistent biases (like the DR forgetting reflex) and depth-scaling bottlenecks were observed within the tested 10B–20B step budgets, highlighting that scaling model capacity requires carefully matched interaction volumes.

Summary updated

Abstract

Standard In-Context Reinforcement Learning (ICRL) typically assumes stationary dynamics within an interaction history, a restriction that limits its real-world applicability. We formalize Lifelong ICRL, a more realistic paradigm in which agents must continuously adapt to diverse non-stationary dynamics, ranging from abrupt random shifts to structured temporal drifts within a single lifetime. To probe the adaptation limits of this setting, we conduct a large-scale empirical study across non-stationary environments that span discrete symbolic reasoning and continuous physics-based control. We systematically investigate three core dimensions governing adaptation: (i) Training Regimes, comparing the generalization boundaries of domain randomization, stationary training, non-stationary training, and their staged combinatorial strategies; (ii) Model Architectures, evaluating modern sequence models, including Linear Attention and hybrid designs; and (iii) Impact of Scale, analyzing the relative contributions of interaction scale and model capacity. Our results reveal how these factors jointly shape robust in-context adaptation under unknown dynamics, yielding actionable insights for the design of generalist agents.
BibTeX
@inproceedings{wang2026exploring,
  author = {Ye Wang and Kaiqian Cui and Xinrun Xu and Tao Zhang and Qin Jin},
  title = {{Exploring Lifelong Adaptation: In-Context Reinforcement Learning in Non-Stationary Environments}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=B4sdRfOm1V},
}
Figure