Manuscript Offprint
arXiv:2610.38980Context Compaction for World Models
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
ABSTRACT
World models let observers explore and interact with generated worlds. Recent work shows that when observers revisit a region, current models often fail to regenerate it consistently. We view this as a context retrieval problem. LLM agents manage context retrieval at two layers of their stack. At the model layer, the KV cache design determines how much context fits in memory. At the agent harness layer, harnesses such as Claude Code pick the context sent to the LLM. Prior work on world models has mostly focused only on the model layer. In this paper, we make three contributions. First, we build a benchmark to measure world model context retrieval. It generates new worlds for every episode, preventing a model from recalling rooms using training data. It also separates context retrieval from guesses based on nearby frames. Second, we build an agent harness that performs context compaction for world models, which to our knowledge no prior work has studied. Third, we use our benchmark to study four world model designs. Context compaction lets our world models retrieve rooms up to 4 times beyond their context window without retraining. However, world models with sliding-window attention lose most of their context retrieval when dreaming. Therefore, a dreaming world agent benefits more from extending the reach of its world model using context compaction than switching to sliding window attention at the model layer.
1 INTRODUCTION
World models are systems that can predict a given environment from actions and observations. World models are useful in the realm of robotics and physical AI because they allow an RL agent to learn from a world model's imagined environment and then use that training to act in the environment (Ha & Schmidhuber, 2018; Hafner et al., 2020). In addition to agents, people can also explore and play inside the vast and imaginative worlds constructed by world models (Bruce et al., 2024) making way for a plethora of opportunities in the entertainment and video game industry (Team et al., 2026).
When an observer explores and interacts with a world model's generated world for an extended period of time, they often return to places they visited earlier on in their trajectory. A realistic world model is expected to generate the same output for a given place on a revisit as it did on the first visit. Unfortunately, two recent evaluations (Lian et al., 2025; Ye et al., 2026) demonstrate that world models do not currently maintain good consistency when observers revisit the same area in the generated world.
We view this as a context retrieval problem, similar to how LLMs are expected to maintain the context of a user's con-
versation during long sessions. For LLMs, this is a well-explored area of research. Context in LLMs is typically managed at two layers of the inference stack: the model layer and the agent harness layer. At the model layer, there is a subtle tradeoff between the size of the KV cache and an LLM's context retrieval. If an LLM designer reduces the number of bytes of KV cache required per LLM token, it enables a fixed amount of GPU memory to fit a longer context. On the other hand, reducing the size of the KV cache per token can also reduce how accurately an LLM retrieves previous tokens in its context.
There are many optimizations that reduce the size of an LLM's KV cache. Multi-query attention (Shazeer, 2019) and Grouped-query attention (Ainslie et al., 2023) share an LLM's keys and values across multiple attention heads. A Decoder-Decoder model (DD) (Sun et al., 2024) computes an LLM's keys and values once for a token and shares them across all of the LLM's upper layers. Sliding Window Attention (SWA) (Beltagy et al., 2020) lets each of an LLM's tokens only attend to a fixed window of tokens preceding it. In addition to the KV cache, some model architectures also focus on reducing the compute necessary for the prefill stage in inference. For example, recently, the Causal Encoder-Decoder (CED) introduced by DeepSeek-V4.1-Flash (DeepSeek-AI, 2026) lets an LLM project the keys and values for each upper layer from the hidden state of the middle layer. Note that the key and value weight matrices still remain separate for each upper layer in a CED, hence the KV cache in a CED is not smaller than the KV
¹Boston University, Boston, Massachusetts, USA ²AllSpice Inc., Boston, Massachusetts, USA. Correspondence to: Hayder Tirmazi hayder@bu.edu.

