Abstract
Standard Reinforcement Learning (RL) agents typically handle partially observable, non-Markovian environments using "Frame Stacking"—concatenating a fixed window of recent observations. However, this approach scales poorly when critical information is separated from the current state by long time intervals. We introduce Adaptive Stacking (AS), a meta-algorithm that empowers agents to actively manage a small, fixed-size memory stack. By learning which observations to retain and which to discard, AS enables agents to solve tasks with long-range dependencies—up to one million steps—using significantly fewer computational resources than traditional methods.
Introduction
In many real-world Reinforcement Learning scenarios, the current observation does not provide a complete state description. These non-Markovian environments require agents to maintain context from the past to make optimal decisions. The conventional solution, Frame Stacking (FS), uses a sliding window of the last $k$ observations. While effective for short-term dependencies, FS suffers from a "memory explosion" as $k$ increases, particularly for architectures like Transformers where computational costs scale quadratically with window size. Furthermore, most observations in a long sequence are often irrelevant noise. Adaptive Stacking addresses this by transforming memory management into a learned behavior.
The Adaptive Stacking Framework
Adaptive Stacking modifies the standard RL loop by introducing an internal memory stack of fixed size $\kappa$, where $\kappa$ is typically much smaller than the required sliding window $k^*$.
As shown in the architecture above, at each timestep $t$, the agent receives an observation $X_t$ and produces two distinct outputs:
- Environment Action ($A_t$): The standard action taken to interact with the external world.
- Memory Action ($I_t$): An index indicating which slot in the memory stack to "pop" or overwrite to accommodate the new observation $X_t$.
This mechanism allows the agent to selectively "forget" irrelevant data. For instance, in a navigation task, an agent might learn to keep a goal cue in its stack while discarding thousands of identical hallway observations. AS is architecture-agnostic and can be integrated with MLPs, LSTMs, and Transformers.
Experimental Results
The researchers evaluated AS across several challenging benchmarks, including T-Mazes, XorMaze, and robotic control tasks like FetchReach.
Extreme Temporal Generalization
The most striking result occurred in the Passive T-Maze task. Agents were trained on mazes of length 16 and then tested on mazes of length one million.
As illustrated in the figure above, Adaptive Stacking maintained a 100% success rate across MLP, LSTM, and Transformer architectures using a memory stack of only $\kappa=2$. In contrast, standard Frame Stacking (FS) performed no better than a random policy, as it would have required a window size of one million frames to retain the initial cue.
Efficiency and Performance
Beyond simple mazes, AS demonstrated superior performance in the continuous control environment FetchReach. Even when FS was provided with an "oracle" window size (the theoretically optimal $k$), AS achieved higher success rates. For Transformer-based agents, AS reduces computational complexity from $O(k^2)$ to $O(\kappa^2)$, enabling massive savings in memory and FLOPs without sacrificing the ability to handle long-range dependencies.
Discussion and Limitations
Adaptive Stacking effectively performs "temporal state abstraction," grouping diverse sequences of irrelevant events into a single effective memory state. However, the approach introduces an "exploration burden" because the agent must learn the correct memory management policy alongside the environment policy. Additionally, the current theoretical guarantees for AS rely on a "Value-Consistency" assumption, which may not hold in environments with dense, history-sensitive rewards.
Conclusion
Adaptive Stacking represents a significant step toward more efficient and capable RL agents in partially observable worlds. By treating memory as a resource to be managed rather than a passive buffer, agents can overcome the limitations of sliding windows and generalize to temporal scales previously thought unreachable.
Summary updated