Manuscript Offprint

arXiv:2610.02687

Decoupling Memory from Context: Structured Memory for Token-Efficient Test-Time Continual Learning

Yehya Farhat, Michael Desmond, Anastasios Kyrillidis

Abstract

Large language models (LLMs) are increasingly deployed in enterprise, scientific, and medical applications, where agents must incorporate domain-specific knowledge and adapt from experience. Context engineering offers a practical alternative to weight updates by improving model behavior through instructions, strategies, and evidence supplied at inference time. However, adapting context online typically requires a costly trial-and-error process, while queries are often processed independently, preventing useful experience from carrying forward. Memory systems address this limitation by retaining information across interactions, but approaches that continually append information to a shared context face increasing token costs, context-window limits, and performance degradation as the context expands. We introduce a unified formulation of context optimization and show that an agent memory system update can be interpreted as optimization update procedure over the model's context. This perspective attempts to provide a principled framework for studying memory design and its efficiency. We then propose GraphMemory, a lightweight graph-based memory that accumulates, refines, organizes, and connects reusable strategies. For each query, GraphMemory retrieves only the relevant subgraph, enabling online context adaptation without exposing the model to the entire memory. Under bounded retrieval, the amount of retrieved memory remains constant as the number of processed examples grows. Experiments show that GraphMemory achieves competitive downstream performance while using approximately 81–85% fewer memory-construction tokens than our baselines.

1 Introduction

Modern large language models (LLMs) achieve strong performance across reasoning, question answering, and open-ended generation tasks [20]. Yet deployed agents largely remain static: with fixed parameters, information acquired from one interaction does not naturally improve later behavior. Parameter-efficient fine-tuning (PEFT) provides one mechanism for adaptation [8, 6, 11], while more recent methods generate context-specific adapters on the fly in a single forward pass [4]. These approaches still require access to model weights and training infrastructure, and encode their learned state in model-specific parameters. This limits continual adaptation during deployment and makes the acquired knowledge difficult to transfer across agents.

40th Conference on Neural Information Processing Systems (NeurIPS 2026). Workshop: Towards Test-Time Continual Learning Agents.

Context engineering offers a weight-free alternative by adapting a frozen model through instructions, demonstrations, strategies, or evidence supplied alongside each query to leverage its in-context learning abilities [3]. Prompt-optimization methods treat this context as the optimization variable and search for task-level prompts that improve performance [23, 10, 14, 1]. However, they generally optimize a single prompt against an offline dataset or user-defined evaluator rather than accumulating experience during deployment. Other methods use a hybrid setup that derives training signals from model behavior itself [16]. Persistent memory systems instead update an external natural-language memory as new problems are solved. Dynamic Cheatsheet stores reusable strategies in a persistent file [17], while Agentic Context Engineering (ACE) incrementally evolves a structured playbook through a Generator–Reflector–Curator architecture [25]. Because this memory remains external to the model, it can be inspected, edited, and transferred across agents and has shown success in large-scale enterprise applications [18, 13].

Nevertheless, scaling such memory introduces a fundamental problem. Because existing systems largely maintain a flat collection or a single evolving file, the model must process an increasingly large and heterogeneous memory context for every query. This increases token usage, pushes against context-window limits, and can lead to context degradation or collapse. To address these limitations, we introduce GRAPHMEMORY, a structured external memory for scalable test-time learning. GRAPHMEMORY represents reusable ACE-style knowledge points as nodes and captures useful relationships between them as weighted edges. For each query, the system identifies a small set of relevant entry nodes and traverses their local neighborhoods, exposing only the resulting subgraph to the language model. This representation enables selective retrieval without requiring all experience to be compressed into one global playbook or assigned exclusively to an isolated section. It also makes relationships among individual lessons explicit, allowing knowledge acquired from different experiences to be retrieved together when their connection is useful to the current problem. Our contributions are listed as follows:

• A unified context-optimization framework. We formulate adaptation of a frozen language model as optimization over its textual context and show that persistent memory systems can be interpreted as optimization procedures that update this context across examples. Under bounded update sizes, we show that the context used by append-only memory grows as O(N)O(N), whereas bounded retrieval maintains an O(1)O(1) memory-context length per query.

• GraphMemory. We introduce GRAPHMEMORY, a lightweight external memory that accumulates, refines, organizes, and connects reusable strategies in an evolving graph. Nodes represent ACE-style knowledge points, while weighted edges capture useful relationships among them. For each query, GraphMemory identifies relevant entry nodes, traverses their local neighborhoods, and supplies only the resulting subgraph to the language model. This replaces full-memory prompting with selective relational retrieval while preserving the interpretability, portability, and weight-free adaptation of natural-language memory.

• Competitive performance at substantially lower cost. Across three dataset–model settings on two financial reasoning tasks, FORMULA and FINER, GraphMemory remains within 4.0 percentage points of ACE with Claude Haiku 4.5 and outperforms ACE by 1.5 points on FORMULA with Qwen3.8-27B. GraphMemory reduces training-token usage by 81–85%, test-token usage by 79–92%, and active training time by 21–34%.

References (21)