Figure 1. Left: Impact of model architecture on context retrieval for our video game room generation world model. Decoder-only needs 28.3 MB of KV cache memory for a context window of 128 steps. In the same memory, DD fits a context of 1,020 steps. Middle: Context retrieval gain of each world model when it dreams (with context compaction enabled). DD, which saves its memory with SWA, loses most of its context retrieval. Right: Agent harness layer can improve context retrieval on top of model layer changes. Decoder-only retrieves a room revisited after 262 steps. The visit from 262 steps ago is no longer in Decoder-only's 128-step context window. The model therefore cannot reproduce the room. However, context compaction allows the original visit to still be sent to the model.
cache in a standard LLM. However, since the keys and values in the upper layers depend only on the middle layer, CED can fill the global KV caches of its upper layers during the prefill stage without running the upper layers on the full input prompt.
At the agent harness layer, a harness tries to manage the context of an LLM through a process called context compaction (Tirmazi et al., 2026). Most commonly, such as in Claude Code and OpenCode, context compaction involves creating an LLM-generated summary of the agent's session (Tirmazi et al., 2026). More recently, Codex with GPT-6 Astra can experimentally keep notes across context windows in place of a single summary. Earlier context windows stay searchable, allowing the model to retrieve details from previous messages and tool outputs when it needs them (OpenAI, 2026).
Unlike LLMs, the problem of context retrieval in world models has not been adequately studied. The vast majority of prior work is limited in scope and focuses primarily on the model layer. Prior work explores how a world model's architecture or its KV cache can be modified for better context retrieval. WorldMem (Xiao et al., 2025) is a video world model that stores previously generated frames into a memory bank and retrieves them back into its diffusion transformer blocks during inference. Similarly, WorldPack (Oshima et al., 2026) attempts to pack previously generated frames into fewer tokens allowing more frames to be fit into the context window during inference. WorldKV (Yi et al., 2026) keeps and retrieve KV-cache chunks that are evicted by a sliding window. Finally, CaR (Peng et al., 2026) learns a compression network to improve context retrieval.
All of the above papers evaluate their design by checking
whether a frame that an observer revisits looks similar to the frame that the world model generated on the observer's original visit. However, this method of evaluating the model design does not completely answer the isolated question of whether a world model is good at context retrieval. When a world model generates a frame on an observer's revisit that is similar to the original frame, it can be due to three distinct reasons.
-
The world model retrieved the original frame from its context.
-
The world model reconstructed a frame similar to the original frame from its original training data that the model memorized.
-
The world model inferred a frame similar to the original frame using context clues from other recent frames that are in its context.
In this paper, we call the latter two cases context reconstruction and context inference respectively, to distinguish them from context retrieval. Since most evaluations of prior work score only the output of the world model, they cannot separate the three cases. The closest prior work to our approach is a recent study that replaces the memory that a world model reads with memory from elsewhere (such as another scene) and measures how much of the benefit of memory depends on its content (Tiwari et al., 2026). However, they evaluate existing world models on existing datasets and do not control whether those scenes appear in the training data. Therefore, the study still cannot rule out context reconstruction.
When it comes to the agent harness layer, we are not aware of any prior work that uses an agent harness to manage the context of a world model similar to how existing LLM harnesses such as Claude Code and Codex manage the context of an LLM. The closest prior works we were able to find are WorldPlay (Sun et al., 2025) and Echo-Memory (King et al., 2026). While WorldPlay and the context-based variants of Echo-Memory use a retriever outside of the model to choose frames for a world model, they require the world models to be trained using the frames chosen by the external retriever. In other words, they are not agent harness layer optimizations in the same sense as context compaction in LLM agents. Claude Code, for example, manages the context of an existing Anthropic LLM such as Claude Opus without having to change the LLM's weights or re-train it. World in World (Song et al., 2026) retrieves earlier generated states for a frozen world model without training, but it does so inside the model, by restoring their KV caches and by rescaling attention during generation. Our agent harness leaves the computation of the world model unchanged and only decides which context the world model reads.
In this paper, we conduct a thorough study of the problem of context retrieval in world models. We train research world models of about 14M parameters that generate video game rooms and then use them to investigate how an array of systems decisions across the model layer and agent harness layer impact context retrieval. Concretely, we make the following three contributions.
-
Create a benchmark for world models that specifically evaluates a world model's context retrieval. Unlike prior work, our benchmark separates context retrieval from context reconstruction and context inference.
-
Introduce an agent harness for world models that can perform context compaction. Our agent harness manages the context of an underlying world model without having to retrain or modify its weights. Our approach is similar to how agent harnesses for LLMs such as Claude Code, Codex, and OpenCode work.
-
Conduct an evaluation of the effect of systems decisions at the model layer and agent harness layer (as well as their combinations) on context retrieval in world models, both when the world model reads true frames and when it dreams.
We vary the model architecture and the agent harness independently and measure context retrieval on each configuration. Note that the two layers interact with each other and both play a part in a world model's ability to do accurate context retrieval. For example, a good context compaction algorithm at the agent harness layer can extend the reach of a world model's context retrieval far beyond the model's context window. Similarly, the design of the KV cache at the model layer significantly impacts the size of the model's context window assuming the available memory is fixed. Figure 1 shows both effects. In practice, a world agent dreams, i.e., its world model predicts new frames from frames that it generated earlier. Once our world agents dream, world models whose lower blocks use SWA lose almost all of their context retrieval, with or without context compaction, as we show in the middle plot of Figure 1.
We can use a Key-Value (KV) cache to store the keys and values of each processed token in each transformer block in . Using a KV cache reduces the compute cost of generating each new token after tokens in to . 's KV cache needs to store bytes. If we use Sliding Window Attention (SWA) with a window size of tokens then the compute cost of an SWA transformer block is and with and without a KV cache respectively. The KV cache only needs to store bytes for an SWA transformer block. We derive these costs along with a more rigorous treatment of model architectures in Appendix A.
Decoder-Decoder Models. We use to denote a Decoder-Decoder Model (Sun et al., 2024). In , transformer blocks are split into lower blocks and upper blocks, i.e., . Following the SWA variant of YOCO, the lower blocks in use SWA. Let be the normalized output of the last lower block in . is projected onto a shared key matrix and a shared value matrix . Each upper block in computes its own queries and attends over and through cross-attention. This lets 's KV cache get away with only storing bytes. In other words, the part of the KV cache that grows with the model's history, , is times smaller than in where it was bytes.
Causal Encoder-Decoder Models. DeepSeek's recent model, DeepSeek-V4.1-Flash, uses a novel model architecture called a Causal Encoder-Decoder model (DeepSeek-AI,
2026). We use to denote Causal Encoder-Decoder models. In an , similar to a Decoder-Decoder model, transformer blocks are split into lower blocks and upper blocks. The lower blocks are called encoder blocks. They are ordinary decoder-only transformer blocks. The upper blocks are called decoder blocks. Let be the normalized output of the last encoder block in . Each decoder block has a separate key weight matrix and separate value weight matrix . The key and value for each decoder block are computed from , i.e., and . Note that the decoder blocks use cross-attention. As defined, does not reduce KV cache size as compared to , the decoder-only Transformer model. However, it does save compute cost. Since each of the decoder blocks uses , the compute cost of prefilling tokens in is compared to in . Our description of follows the general formulation in the DeepSeek-V4.1-Flash technical report. However, note that DeepSeek-V4.1-Flash also adds some components orthogonal to the idea of Causal Encoder-Decoders which we do not include as part of for simplicity.
Context Compaction. There are two places where we can store the history of the world being predicted by a world model. The first is the KV cache within the model, which is common practice today. The second is the memory maintained by an external agent or program that interacts with the model. While common in LLM agent harnesses, this is an underexplored concept in world models. An LLM agent harness typically maintains a transcript of its state. When the transcript exceeds the context window, the agent harness selects a subset or summary of the transcript to fit within it. This is called context compaction (Tirmazi et al., 2026).
3 WORLD RETRIEVAL
In this section, we introduce a benchmark that evaluates a world model's context retrieval capabilities in a way that decouples them from the world model's context reconstruction and context inference capabilities, as discussed in § 1.
3.1 Benchmark World
Our world consists of an grid of video game rooms. Each room in the world is a grid of tiles. There are eight types of tiles in the world such as a rock tile and a water tile. The borders of the room hold walls and a door for each neighboring room. Consequently, each border can have at most one door tile and the rest of the tiles of the border are wall tiles. We use public domain sprites (Drummyfish, 2018) for the tiles. We uniformly randomly choose a room in the world and place the observer in the room. The observer is placed in the center of the current room and an action in the

