Manuscript Offprint

arXiv:2610.13348

Test-Time Memory Construction

Zijun Wang, Yifan Ji, Haidong Xin, Zhenghao Liu, Yukun Yan, Zulong Chen, Yu Gu, Ge Yu, Maosong Sun

ABSTRACT

Large Language Models (LLMs) struggle to answer questions over long interaction histories, where relevant evidence may be scattered across distant sessions. Existing memory systems typically construct and maintain sophisticated memory representations offline, before user queries are observed, incurring substantial overhead and limiting their ability to adapt memory construction to query-specific information needs. In this paper, we propose T²Mem, a Test-Time Memory construction framework that defers memory construction to inference and progressively builds memory along the reasoning process. Specifically, T²Mem extracts lightweight episode-level metadata offline to capture key events and temporal associations as retrieval cues, while retaining links to the original interactions to facilitate the reconstruction of dependencies across episodes. At test time, the LLM adaptively retrieves and organizes metadata and raw interactions, progressively constructing query-specific memory as reasoning unfolds. Experiments on LoCoMo and LongMemEval show the effectiveness of T²Mem by consistently outperforming strong baselines across different backbone LLMs while substantially reducing the overhead of memory construction. Further analysis demonstrates that deferring memory construction to inference enables the memory construction process to dynamically adapt to the information needs of individual queries. All code is available at https://github.com/OpenBMB/T2Mem.

1 INTRODUCTION

Large Language Models (LLMs) have demonstrated strong emergent capabilities across a wide range of tasks (Yao et al., 2023; Li et al., 2025; Xin et al., 2026b; Liu et al., 2026). However, as user interactions grow longer, LLMs still struggle to reason over extended interaction histories due to limited context windows and the difficulty of effectively locating relevant information within long contexts (Hu et al., 2025; Liu et al., 2024; Hsieh et al., 2024). A straightforward solution is Retrieval-Augmented Generation (RAG), which segments historical interactions into chunks and retrieves relevant ones at inference time (Lewis et al., 2020; Edge et al., 2024; Li et al., 2025; 2026b). However, chunk-level retrieval often treats historical interactions as isolated units, potentially disrupting temporal context and cross-turn dependencies among related interactions. This fragmentation makes it difficult for LLMs to fully exploit the interconnected information embedded in long interaction histories (Xin et al., 2026a; Zhang et al., 2025).

To address this limitation, recent memory systems (Chhikara et al., 2025; Kang et al., 2025; Fang et al., 2026) organize long interaction histories into manageable memory units. These methods introduce dedicated mechanisms to filter, summarize, and consolidate historical interactions into persistent memory representations, enabling efficient access in future interactions. However, constructing and maintaining such sophisticated memory representations can incur substantial overhead. In particular, offline memory construction must anticipate diverse future queries and preserve sufficiently comprehensive information in each memory unit, resulting in considerable preprocessing and maintenance costs that can hinder the scalability and practical deployment of memory systems (Peng

∗^{*}indicates equal contribution.

†^{\dagger}indicates corresponding author.

et al., 2026). Recent efforts have therefore explored deferring memory construction to test time, reducing the reliance on costly preconstructed memory representations (Yu et al., 2026; Yin & Tang, 2026). Nevertheless, these approaches typically construct memory from an initially retrieved candidate set, making it difficult to acquire additional evidence that is not retrieved initially but becomes necessary as the memory construction process unfolds.

Recent advances in test-time scaling have demonstrated the potential of leveraging additional inference-time computation to elicit stronger reasoning capabilities from LLMs. By allocating more computation at inference time, LLMs can iteratively explore, verify, and revise intermediate solutions (Snell et al., 2025; OpenAI et al., 2024; Guo et al., 2025). This raises a natural question: Can memory construction similarly benefit from inference-time reasoning, allowing an LLM to dynamically determine what historical information to activate and organize as it reasons? We answer this question by treating memory not as a fixed representation constructed offline, but as an evolving state that is progressively constructed during inference.

Based on this perspective, we propose T²Mem, a Test-Time Memory construction framework that dynamically constructs memory during inference. T²Mem draws inspiration from associative recall, where relevant memories can be progressively activated as retrieval cues emerge (Teyler & Rudy, 2007; Horner et al., 2015). Instead of constructing sophisticated memory representations offline, T²Mem first extracts lightweight episode-level metadata that captures salient events and temporal associations, while retaining backlinks to the corresponding raw interactions. The metadata provides a compact structure for associating related episodes and locating their underlying evidence. During inference, the LLM progressively reasons over the query and uses this evolving reasoning process to navigate the metadata and selectively activate corresponding raw interactions. In this way, memory construction and reasoning are interleaved: each newly activated piece of evidence can inform subsequent reasoning and, in turn, guide the construction of a more relevant memory state. The final memory is therefore not predetermined before inference, but emerges progressively from the interaction between reasoning and memory activation.

In our experiments, we evaluate T²Mem on LoCoMo and LongMemEval with two backbone LLMs. Across both benchmarks, T²Mem consistently outperforms strong memory and retrieval baselines under comparable total token budgets, demonstrating the effectiveness of dynamically constructing memory at test time. Further analysis reveals that deferring memory construction to inference allows T²Mem to adapt the construction process to the specific information needs of each query. This advantage is particularly evident for queries that require deeper memory construction, such as multi-hop and temporal questions, where relevant evidence is distributed across multiple episodes and cannot be fully identified through a single initial retrieval step. Moreover, by leveraging episode-level metadata, T²Mem enables the LLM to establish dependencies across episodes and trace these dependencies back to relevant source interactions during reasoning, facilitating more effective memory construction without the substantial overhead of maintaining sophisticated memory units.

References (38)