Figure 2. A frame in our benchmark world with the observer placed at the center of the room. The observer is allowed to use the doors to transition to the neighboring rooms in the world's grid.
world consists of the observer moving through a door to a neighboring room. Consequently, each frame in our world is a given video game room. Similarly, each step in our world is at the granularity of a room transition. Please refer to Figure 2. In our benchmark, we generate episodes (for both training and evaluation) by making the observer navigate the benchmark world using a random walk. At any given step, we uniformly randomly choose one of the doors of the current room and make the observer go through that door. However, we exclude the door the observer just entered through from the set of doors we uniformly randomly choose from. In case there is a dead end, i.e., when there is no door other than the door the observer entered from, we make the observer return through the same door. Using our approach, the observer frequently revisits rooms without the need for scripted loops. The length of the walk between an observer's original visit and the observer's revisit to the same room ranges from a few steps to the length of the benchmark's episode. We denote this length as the gap of the revisit for the remainder of this paper. We group room revisits by their gap into the following seven bins: 1–7, 8–15, 16–31, 32–63, 64–127, 128–255, and 256–511 steps. Note that we incrementally double the interval of the gap bins.
3.2 World Model
Our benchmark world and its evaluation can be used with any world model that can ingest our video game rooms tokenized in any form and predict the next room. In this section, we provide an overview of the world models we specifically train and evaluate on. For our world models, we use 8 tokens to encode frames and 1 token to encode the observer's action. We tokenize a video world room in the following way. Each of the 8 tokens corresponds to a type of tile, e.g., the water tile is assigned a token. Each token is computed from a boolean map where a 1 at position corresponds to the water tile being at tile position in the video game room's tile grid. The action token simply encodes the direction of the door the observer wants to transition to. Note that there is at most 1 door for each of the four directions in a room. Consequently, our world models are sent 9 tokens for each step. Our world models generally have a context window of 128 steps.
We train and evaluate on four world models. In the notation of § 2, all four of our world models have transformer blocks with attention heads. Each attention head has width . All four world models also all have an embedding width of . We store the KV cache in float32, so we use bytes per floating point value for all cache sizes. The first model uses the Decoder-only architecture, , as described in § 2. The second model uses the Decoder-Decoder architecture, . The third model uses a Causal Encoder-Decoder architecture, which we described using with ordinary lower transformer blocks. Our fourth world model is a variant of that uses SWA for its lower blocks similar to 's lower blocks. We will refer to this variant of as . Figure 3 illustrates the design of the four world models. Note that all four models have roughly 14M parameters. Specifically, has 14,352,000 parameters. Both and have 14,352,768 parameters. Finally, has 13,465,728 parameters. For simplicity, we use , , , and interchangeably with Decoder-only, CED, CED-SWA, and DD in the rest of this paper.
3.3 Context Reconstruction
Context reconstruction occurs if a world model has observed a frame in our world in its training data. For foundation world models that are typically pretrained on a large corpus of data from the internet and other sources, we prevent this by ensuring that the video game rooms in our benchmark world are randomly generated at benchmark time. For world models specifically trained for our benchmark world, we ensure that separate pseudorandom seeds are used for training and evaluation. Training on pseudorandom seeds of our benchmark world that are not the same as the evaluation seeds can certainly teach a world model general terrain statistics of the world such as the typical size of a patch of water. However, it cannot teach a world model the specific layout of a given room generated during evaluation. This property ensures that to predict a revisited room with a high accuracy upon a revisit, a world model cannot successfully rely on context reconstruction from its training data.
3.4 Context Inference
Context inference occurs if a world model is able to accurately predict a revisited frame without actually retrieving the original visit frame from its context. As we discussed earlier, this can be due to the model using context clues from other recent frames that are in its context. To separate context retrieval from context inference, we score each revisit in two runs. In the first run, the world model reads its normal context window. In the second run, we keep only the 5 most recent steps of the benchmark world in the context window and replace all earlier steps with the same number of steps from another benchmark world. We call the second run a shuffled run and refer to its context window as a shuffled context window.
Note that the reason we chose to keep the 5 most recent steps (as opposed to any other number of recent steps) is because 5 steps is the receptive field of the SWA transformer blocks in two of the model architectures, CED-SWA and DD, that we describe in § 3.2. In these two model architectures, each of the four lower blocks attends over the 2 most recent steps. The information from earlier steps therefore can move at most one step forward through each lower block. Hence the output of the final lower block depends on the five most recent steps only. If we keep the 5 most recent steps, we can prevent the input of the lower transformer blocks that rely on SWA from changing. The shuffled run therefore changes only the history that a model reads through attention beyond its local window. We keep the same 5 steps for every model architecture in the paper, therefore, we score all model architectures on the same shuffled contexts.
Let be the accuracy of a world model on a revisited room in our benchmark world when the world model is provided the original context window. Let be the accuracy of the world model when it is provided a shuffled context window. We define the context retrieval gain, , to be .
For any room that was visited earlier than 5 steps ago, if a world model is relying on context retrieval for its prediction, it will have a much lower as compared to . This is because the shuffled context will not contain the originally visited frame that the world model is using to predict the revisited frame. Therefore, the world model's context retrieval gain will be large. On the other hand, if the world model is relying primarily on context inference, the difference between and will not be as stark, resulting in a lower context retrieval gain.
We use revisits that span more than 128 steps after the origi-

Figure 3. The architecture of the four world models we train and evaluate on. Each world model has 8 transformer blocks. We show the KV cache corresponding to a transformer block to the right of each respective block. From left to right, each architecture changes one property of the model incrementally. Switching from Decoder-only to CED, the upper blocks compute their keys and values from the output z of the last lower block. From CED to CED-SWA, the lower blocks switch to using SWA so they only attend over the 2 most recent steps. Finally, from CED-SWA to DD, the 4 upper KV caches become one shared KV cache that is read by all the upper blocks.
nal visit as a negative control. As we mentioned earlier, the world models we train and evaluate in this paper have a raw context window of 128 steps. A raw context window of 128 steps does not contain the original visit at these gaps, even in the first run. Our negative control run (both with a regular context window and a shuffled context window) therefore does not have the original visit in its context. Hence, the context retrieval gain for our negative control run should be close to zero. If we see a larger gain, it would imply that the shuffled run is failing to remove a helpful context clue. Our experiments show the negative control runs to have a context retrieval gain in the range [0.03, 0.06] for all four world models serving as a validation for our approach of isolating context inference in our benchmark. Please see Appendix B.1 for more details.
4 WORLD AGENTS
Popular LLM agents such as Claude Code and Codex are responsible for managing the context of their underlying LLM (Tirmazi et al., 2026). In the same way, we build an agent harness for our world models to manage context. Note that similar to LLM agent harnesses, our harness does not require the underlying world model to be retrained. Also like LLM agent harnesses, our harness is independent of the underlying model and can be used interchangeably with all four model designs that we test on and, in fact, should be easy to adapt for any world model that can work with our benchmark. Analogous to how an LLM along with the harness is called an LLM agent, we refer to a world model together with its harness as a world agent.
Our agent harness is situated at the interface between a world model and an observer. We record every frame and action of an observer's session with the model in the harness.

Figure 4. Our agent harness conducts context compaction before sending it to a world model. It records the entire session as the full context, which soon outgrows the model's context window. Context compaction allows it to send the model a walk through every visited room instead of the full context.
This is referred to as the full context of the agent session. However, recall that the world model only has a context window length of 128 steps. As we mentioned earlier, LLM agent harnesses send a subset or summary of their full context to the underlying LLM using a process called context compaction. In the case of our world agent, without context compaction the original visit of any room revisit that has a gap larger than 128 cannot be retrieved from the context. However, our agent harness can send a compacted context to the world model (Figure 4).
4.1 Compacted World
Recall that an observer can choose one of four available actions in a given room. The observer can take a door at any of the room's four borders to go into a neighboring room. In the agent harness, we can build the compacted context of the session using only the observers actions. After an action, the observer moves by one room in our room grid. Therefore, we track the position of the observer in the harness without storing any information about the room's tiles. If the observer takes two steps at the same position, we only need to keep the most recent frame of the visited room in the context. Note that the harness cannot simply send these frames as a list since our models trained only on raw steps, in which every step moves to an adjacent room. The compacted context therefore has to look like a real walk.
Our agent harness plans the shortest walk that passes through every visited room and ends at the current one. This is an instance of the traveling salesman problem. Since the traveling salesman problem is NP-hard in general, our harness uses the Christofides approximation (Christofides, 2022) to plan a short tour through every visited room and removes the longest edge of the tour to obtain a walk. Each step of the walk carries the newest frame of its room and the action toward the next room. For example, suppose the observer's trajectory in a 4 room world is A, B, A, B, C, B, C, D, C, D. The compacted context is the walk A, B, C, D. When the visited rooms do not lie on a single path, the walk must pass through some rooms more than once. If room B connects to rooms A, C, and D, for example, the walk is A, B, C, B, D.
4.2 Compaction Policies
Our agent harness can follow one of two policies. Under compact every step, the harness compacts the full context before every call to the world model. Under compact when full, which is similar to the policy of coding agents such as Claude Code¹, the harness appends raw steps until the context holds 128 steps, compacts it, and then appends raw steps again. During our experiments with the compact when full policy, we observed that the agent harness compacted about once every 50 steps. We also observed that the context sent to the world model held about 103 steps on average.
5 EVALUATION
We begin by describing the experimental setting in § 5.1. We then answer three questions that follow our contributions. First, how far can the agent harness extend the context retrieval of a world model without retraining it (§ 5.2)? Second, how does the KV cache design at the model layer trade memory against context retrieval (§ 5.3)? Third, how does dreaming affect the context retrieval of each KV cache
¹We say the policy is similar, not identical, because LLM agents often compact when the context is nearly full, e.g., at 95% of the context window of the underlying LLM (Tirmazi et al., 2026).

Figure 5. Performing context compaction at the agent harness layer lets every world model retrieve rooms beyond its raw context window. Each bar shows the context retrieval gain for revisits with gaps in the range [128, 511] steps.
design (§ 5.4)? Finally, we measure the agent latency of our world agents, split into the inference latency of the world model and the latency of the agent harness (§ 5.5). The source code for our work and our benchmark generator are available in our GitHub repository. The weights of all 21 trained world models are available on Hugging Face.
5.1 Experimental Setting
We train our world models on 5000 generated episodes of our benchmark world. Each episode is 512 steps. We evaluate our models on 400 separate episodes. Each training window spans 128 steps. We train with 3 random seeds, 42, 43, and 44, and conduct 20K optimizer updates using batch size 4. We give each world model identical training windows in the same order for each seed. We use AdamW (Loshchilov & Hutter, 2019) for optimization with a peak learning rate of , , , a weight decay of 0.1, gradient norm clipping at 1.0, and a one-cycle schedule. During each evaluation, we sample 40 revisits from each of our 7 gap bins. We score every world model and every context that the agent harness sends on the same revisits. In our figures and results, we report the mean over our 3 seeds and error bars are one population standard deviation.
5.2 Agent Harness Layer
In this section, we show that context compaction at the agent harness layer allows us to retrieve rooms whose original visit was up to 511 steps earlier. This is 4 times beyond the 128 step context window size of our world models. This does not require any retraining. Figure 5 shows the context retrieval gain for all four model designs for revisits with gaps in the range [128, 511]. As expected, since the context window length is only 128 steps, sending the raw context gives us a gain of near zero, specifically in the range [0.03, 0.06]. If we conduct context compaction at every step, the gain

Figure 6. Context retrieval gain of our world model designs when the memory budget is fixed at 2,304 vectors. Note that each vector has elements and we use bits per floating point.

Figure 7. Context retrieval gain of our world model designs when the raw context window size is fixed at 128 steps.
becomes significantly larger for all four models, lying in the range [0.39, 0.51]. If we only conduct context compaction when the context is full, the gain is in the range [0.44, 0.54] for all models. We believe the compact when full policy scores slightly higher for two reasons: 1) its context holds more steps and keeps the most recent steps raw similar to the world model's training data, and 2) it is less affected by the five-step bias of the shuffled run (Appendix B.1). Compact when full also has a lower agent latency per step (§ 5.5). To rule out that these gains come simply from sending a shorter context, we send a truncated context that holds only the most recent steps, as many as the compacted context holds. This results in a near zero gain similar to the raw context window.
5.3 Model Layer
In this section, we show that when designing the KV cache at the model layer, world model designers face a tradeoff between how much context fits in a given amount of memory and how accurately the world model retrieves information from that context. We show both sides of this tradeoff in Figures 6 and 7. In Figure 6, we fix the memory budget of the world model's KV cache to 2,304 vectors. This memory budget is enough for us to store all 128 steps in the context window if we are using DD, since we only need to store 2 vectors per token for DD. However, since we need to store 16 vectors per token for Decoder-only and CED, we cannot store more than 16 steps in their context window. Similarly, since we need to store 8 vectors per token for CED-SWA, we cannot store more than 32 steps in its context window under our memory budget. Please refer to Appendix B.4 for more details.
For our constrained memory budget experiment, we train bounded versions of Decoder-only and CED in which their transformer blocks attend only to the 16 most recent steps. Similarly, we train a bounded version of CED-SWA, where the upper blocks attend only to the 32 most recent steps. We train these bounded versions of our world models from scratch, with identical training data, seeds, and number of updates as the existing (unbounded) versions of our world models. An alternative here would have been to shorten the context windows of existing versions of our world models only at inference time to fit the memory budget. However, this approach would make the existing versions of the world models read shorter context windows compared to the ones they were trained on. This confounds the effect of smaller memory with the effect of the mismatch between the context lengths the world model trained on and the ones it is evaluated on making it difficult to isolate these two in our results. Note that we do not need to train a bounded version of DD because the unbounded 128-step context window version of DD already fits within our memory budget. Therefore, we use the same version of our DD world model in both Figure 6 and Figure 7.
Using the same memory budget, DD is able to retrieve rooms with revisit gaps of up to 127 steps. However, the context retrieval gain of Decoder-only, CED, and CED-SWA declines significantly as soon as the revisit gap becomes larger than their context window. In other words, when memory is the constraint, a smaller KV cache per token lets a world model retrieve rooms much further back in a world agent exploration session.
In Figure 7, we instead fix the context length, i.e., all four world models read the same 128-step raw context window. Here, the smaller KV cache of DD comes at a price. DD retrieves rooms 8 to 31 steps back as well as Decoder-only, but its context retrieval gain falls behind as the revisit gap

Figure 8. The effect of dreaming on context retrieval gain for our four world model designs.
grows, e.g., 0.39 compared to 0.54 for revisit gaps in the range [64, 127]. Compared to Decoder-only, DD makes three changes to the architecture of the world model: it computes the keys and values of its upper blocks from , it uses SWA in its lower blocks, and it shares a single KV cache across all of its upper blocks. To understand which of these changes lowers the context retrieval gain, we compare neighboring designs in Figure 3, since each design changes exactly one property of the previous one. For revisit gaps of 32 to 63 steps, computing the upper keys and values from , as in CED, does not lower the context retrieval gain. Switching the lower blocks to SWA, as in CED-SWA, lowers it. Sharing a single KV cache across all upper blocks, as in DD, lowers it further.² In other words, the two changes that shrink the KV cache of DD, i.e., its SWA lower blocks and its shared KV cache, are the ones that lower context retrieval, while computing the keys and values from only saves prefill computation (§ 5.5).
5.4 Dreaming
The process of dreaming occurs when we make a world model predict new frames based on frames previously predicted by the world model (Ha & Schmidhuber, 2018; Hafner et al., 2020). Without dreaming, we include the ground truth frames from our benchmark world in the world model's context window and only use the world model to predict the current frame. In other words, dreaming implies we are allowing the context window of a world model to include frames from the world model's own output. Dreaming is often a more realistic setting for world agents in the same way that LLM agents typically include their own outputs
from previous prompts in the session in their context.
In our regular evaluation, we store the true frame in the agent harness's session history and only use the world model to predict the current room. In the dreaming setting, we instead start storing the world model's predicted frames in the agent harness's session history. Note that in our world agents, we store the layout of the benchmark world's room grid in the agent harness without actually storing the actual room, i.e., what tiles each room has. On an observer's first visit to a room, we store the true frame of the room in the agent harness's session history. Note that we do not use the world model on a first visit. On a revisit, we use the world model to predict the room from the context we send it through the agent harness. We then score the world model's prediction against the true room. In other words, our world agents only dream on revisits. In this section, we show that world models whose lower blocks use SWA, i.e., CED-SWA and DD, lose almost all of their context retrieval once they dream, whether the agent harness sends the raw context window or a compacted context.
We run our world agents for sessions of 512 steps in newly generated evaluation worlds that our world models were not trained on. In each session, the observer alternates between a loop of 128 steps (i.e. a revisit gap of exactly 128 steps) and a random walk of 128 steps. We measure the context retrieval gain on the revisit both with and without dreaming. Figure 8 shows our results. Without dreaming, compact every step has a gain in the range [0.37, 0.50] for all four world models. With dreaming, Decoder-only and CED keep a gain in the range [0.28, 0.42] with either context. However, the gain of CED-SWA and DD drops to at most 0.09. The drop also appears at short gaps. With loops of only 8 steps, the gain of CED-SWA and DD with dreaming is at most 0.14, compared to at least 0.33 for Decoder-only and CED (Appendix B.3).
Since CED and CED-SWA differ only in their lower blocks, which use SWA in CED-SWA, the drop comes with the switch to SWA lower blocks. Note that our experiments show where the drop appears, but they do not establish why SWA lower blocks cause it. Consequently, the longer context that SWA buys DD at a fixed memory budget (§ 5.3) only helps a world agent that does not dream.
5.5 Agent Latency
Agent latency comprises the inference latency of the model and the agent harness's latency which is mostly context compaction time. In Figure 9, we show the mean agent latency per step of a 512-step session for our world models trained using seed 42. For the raw context window, the harness latency is negligible (about 8 µs per step). Also for the raw context window, we have to prefill the whole raw context window on every step after step 128. This
²For revisit gaps in the range [32, 63], CED matches or exceeds Decoder-only. DD falls below CED-SWA. CED-SWA falls below CED in 2 of 3 seeds. In the third seed, Decoder-only and CED were still learning to retrieve distant rooms when training stopped. Hence, we compare the designs within each seed.

Figure 9. Mean agent latency per step over a 512-step exploration session of the benchmark world.
is because the learned position embeddings we use in our world models are based on the position of a step in the context window, i.e., the first step of the window gets the first position embedding, the second step gets the second one etc. Hence, when the context window is full and a new step pushes the oldest step out of the window, all remaining steps are shifted by one position. Consequently, the keys and values in the KV cache, which were computed at the old positions, no longer match their current steps. This forces the agent harness to prefill the entire window again. In the compact every step policy, we plan a new walk before every step. Since each new walk can visit the rooms in a different order, the context changes from one step to the next forcing us to prefill the compacted context on every step of the session. The inference latency is lower than with the raw context window since the compacted context itself is smaller. In the compact when full policy, we only plan a walk when the context is full, which happens about once every 50 steps. Otherwise, we just decode a step from the KV cache. Hence we only prefill on 8 of the session's 512 steps. Consequently, compact when full has the lowest agent latency. CED, CED-SWA, and DD prefill about 1.5 times faster than Decoder-only, since their upper blocks only process the most recent step. Please see Appendix B.5 for further details on our agent latency evaluation.
6 RELATED WORK
Laird & Clark (2026) compare memory mechanisms in transformer world models on a state recall task. Our paper additionally matches parameter counts within 7% for our evaluated world models and measures context retrieval gain using a shuffled run. R2M-Bench (Gu et al., 2026) compares each revisit with pairs from the same rollout that revisit nothing at a matched gap. Its controls, however, still act on the output of the world model. Our benchmark acts on the context instead. It rules out context reconstruction by generating a new world for every episode and separates
context retrieval from context inference with the shuffled run.
At the model layer, we compare designs that share keys and values across blocks. Other work reduces the memory of the KV cache in different ways. StreamingLLM (Xiao et al., 2024) keeps only a few initial tokens and a window of recent tokens. H2O (Zhang et al., 2023) evicts all but the most important and the most recent tokens. KIVI (Liu et al., 2024) quantizes keys and values to 2 bits. Since these techniques act on the KV cache of a given design, they can in principle be combined with the designs we compare.
At the agent harness layer, MemGPT (Packer et al., 2023) manages the context of an LLM by moving data between its context window and an external memory, similar to how an operating system manages memory. Tirmazi et al. (2026) formalize context compaction as the step in an agent loop that shrinks the state of the agent to fit the context window of the model. In language, what a compacted context preserves is hard to measure. In our benchmark world, however, we know that a compacted context preserves every visited room, which lets us measure context retrieval through a compacted context directly.
7 LIMITATIONS AND CONCLUSION
Our work has three main limitations. First, we evaluate a single benchmark world at a single model scale with three training seeds. Our world models also never train on compacted contexts. Second, our world agents only dream on revisits and only for loops of up to 128 steps. Therefore, we do not yet know how dreaming affects context retrieval beyond the raw context window. Third, the rooms of our benchmark world are laid out on a predetermined grid which simplifies our context compaction algorithm. Consequently, our results show context compaction in its ideal case. In world models where the camera moves continuously, an agent harness would first have to decide which frames show the same place.
Context retrieval in world models depends on both layers of the inference stack. At the model layer, a smaller KV cache per token reduces context retrieval at a fixed context length but allows for a longer context at a fixed memory budget. At the agent harness layer, context compaction lets a world model retrieve rooms far beyond its context window without retraining. However, once a world agent dreams, only the world models whose lower blocks attend over the full context instead of relying only on SWA show consistent context retrieval, with or without context compaction. Therefore, it is often easier for a world agent to extend the reach of its world model with context compaction at the agent harness layer as opposed to sacrificing full attention in the lower blocks of the world model.
REFERENCES
Ainslie, J., Lee-Thorp, J., de Jong, M., Zemlyanskiy, Y., Lebrón, F., and Sanghai, S. GQA: Training generalized multi-query transformer models from multi-head checkpoints. In Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing, pp. 4895–4901, Singapore, 2023. Association for Computational Linguistics.
Beltagy, I., Peters, M. E., and Cohan, A. Longformer: The long-document transformer. arXiv preprint arXiv:2004.05150, 2020.
Bruce, J., Dennis, M. D., Edwards, A., Parker-Holder, J., Shi, Y., Hughes, E., Lai, M., Mavalankar, A., Steigerwald, R., Apps, C., Aytar, Y., Bechtle, S. M. E., Behbahani, F., Chan, S. C., Heess, N., Gonzalez, L., Osindero, S., Ozair, S., Reed, S., Zhang, J., Zolna, K., Clune, J., Freitas, N. D., Singh, S., and Rocktäschel, T. Genie: Generative interactive environments. In Proceedings of the 41st International Conference on Machine Learning, volume 235 of Proceedings of Machine Learning Research, pp. 4603–4623. PMLR, 2024.
Christofides, N. Worst-case analysis of a new heuristic for the travelling salesman problem. Operations Research Forum, 3(1), 2022. doi: 10.1007/s43069-021-00101-z. Reprint of GSIA Technical Report 388, Carnegie Mellon University, 1976.
DeepSeek-AI. DeepSeek-V4.1-Flash: Pushing the limits of KV cache compression. Technical report, https://huggingface.co/deepseek-ai/DeepSeek-V4.1-Flash/blob/main/DeepSeek_V41_Tech_Report.pdf, 2026.
Drummyfish. 1bit graphics collection. https://opengameart.org/content/1bit-graphics-collection, 2018. OpenGameArt, CC0 public domain dedication.
Gu, Q., Gao, B., Chen, R., Li, G., Li, J., Wen, Q., Niu, L., Tang, J., Chu, X., and Zhao, J. R2M-Bench: Evaluating revisit memory via relative consistency in interactive video world models. arXiv preprint arXiv:2608.27328, 2026.
Ha, D. and Schmidhuber, J. World models. arXiv preprint arXiv:1803.10122, 2018.
Hafner, D., Lillicrap, T., Ba, J., and Norouzi, M. Dream to control: Learning behaviors by latent imagination. In International Conference on Learning Representations, 2020.
King, W., Xue, Z., Bian, Y., Huang, J., Li, H., Li, Y., Su, Y., Li, Y., Wang, H., Zhang, S., Zhang, S., Niu, Y., Xu,
S., Zhuang, J., Huang, H., and Duan, N. Echo-Memory: A controlled study of memory in action world models. arXiv preprint arXiv:2606.09803, 2026.
Laird, E. J. and Clark, C. On memory: A comparison of memory mechanisms in world models. Transactions on Machine Learning Research, 2026.
Lian, K., Cai, S., Liang, Y., and Liu, A. LoopNav: Benchmarking spatial consistency in world models. arXiv preprint arXiv:2505.22976, 2025.
Liu, Z., Yuan, J., Jin, H., Zhong, S., Xu, Z., Braverman, V., Chen, B., and Hu, X. KIVI: A tuning-free asymmetric 2bit quantization for KV cache. In International Conference on Machine Learning, 2024.
Loshchilov, I. and Hutter, F. Decoupled weight decay regularization. In International Conference on Learning Representations, 2019.
OpenAI. GPT-6 Astra: A new generation of intelligence. https://openai.com/index/gpt-6-astra/, 2026.
Oshima, Y., Iwasawa, Y., Suzuki, M., Matsuo, Y., and Furuta, H. WorldPack: Dynamic frame compression for long-context video world modeling. Transactions on Machine Learning Research, 2026.
Packer, C., Wooders, S., Lin, K., Fang, V., Patil, S. G., Stoica, I., and Gonzalez, J. E. MemGPT: Towards LLMs as operating systems. arXiv preprint arXiv:2310.08560, 2023.
Peng, Z., Ma, J., Sun, H., Gao, C., Xue, Z., Pan, Z., Cao, Z., Liang, J., and Li, J. Compression and retrieval: Implicit memory retrieval for video world models. arXiv preprint arXiv:2606.23105, 2026.
Shazeer, N. Fast transformer decoding: One write-head is all you need. arXiv preprint arXiv:1911.02150, 2019.
Song, C., Yang, Y., and Zhang, C. World in World: Explore the world with world models. arXiv preprint arXiv:2609.11548, 2026.
Sun, W., Zhang, H., Wang, H., Wu, J., Wang, Z., Wang, Z., Wang, Y., Zhang, J., Wang, T., and Guo, C. World-Play: Towards long-term geometric consistency for real-time interactive world modeling. arXiv preprint arXiv:2512.14614, 2025.
Sun, Y., Dong, L., Zhu, Y., Huang, S., Wang, W., Ma, S., Zhang, Q., Wang, J., and Wei, F. You only cache once: Decoder-decoder architectures for language models. In Advances in Neural Information Processing Systems, volume 37, pp. 7339–7361, 2024.
Team, A., Zhang, K., Li, C., Zhan, Y., Ge, Y., Yin, Y., Tan, J., He, K., Fan, L., Liu, R., et al. Alayaworld: Long-horizon and playable video world generation. arXiv preprint arXiv:2607.06291, 2026.
Tirmazi, H., Markelon, S., Bishop, A., and Mitzenmacher, M. Context compaction theory. arXiv preprint arXiv:2608.01326, 2026.
Tiwari, A., Bhalla, A., Prasad, D., and Ji, H. Does video memory use what it retrieves? A causal audit of memory specificity. arXiv preprint arXiv:2609.12090, 2026.
Xiao, G., Tian, Y., Chen, B., Han, S., and Lewis, M. Efficient streaming language models with attention sinks. In International Conference on Learning Representations, 2024.
Xiao, Z., Lan, Y., Zhou, Y., Ouyang, W., Yang, S., Zeng, Y., and Pan, X. WorldMem: Long-term consistent world simulation with memory. In Advances in Neural Information Processing Systems, 2025.
Ye, Y., Lu, X., Jiang, Y., Gu, Y., Zhao, R., Liang, Q., Pan, J., Zhang, F., Wu, W., and Wang, A. J. MIND: Benchmarking memory consistency and action control in world models. arXiv preprint arXiv:2602.08025, 2026.
Yi, J., Kim, M., Cho, P. H., Jang, W., Yun, S., and Kim, S. WorldKV: Efficient world memory with world retrieval and compression. arXiv preprint arXiv:2605.22718, 2026.
Zhang, B. and Sennrich, R. Root mean square layer normalization. In Advances in Neural Information Processing Systems, volume 32. Curran Associates, Inc., 2019.
Zhang, Z., Sheng, Y., Zhou, T., Chen, T., Zheng, L., Cai, R., Song, Z., Tian, Y., Ré, C., Barrett, C., Wang, Z., and Chen, B. H₂O: Heavy-hitter oracle for efficient generative inference of large language models. arXiv preprint arXiv:2306.14048, 2023.
AI USAGE DISCLOSURE
Generative AI was used as an assistant throughout this work for the following three purposes. The first purpose was to help the authors write the code for 1) the benchmark, 2) the world models, 3) the agent harness, and 4) the evaluation. Two agent harnesses, Claude Code and Codex, were also used to run the experiments under the direction of the authors. The authors reviewed and corrected this code. The second purpose was to help the authors draft and revise parts of the text, the figures, and the LATEX code. The authors reviewed, rewrote, modified, and verified all of the text and take full responsibility for it. The third purpose was to help the authors search for related work, which the authors then read and verified. Note that all of the content of this paper has been human reviewed and verified for correctness prior to submission. The following LLMs were used for the above purposes: Anthropic's Claude Opus 5.5, Claude Opus 5, and Claude Opus 4.8, and OpenAI's GPT-5.6 Sol and GPT-6.1 Sol. Finally, the authors also used the AI Mode of Google's Search Engine to help with the initial research/exploration and web browsing that eventually led to the formulation of the paper's ideas.
A RIGOROUS BACKGROUND
The decoder-only Transformer is one of the most popular designs for building both world models and large language models. Let be a model with Transformer blocks , an embedding layer , a final normalization layer , and an unembedding layer . Assume has a vocabulary size of with embedding width . Consider a sequence of input tokens. The embedding layer maps each input token to an embedding vector of dimension . Therefore, the shape of the input data becomes . Auxiliary data encoding the position or other information about the token is also added to the embedding vector representing the token. Let be the input data with auxiliary information added to it. For , let and be the input and output of Transformer block respectively. The model sends as input to , i.e., for every . In particular, receives . Note that all and tensors have the shape .
Consider any given Transformer block in . processes its input data first using self-attention and then using a multi-layer perceptron. More concretely, outputs with where is a multi-layer perceptron, is self-attention, and and are normalization functions such as RMSNorm (Zhang & Sennrich, 2019). Note that the attention, perceptron, and normalization parameters of each Transformer block are separate. is a function , i.e., it is applied to each of the rows of its input independently. Recall that in , the rows were the embedding vectors corresponding to the tokens. This means that no information between tokens is shared by . has a hidden width which is typically 4D. Consequently, in an , each of the rows is multiplied by a matrix, passed through a non-linear function, and then multiplied by a matrix. The time complexity of one forward pass of over the whole input is therefore (assuming ). Since is fixed once the model is built, we can treat as a constant, giving us . , on the other hand, is a function and information between tokens is shared inside . In fact, self-attention is the only part of the model that shares information between tokens. We discuss self-attention in detail below.
One of the most common designs for self-attention is causal multi-head self-attention. Assume our model uses self-attention with heads. Note that needs to be a divisor of . Let for some . Each head is a function for . Let denote the input to self-attention, a tensor of shape . Inside the Transformer block this input is . Inside each
head, is multiplied by 3 learned matrices , , and each of which is of shape . They are called the query projection, the key projection, and the value projection respectively. We then get , , and for each head . Note that , , and are all matrices of shape .
The final output of is then
Over here, is a matrix of shape such that when and otherwise. The reason for adding is to ensure that each token only gets information about itself and the tokens before it. This is why is called the causal mask. Note that the softmax is taken along each row of the matrix. The output of the softmax is therefore a matrix of shape . Since we then multiply it by which is a matrix of shape , the overall output of is a matrix of shape . After processing each head, we have a set of outputs . concatenates them to form
Here is a learned matrix of shape called the output projection. Note that the concatenated matrix has shape , so is a matrix of shape . This is what makes the residual addition well defined, and why is a matrix of shape as discussed earlier. The mask defined above gives each token access to its entire prefix. Some architectures use sliding window attention, as opposed to ordinary (i.e., full) attention. Sliding window attention restricts the self-attention of a Transformer block to a bounded window of tokens. It replaces in Equation 1 with the windowed causal mask , where when and otherwise. Other than the mask, a Transformer block that uses sliding window attention is identical to a regular Transformer block.
Consider a given attention head in of a Transformer block . The query, key, and value projections in are matrix multiplications of an matrix and a matrix. The time complexity of the three projections in is therefore . Since has h heads, the time complexity of each projection over all heads is because . Note that this only accounts for the projections and not the subsequent attention computations. For the attention computation, is a multiplication between an matrix and a matrix so it costs per head, i.e., over all heads. Multiplying the softmax output by is a multiplication between an matrix and an matrix so it costs per head, i.e., over all heads. Finally, the output projection is a multiplication
Prior work also uses the term layer for a transformer block. We use the two terms interchangeably.
between an matrix and a matrix so it costs . The overall time complexity of one forward pass of is therefore . Similar to , we can assume is constant, which simplifies the time complexity to . Recall that computes followed by . The overall time complexity of one block is therefore . Since the model has Transformer blocks, the overall time complexity of one forward pass of is .
A.1 Inference and KV Cache
During inference, a decoder-only Transformer generates output tokens sequentially. Consider a model with the parameters as defined earlier. Let's assume , upon receiving a sequence of input tokens, produces output tokens one at a time. To process the attention head in , we need to compute the queries, keys, and values for the relevant tokens. Specifically, we first focus on the computation of any given row in . To get row of , we need together with and . Here, , , and are row of the query projection , key projection , and value projection , respectively. This follows directly from the fact that we first have to multiply and inside the softmax function of . The softmax function itself is computed row by row. After the softmax, we multiply the softmax output by the value projection which means we need as well. Note that we do not need and because the causal mask ensures that the attention weights for these positions are zero.
Since , , and are matrices, and a row of is a vector, computing their products , and for some row is . Recall that we assume and are constant, making the computation of , and effectively . Once and are available, row of performs dot products and a weighted sum of values. Each of them is , so row costs .
If we use no form of caching, model has to recompute every row of to process the next token. This means recomputing every row of in every attention head of every Transformer block . Computing all rows of a given attention head has time complexity . Since the number of heads is fixed, computing all rows for the entire Transformer block also has time complexity . Since model has Transformer blocks, the overall time complexity of producing the next token after tokens without a cache is .
KV caches optimize inference by storing the key and value projections for all processed tokens in a given token sequence for each attention head of each Transformer
block . This means that to compute row of , we can read and from the KV cache and only compute , and for the current row . With a KV cache, to compute the next token after a sequence of tokens, we only compute , , and in each block which is . The dot products and the weighted sum then read cached vectors which is . Therefore, the time complexity of processing a new token is in each Transformer block and in the entire model . The KV cache therefore reduces the cost of generating each new token from to . If a Transformer block uses sliding window attention, the time complexity of generating a new token using can be further reduced from to , where is the window size.
However, by using a KV cache, we are effectively reducing the time of processing new tokens by trading it off with increased memory usage. For a given attention head and a sequence of tokens, a KV cache stores and , which are vectors of numbers each. A Transformer block has heads and . Therefore, a KV cache stores floating point values for each Transformer block . Since a model has Transformer blocks, the total size of its KV cache is where is the number of bytes per floating point value. If a given Transformer block uses sliding window attention, its KV cache only needs to store bytes, where is the window size.
Inference on a new prompt is typically done in two phases called the prefill phase and the decode phase. In the prefill phase, the model reads the input tokens in one forward pass and fills the KV cache of every block with the key and value projection corresponding to each input token. The prefill phase therefore has time complexity even when the KV cache is used because it starts with an empty KV cache. In the decode phase, produces one new token at a time while reading the KV cache and adding the new token's key and value projections back to the KV cache. Hence the decode phase has time complexity per token.
A.2 Decoder-Decoder Models
Prior work (Sun et al., 2024) proposes a novel architecture for large language models called a Decoder-Decoder model. Let be a Decoder-Decoder model. uses Transformer blocks where the first blocks are the lower blocks of and the remaining blocks are the upper blocks of . The lower blocks use a self-attention whose KV cache stays constant in . The lower blocks of a Decoder-Decoder model can be built with either sliding window attention or gated retention. In the sliding window attention version, each lower block attends over a window of tokens and therefore stores numbers regardless of . Let be the normalized output of the last lower block, where is a normalization function. projects once into a shared key matrix and a shared value matrix , using learned matrices and of shape , so and both have shape . The upper blocks of use cross-attention as their token mixer.
In cross-attention, and are divided into slices of columns where and is the number of attention heads per Transformer block. Let and denote the -th slices of columns of and . Head of in an upper block computes its own query projection . Then, it uses the shared key and value matrices to compute the cross-attention
Note that the mask in Equation 3 is the full causal mask of shape defined earlier. Each upper block therefore reads the entire prefix through the shared pair. Each lower block reads only its window of tokens. remains autoregressive. Like , concatenates its head outputs and multiplies the result by an output projection of shape . The only token-mixing parameters an upper block owns are therefore and . The upper Transformer blocks do not have their own key or value projections. This simplifies the KV cache to a single shared pair which holds 2LD numbers for any number of upper Transformer blocks. The total size of a KV cache for the entire model is therefore bytes where the second term is a constant in and is the number of bytes per floating point. Compared to the KV cache of , which needs bytes, a Decoder-Decoder model divides the part of the cache that grows with the history by .
A.3 Causal Encoder-Decoder Models
DeepSeek recently released a large language model called DeepSeek-V4.1-Flash (DeepSeek-AI, 2026). DeepSeek-V4.1-Flash uses a novel architecture called a Causal Encoder-Decoder which is a descendant of Decoder-Decoder models. Let be a Causal Encoder-Decoder model. splits its Transformer blocks similar to Decoder-Decoder models. 's lower blocks are called encoder blocks and 's upper blocks are called decoder blocks, respectively. 's lower blocks, i.e., the encoder blocks, are ordinary decoder-only Transformer blocks akin to those in . Each encoder block in computes separate key and value projections from its input and maintains a dedicated KV cache. The output of the final lower block of is where is a normalization function. 's upper Transformer blocks, however, behave differently from Decoder-Decoder
models. Unlike Decoder-Decoder models, which use a shared key and value matrix, each upper Transformer block in has its own key projection and value projection . Note that both and are learned matrices of shape . A given decoder Transformer block in computes and which are both matrices of shape . Note that all pairs of and are computed independently from the same . The description above follows the general formulation in the DeepSeek-V4.1-Flash technical report. DeepSeek-V4.1-Flash adds components that omits. Its first two encoder layers use sliding-window attention. Its remaining encoder layers use compressed sparse attention. Its decoder layers also run sliding-window self-attention over their own hidden states. One of its decoder layers computes a global pair that the other decoder layers reuse.
In an , each decoder Transformer block uses its key and value projections and to compute cross-attention. Let and denote the j-th slices of columns of and . Head of in decoder block first computes the query projection . Then head computes cross-attention as follows.
where is the causal mask and is the output projection. Identically to self-attention, the head outputs are concatenated before being multiplied by . Each decoder Transformer block in therefore has its own , , , and . The KV cache for each decoder block therefore has to store floating point values. The encoder blocks of are identical to the Transformer blocks in so the KV cache of each encoder block has the same size as in . Hence the total size of the KV cache of is bytes where is the number of bytes per floating point value. Recall that this is the same as the total KV cache size of . A Causal Encoder-Decoder model, therefore, does not provide any KV cache memory savings out of the box. However, significantly reduces the amount of computation needed for prefill. Recall from § A.1 that fills the KV cache for a prompt of tokens with one forward pass over all blocks in . In every and is a function of . Hence the KV cache for a prompt is filled by executing the encoder blocks and the projections of . Importantly, the decoder blocks only need to run for the last token of the prompt during the prefill phase because filling their KV caches only needs projections of . The prefill phase in therefore costs as compared to in . The decode phase has the same time complexity, , in both and since every Transformer block still has to compute the new token's query projection and attend over the cached tokens.
B FURTHER EVALUATION
This section contains a set of fun deep dives across multiple aspects of our evaluation.
B.1 Agent Harness Layer
In Figure 5 of § 5.2, we showed the context retrieval gain for all four world model designs only over the gap bins that are larger than 128 steps, i.e., larger than the context window length of the models. In this section, we look at the context retrieval gain across all gap bins in detail. In Figure 10, we show the gain of each world model for all our gap bins both when we send the raw context window directly and when we conduct context compaction at each step. When we send the raw context window, the gain of all our world model designs drops to near zero as soon as the revisit gap is larger than the model's context window length of 128 steps. However, when we do context compaction, the gain stays roughly flat across all gap bins. Note that at gaps of 8 to 127 steps, the context compaction version almost always has a lower score compared to the raw context window for all our world models. We suspect that part of this difference comes from the shuffled run. The shuffled run keeps the five most recent steps of the context, and a compacted walk can pass through the revisited room within its last five steps. In that case, the shuffled context still contains the revisited room, which lowers the context retrieval gain of the compacted context.
B.2 Truncated Contexts
As mentioned in § 5.2, we want to rule out that the gains of context compaction come from simply sending a shorter context to the world model. In Figure 11, we compare context compaction with the alternative of simply truncating the context by keeping the most recent steps. Beyond 128 steps, the context retrieval gain of using a truncated context drops to near zero similar to using no context compaction. Therefore, a shorter context alone is not the reason for context compaction improving a world model's long context retrieval beyond its context window length.
B.3 Dreaming
In Figure 8 in § 5.4, we show the context retrieval gain in the dreaming setting for a loop with 128 steps. In this section, we extend our results to loops of lengths 8 and 32 steps respectively. Figure 12 shows our results. Without dreaming and with the raw context window, the gain of CED-SWA and DD falls as the loop grows since the starting room moves further back in the raw context window until it is the oldest step at 128 steps. Without dreaming and with context compact at every step, the gain of every world model stays roughly constant across loop lengths. With dreaming,
Table 1. The latency (in milliseconds) for a call to our world model designs using a context of 128 steps. We report the median latency over 30 iterations.
| Model | Decode | ||
|---|---|---|---|
| Batch 1 | Batch 16 | Prefill | |
| Decoder-only | 5.74 | 17.42 | 14.53 |
| CED | 5.89 | 18.06 | 9.80 |
| CED-SWA | 5.30 | 11.37 | 9.56 |
| DD | 4.49 | 7.53 | 9.20 |
the gain of CED-SWA and DD stays at 0.14 or less at every loop length and with either context.
B.4 Memory Budget
In Figure 6 in § 5.3, we use a fixed memory budget of 2,304 vectors for the KV cache of all four of our world model designs. Note that each vector has 384 elements each of which is a 32-bit floating point value. In this section, we discuss the reasoning behind our memory budget. We first show that to maintain a context window size of 128 steps, our most memory efficient world model design, DD, requires 2,304 vectors. As mentioned in § 5.3, we then show that the same memory budget results in a context window length of only 16 steps for Decoder-only and CED and a context window length of 32 steps for CED-SWA. Recall from § 3.2 that each step of our benchmark world is 9 tokens, i.e., 8 tokens for the tiles of a room and 1 token for the action. In DD, we store a shared key vector and a shared value vector per token for its upper blocks, i.e., 2 vectors per token. Therefore, a context window of 128 steps needs vectors in DD. Since each vector has elements stored as 32-bit floating point values, this is about 3.5 MB. When using Decoder-only and CED, we have to store a key vector and a value vector per token in each of their 8 transformer blocks, i.e., 16 vectors per token. Hence, their context window is steps. With CED-SWA, we have to store a key vector and a value vector per token in each of its 4 upper blocks, i.e., 8 vectors per token. This results in a context window size of steps. Note that we also need to store vectors for the 4 lower blocks of CED-SWA and DD that use SWA with 2-step windows. However, since the number of vectors needed by SWA blocks do not grow with the context, we do not count them toward the budget for simplicity. They add only a fixed cost of about 3.125% to the total memory of CED-SWA and DD.
B.5 Timing Methodology
In this section, we look a bit more carefully into the inference latency of our world model designs. In Table 1, we show the decode latency and prefill latency of all four of

Figure 10. The context retrieval gain of all four of our world model designs over a range of gap bins. We use solid black lines to show the 128-step raw context window and use dashed gray lines to show a compacted context of about 80 steps.

Figure 11. Context retrieval gain for gap bins of 128 to 511 steps.
our world model designs. Decode latency, as is standard terminology, is the time to predict one step when we already hold the previous 127 steps in the KV cache. We measure decode latency at batch sizes of 1 and 16. Prefill latency is the time to read the 128-step raw context window, fill them up in an empty KV cache, and then predict the next step. Note that we only need to run prefill on the upper blocks of CED, CED-SWA, and DD at the last step (step 128) since their upper blocks only see earlier steps through the projected keys and values. We benchmark the trained world models of seed 42, i.e., the same world models as in
Figure 1, on frames of our evaluation recording. We run all of our measurements in float32 on the GPU of an Apple M4 Pro with PyTorch 2.14. In Table 1, we show the median latency over 30 iterations of the same request to the world model. To measure the agent latency per step in Figure 9, we replay the first episode of our evaluation recording under each policy. For each step in the episode, we record 1) whether the policy decodes one step or prefills its context, 2) how many steps the context holds, and 3) the harness latency, i.e., how long the agent harness takes to build the context sent to the world model. We measure the harness latency of a step as the median over 3 runs of building its context, i.e., planning and gathering a compacted context or stacking the frames of the raw context window. We measure the inference latency of a step as the median over 10 runs of the world model decoding or prefilling a context of that length. The agent latency of a step is the sum of its harness latency and its inference latency. Note that in the compact every step policy (the policy where context compaction occurs the most), the harness latency is 7.8 ms per step on average and 15.0 ms at most.

Figure 12. Context revisit gain for revisit loops of length 8, 32, and 128 steps respectively with and without letting the world model dream.