将记忆与上下文解耦:面向Token高效测试时持续学习的结构化记忆

arXiv cs.AI 论文

摘要

本文提出了GraphMemory,一种轻量级的基于图的记忆系统,将存储的知识与上下文解耦,每次查询仅检索相关的子图,从而实现Token高效的测试时持续学习,同时相比基线方法节省81–85%的记忆构建Token。

arXiv:2610.02687v1 Announce Type: new 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 an 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.
查看原文
查看缓存全文

缓存时间: 2026/10/05 09:59

# Decoupling Memory from Context: Structured Memory for Token-Efficient Test-Time Continual Learning
Source: [https://arxiv.org/html/2610.02687](https://arxiv.org/html/2610.02687)
\\workshoptitle

Towards Test\-Time Continual Learning Agents\\workshoptitleTowards Test\-Time Continual Learning Agents

Yehya FarhatAffiliation:Rice University, Department of Computer ScienceAffiliation:Houston, TX, USAEmail:[Yehya\.Farhat@rice\.edu](mailto:)Michael DesmondAnastasios KyrillidisAffiliation:Rice University, Department of Computer ScienceAffiliation:Houston, TX, USAEmail:[anastasios@rice\.edu](mailto:[email protected])

###### 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 approximately8181–85%85\\%fewer memory\-construction tokens than our baselines\.

## 1Introduction

Modern large language models \(LLMs\) achieve strong performance across reasoning, question answering, and open\-ended generation tasks\[[20](https://arxiv.org/html/2610.02687#bib.bib17)\]\. 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](https://arxiv.org/html/2610.02687#bib.bib1),[6](https://arxiv.org/html/2610.02687#bib.bib2),[11](https://arxiv.org/html/2610.02687#bib.bib3)\], while more recent methods generate context\-specific adapters on the fly in a single forward pass\[[4](https://arxiv.org/html/2610.02687#bib.bib5)\]\. 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\.

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](https://arxiv.org/html/2610.02687#bib.bib6)\]\. Prompt\-optimization methods treat this context as the optimization variable and search for task\-level prompts that improve performance\[[23](https://arxiv.org/html/2610.02687#bib.bib7),[10](https://arxiv.org/html/2610.02687#bib.bib8),[14](https://arxiv.org/html/2610.02687#bib.bib9),[1](https://arxiv.org/html/2610.02687#bib.bib10)\]\. 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](https://arxiv.org/html/2610.02687#bib.bib4)\]\. 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](https://arxiv.org/html/2610.02687#bib.bib11)\], while Agentic Context Engineering \(ACE\) incrementally evolves a structured playbook through a Generator–Reflector–Curator architecture\[[25](https://arxiv.org/html/2610.02687#bib.bib12)\]\. 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](https://arxiv.org/html/2610.02687#bib.bib21),[13](https://arxiv.org/html/2610.02687#bib.bib22)\]\.

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 introduceGraphMemory, a structured external memory for scalable test\-time learning\.GraphMemoryrepresents 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 asO⁡\(N\)O\(N\), whereas bounded retrieval maintains anO⁡\(1\)O\(1\)memory\-context length per query\.
- •GraphMemory\.We introduceGraphMemory, 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,FormulaandFiNER, GraphMemory remains within4\.04\.0percentage points of ACE with Claude Haiku 4\.5 and outperforms ACE by1\.51\.5points onFormulawith Qwen3\.8\-27B\. GraphMemory reduces training\-token usage by8181–85%85\\%, test\-token usage by7979–92%92\\%, and active training time by2121–34%34\\%\.

## 2Context and Memory Formalization

### 2\.1Offline Context Optimization

Let𝒟=\{\(xi,yi\)\}i=1n\\mathcal\{D\}=\\\{\(x\_\{i\},y\_\{i\}\)\\\}\_\{i=1\}^\{n\}be an offline training set, letffbe a frozen language model, and letc∈𝒞c\\in\\mathcal\{C\}denote textual context supplied alongside an input\. We define the empirical context risk as

L𝒟​\(c\)=1n​∑i=1n𝔼⁡\[ℓ⁡\(f⁡\(c,xi\),yi\)\],L\_\{\\mathcal\{D\}\}\(c\)=\\frac\{1\}\{n\}\\sum\_\{i=1\}^\{n\}\\mathbb\{E\}\\left\[\\ell\\bigl\(f\(c,x\_\{i\}\),y\_\{i\}\\bigr\)\\right\],\(1\)where the expectation is over any randomness in the model or its execution environment\. Context optimization seeksc∗∈arg⁡minc∈𝒞​L𝒟​\(c\)c^\{\*\}\\in\\arg\\min\_\{c\\in\\mathcal\{C\}\}L\_\{\\mathcal\{D\}\}\(c\)\. The context may contain instructions, demonstrations, knowledge, strategies, or any combination thereof\. Becauseccis a discrete sequence of tokens and the model may be accessible only through a black\-box interface, ordinary first\-order optimization with respect toccis unavailable\.

Prompt\-optimization methods such as MIPROv2 and GEPA\[[14](https://arxiv.org/html/2610.02687#bib.bib9),[1](https://arxiv.org/html/2610.02687#bib.bib10)\]approximate this problem by restricting the search to proposed candidates\. Let𝒫T⊂𝒞\\mathcal\{P\}\_\{T\}\\subset\\mathcal\{C\}denote the candidate pool considered within budgetTT\. Their shared abstraction is

c^T∈arg⁡minc∈𝒫T​L𝒟​\(c\)\.\\widehat\{c\}\_\{T\}\\in\\arg\\min\_\{c\\in\\mathcal\{P\}\_\{T\}\}L\_\{\\mathcal\{D\}\}\(c\)\.\(2\)The methods differ in how𝒫T\\mathcal\{P\}\_\{T\}is constructed and searched\. When abstracted to a single context variable, Equation \([2](https://arxiv.org/html/2610.02687#S2.E2)\) produces a task\-level context that is held fixed on the test set\. We give the more specific formulations in Appendix[A\.1](https://arxiv.org/html/2610.02687#A1.SS1)\.

A complementary family of methods uses model feedback to iteratively propose textual changes to the current context\. Lety^t=f⁡\(ct,xt\)\\widehat\{y\}\_\{t\}=f\(c\_\{t\},x\_\{t\}\), and letτt\\tau\_\{t\}contain the available feedback and execution trace\. We abstract such an update as

Δ​ct=𝒪⁡\(ct,xt,y^t,τt\),ct\+1=ct⊙Δ​ct,\\Delta c\_\{t\}=\\mathcal\{O\}\(c\_\{t\},x\_\{t\},\\widehat\{y\}\_\{t\},\\tau\_\{t\}\),\\qquad c\_\{t\+1\}=c\_\{t\}\\odot\\Delta c\_\{t\},\(3\)where𝒪\\mathcal\{O\}is a black\-box optimization oracle and⊙\\odotapplies the proposed addition, deletion, replacement, or edit\. Equation \([3](https://arxiv.org/html/2610.02687#S2.E3)\) is structurally analogous to a gradient\-descent step over the context:Δ​ct\\Delta c\_\{t\}plays the role of an update direction\. It is not a literal gradient, however, and it need not decrease Equation \([1](https://arxiv.org/html/2610.02687#S2.E1)\)\. Methods such as OPRO, TextGrad, and TRACE\[[5](https://arxiv.org/html/2610.02687#bib.bib15),[24](https://arxiv.org/html/2610.02687#bib.bib14),[22](https://arxiv.org/html/2610.02687#bib.bib13)\]differ primarily in how they construct the oracle𝒪\\mathcal\{O\}and the update\. We discuss these realizations in Appendix[A\.1](https://arxiv.org/html/2610.02687#A1.SS1)\.

### 2\.2From Local Context Updates to Memory

Directly asking an imperfect oracle to improve one global context over the entire dataset is difficult\. Memory systems instead extract a short context blockΔi\\Delta\_\{i\}from an individual experience\(xi,yi\)\(x\_\{i\},y\_\{i\}\)\. Writing the collection of context blocks asδ=\(Δ1,…,Δn\)\\delta=\(\\Delta\_\{1\},\\ldots,\\Delta\_\{n\}\), we define the context\-block risk as the local surrogate

L𝒟block​\(δ\)=1n​∑i=1n𝔼⁡\[ℓ⁡\(f⁡\(Δi,xi\),yi\)\]\.L^\{\\mathrm\{block\}\}\_\{\\mathcal\{D\}\}\(\\delta\)=\\frac\{1\}\{n\}\\sum\_\{i=1\}^\{n\}\\mathbb\{E\}\\left\[\\ell\\bigl\(f\(\\Delta\_\{i\},x\_\{i\}\),y\_\{i\}\\bigr\)\\right\]\.\(4\)This surrogate decomposes update generation into smaller problems: the oracle need only distill a focused lesson, for example, a strategy, correction, or failure mode, from one experience at a time\. The blocks collectively form an external memory bankδ\\delta, which serves as the evolving optimization state of the memory system\.

Optimizing Equation \([4](https://arxiv.org/html/2610.02687#S2.E4)\) is not claimed to be equivalent to optimizing the global objective in Equation \([1](https://arxiv.org/html/2610.02687#S2.E1)\)\. A block may overfit its source example and need not generalize in isolation\. The motivation for this surrogate is primarily practical\. First, it models the update procedure of a memory system\. Second, it makes the oracle’s task more local: proposing a focused updateΔi\\Delta\_\{i\}is a simpler generation task than proposing changes to improve performance over the entire dataset\. A separate composition or retrieval mechanism must determine which blocks should form the context for a new input; the local surrogate alone does not ensure generalization\. We expand on this distinction in Appendix[A\.2](https://arxiv.org/html/2610.02687#A1.SS2)\. Dynamic Cheatsheet and ACE instantiate this view by integrating locally extracted lessons into a shared natural\-language memory\[[17](https://arxiv.org/html/2610.02687#bib.bib11),[25](https://arxiv.org/html/2610.02687#bib.bib12)\]\. The blocks are integrated into one shared context, making accumulated lessons available across examples and producing a single task\-level memory for deployment\. The resulting memory must therefore serve new inputs rather than supply example\-indexed solutions\.

Under an append\-only abstraction, this context evolves as

cδ\(t\+1\)=cδ\(t\)⊕Δ\(t\),c\_\{\\delta\}^\{\(t\+1\)\}=c\_\{\\delta\}^\{\(t\)\}\\oplus\\Delta^\{\(t\)\},\(5\)
where⊕\\oplusappends the new block to the shared contextcδc\_\{\\delta\}\. This is an idealized regime: Dynamic Cheatsheet and ACE may edit, merge, or delete existing content rather than literally appending every update\. Nevertheless, these operations do not preclude systematic context growth\. In Figure[1](https://arxiv.org/html/2610.02687#S2.F1.fig1), we show that the measured growth of ACE’s prompt\-token usage is consistent with the growth trend predicted by the update regime in Equation \([5](https://arxiv.org/html/2610.02687#S2.E5)\) over the evaluated training horizon\.

###### Proposition 1\(Append\-only memory\-context growth\)\.

Suppose thatNNexamples produce at most one block each and thatlen⁡\(Δ\(t\)\)≤B\\operatorname\{len\}\(\\Delta^\{\(t\)\}\)\\leq B, whereBBis independent ofNN\. Under Equation \([5](https://arxiv.org/html/2610.02687#S2.E5)\), with a fixed initial context, the final memory\-context length satisfies

len⁡\(cδ\(N\)\)≤len⁡\(cδ\(0\)\)\+N​B=O⁡\(N\)\.\\operatorname\{len\}\\left\(c\_\{\\delta\}^\{\(N\)\}\\right\)\\leq\\operatorname\{len\}\\left\(c\_\{\\delta\}^\{\(0\)\}\\right\)\+NB=O\(N\)\.\(6\)

The proof follows by unrolling the induced length recurrence and is given in Appendix[A\.3](https://arxiv.org/html/2610.02687#A1.SS3)\.

This growth matters because the shared memory is not stored and read only once: it is repeatedly supplied to the model on subsequent examples\. The amount of memory processed per query therefore increases with the number of accumulated time\-steps \(lessons\)\. AcrossNNsequential updates, this can produce quadratic cumulative memory\-context exposure, even though the final context itself grows only linearly\. In practice, the expanding context also moves the system toward the model’s context\-window limit and mixes an increasingly heterogeneous collection of lessons, only a fraction of which may be relevant to the current input\. The corresponding cumulative bound is derived in Appendix[A\.3](https://arxiv.org/html/2610.02687#A1.SS3)\. The resulting efficiency problem is not that the stored memory grows; a continual learner should retain experience\. The problem is that full\-memory systems couple stored\-memory size to the amount of memory processed on every query\. This motivates a memory interface that allows the stored knowledge to continue growing while keeping the active context small\.

### 2\.3Memory with Bounded Retrieval

A more token\-efficient procedure introduces an interface that separates the accumulated memoryδ\\deltafrom the contextccexposed to the model:

δ\(t\+1\)=δ\(t\)∪\{Δ\(t\)\},cϕ\(t\+1\)​\(x\)=ϕ⁡\(δ\(t\+1\),x\),\\delta^\{\(t\+1\)\}=\\delta^\{\(t\)\}\\cup\\\{\\Delta^\{\(t\)\}\\\},\\qquad c\_\{\\phi\}^\{\(t\+1\)\}\(x\)=\\phi\\bigl\(\\delta^\{\(t\+1\)\},x\\bigr\),\(7\)whereϕ\\phiretrieves a query\-dependent subset of the accumulated blocks\. The oracle𝒪\\mathcal\{O\}determines what is learned from each experience, whileϕ\\phidetermines which learned information is exposed for a particular input\.

To this end, we introduce GraphMemory and modelδ\\deltaas a graphG\(t\)=\(V\(t\),E\(t\)\)G^\{\(t\)\}=\(V^\{\(t\)\},E^\{\(t\)\}\)\. Each node stores a reusable context blockΔ\\Delta, and weighted edges identify blocks that may be useful together\. The graph is a modeling choice for instantiatingϕ\\phithat supports selective retrieval and composition of related blocks\. Our framework also admits other representations: for example, each block inδ\\deltacould be embedded andϕ\\phiimplemented as a similarity\-based retriever\. In GraphMemory, for each query,ϕ\\phiselects entry nodes from a condensed index and expands through their neighborhoods under a fixed budget; only the retrieved subgraph is supplied to the modelff\. The complete graph update and its relation to full\-memory exposure are given in Appendix[A\.4](https://arxiv.org/html/2610.02687#A1.SS4); the concrete retrieval and update procedures are described in the following section\.

###### Proposition 2\(Bounded context under retrieval\)\.

Suppose each stored block contains at mostBBtokens andϕ\\phiretrieves at mostKKblocks, whereBBandKKare independent ofNN\. Then, for every queryxx, the retrieved memory context satisfies

len⁡\(cϕ\(N\)​\(x\)\)≤K​B=O⁡\(1\)\\operatorname\{len\}\\left\(c\_\{\\phi\}^\{\(N\)\}\(x\)\\right\)\\leq KB=O\(1\)\(8\)

The proof and cumulative memory\-context bound are given in Appendix[A\.3](https://arxiv.org/html/2610.02687#A1.SS3)\. Proposition[2](https://arxiv.org/html/2610.02687#Thmproposition2)concerns only the memory supplied to the Generator; it does not bound storage or the internal cost of retrieval\. Figure[1](https://arxiv.org/html/2610.02687#S2.F1.fig1)illustrates the different prompt\-token growth trends of ACE and GraphMemory over the evaluated training horizon\.

![Refer to caption](https://arxiv.org/html/2610.02687v1/diagrams/theoretical_vs_real_tokens.png)Figure 1:Prompt\-token usage at successive training checkpoints for GraphMemory and ACE onFormulawith Qwen3\.8\-27B\.

## 3GraphMemory

We use ACE as our workhorse for realizing GraphMemory\. GraphMemory changes ACE at precisely two interfaces: what the Generator \(ff\) reads and what the Curator \(𝒪\\mathcal\{O\}\) writes\. Instead of exposing the complete playbook to every query, we prepend a retrieval stage; instead of writing only bullet\-point updates, the Curator can also write relations between them\. The resulting adaptation loop isRetrieve–Generate–Reflect–Curate, as illustrated in Figure[2](https://arxiv.org/html/2610.02687#S4.F2)\. For retrieval, we maintain a compact index containing each node’s identifier and a short key, but not its full bullet\-point content\. Given a query, the Retriever reads this index and selects a small set of entry nodes\. We then perform a deterministic breadth\-first traversal from those entries, expanding neighbors in order of learned edge utility, under fixed hop, node, and token budgets\. Only the full contents of the nodes reached during this traversal are loaded and passed to the Generator\. The LLM therefore makes the initial semantic choice, while the graph provides a cheap and deterministic mechanism for bringing in connected knowledge\.

Generation follows ACE\. Reflection is extended in one respect: beyond ACE\-style critique, the Reflector labels the Generator’s reported memory transitions as helpful, harmful, or neutral\. Helpful and harmful labels contribute confidence\-weighted evidence to the corresponding edges, while neutral labels leave the counters unchanged\. The traversal utility is the mean of the resulting Beta posterior, so retrieval preferentially follows transitions with stronger helpful evidence\. The difference appears during curation: the Curator produces a graph update that may add or revise bullet\-point nodes, add or revise edges, or do both\. The update is applied locally without rewriting the rest of the graph\. New nodes are added to the compact index, while new edges determine which lessons can be reached together during later retrieval\. We provide the detailed construction of GraphMemory in Appendix[B](https://arxiv.org/html/2610.02687#A2)\. It is important to note that this realization is not strictlyO⁡\(1\)O\(1\)end to end because the Retriever still reads an index that grows with the number of nodes\. The bound in Proposition[2](https://arxiv.org/html/2610.02687#Thmproposition2)applies to the full memory content supplied to the Generator\. Since each index entry contains only an identifier and a short key, however, this residual growth is far smaller than repeatedly supplying every bullet in full\. Over the training horizon studied here, the resulting context grows slowly enough to exhibit the near\-constant behavior shown in Figure[1](https://arxiv.org/html/2610.02687#S2.F1.fig1)\.

## 4Experiments

Figure 2:Overview of GraphMemory\. An LLM retriever selects entry nodes from a compact index, after which a bounded breadth\-first traversal loads the relevant subgraph\. The ACE Generator and Reflector operate on this retrieved context, while the Curator writes new nodes and edges back to the graph\.Table 1:Offline adaptation performance, token usage, and estimated training cost onFormulaandFiNER\. Training\-token counts and costs are approximate\. Costs assume a 95%–5% input–output token split and standard real\-time API prices\. Initial accuracy denotes cold\-start test accuracy\.\*Standard input/output prices per million tokens: Claude Haiku 4\.5, $1\.00/$5\.00 \([Anthropic](https://platform.claude.com/docs/en/about-claude/pricing)\); Qwen3\.8\-27B, $0\.50/$3\.00 \([Alibaba Cloud Model Studio](https://www.alibabacloud.com/help/en/model-studio/model-pricing), International tier\)\. Qwen costs are API\-equivalent estimates; the experiments ran locally using a quantized model\.

![Refer to caption](https://arxiv.org/html/2610.02687v1/diagrams/finer_val_curve.png)

![Refer to caption](https://arxiv.org/html/2610.02687v1/diagrams/formula_val_curve.png)

Figure 3:Validation performance of GraphMemory and ACE on Claude across training steps onFiNER\(left\) andFormula\(right\)\.BaselinesWe compare GraphMemory against ACE\[[25](https://arxiv.org/html/2610.02687#bib.bib12)\]using two state\-of\-the\-art LLM backbones across two financial reasoning tasks\. For each backbone and task, we report cold\-start performance and final test performance after memory construction\. To assess adaptation efficiency, we track cumulative token consumption over the full training run and estimate the monetary cost of constructing each memory\.

ModelsWe evaluate GraphMemory and ACE using Claude Haiku 4\.5\[[2](https://arxiv.org/html/2610.02687#bib.bib18)\]through LiteLLM and a 4\-bit quantized Qwen3\.8\-27B\[[15](https://arxiv.org/html/2610.02687#bib.bib16)\]on an RTX 6000 GPU with 48 GB of memory\. For each configuration, we select the memory state that achieves the highest validation accuracy and report its performance on the held\-out test set\. In the Claude Haiku 4\.5 experiments, we cap the ACE memory at 80,000 tokens because its growth would otherwise exceed the model’s context\-window limit\. No such cap is required for Qwen3\.8\-27B, which supports a larger context window\. This highlights the importance of retrieval\-based memory: using ACE with smaller context windows may require a memory cap or other context\-management techniques\.

DatasetsBoth memory systems are evaluated on the two financial reasoning tasks:FiNER\[[12](https://arxiv.org/html/2610.02687#bib.bib19)\]andFormula\[[19](https://arxiv.org/html/2610.02687#bib.bib20)\]\. Each system is trained for a single epoch\. OurFormulasplit uses 500/300/200 training, validation, and test examples, respectively, while ourFiNERsplit uses 1,000/500/441 examples\. We evaluate validation performance every 100 training iterations\.

Adaptation performanceTables[1](https://arxiv.org/html/2610.02687#S4.T1)and[2](https://arxiv.org/html/2610.02687#S5.T2)summarize our findings\. Across three dataset–model configurations, GraphMemory reduces memory\-construction tokens by approximately8181–85%85\\%, estimated cost by a similar margin, and test tokens by78\.6%78\.6\\%–92\.2%92\.2\\%, while maintaining competitive accuracy\. OnFormulawith Qwen3\.8\-27B, it slightly outperforms ACE using only19%19\\%of its training\-token budget\. With Claude Haiku 4\.5, ACE leads by 4\.0 percentage points but uses6\.6×6\.6\\timesas many training tokens\. OnFiNER, GraphMemory trails ACE by 2\.94 points\. Figure[3](https://arxiv.org/html/2610.02687#S4.F3)shows that ACE improves rapidly before plateauing or declining as its memory approaches the 80k\-token cap\. GraphMemory improves more slowly and varies more initially, but continues improving as its graph grows, suggesting a trade\-off between early sample efficiency and late\-stage stability\.

Token and monetary efficiencyThe largest reduction occurs onFormulawith Claude Haiku 4\.5, where GraphMemory uses approximately 20M training tokens compared with 131M for ACE, an84\.7%84\.7\\%reduction\. Its test\-time token usage decreases from approximately 18M to 1\.4M, a92\.2%92\.2\\%reduction\. Comparable savings are observed with Qwen3\.8\-27B, for which GraphMemory reduces training\-token usage from 42M to 8M, and onFiNER, where usage falls from 327M to 57M\. Under our pricing assumptions, these reductions lower the estimated cost of memory construction from $157\.20 to $24\.00 on Claude/Formula, from $26\.25 to $5\.00 on Qwen/Formula, and from $392\.40 to $68\.40 on Claude/FiNER\.

Wall\-clock efficiencyAs shown in Table[2](https://arxiv.org/html/2610.02687#S5.T2), GraphMemory also reduces active training time\. Training time decreases by21\.0%21\.0\\%onFormula\(6\.4 versus 8\.1 hours\) and34\.3%34\.3\\%onFiNER\(19\.0 versus 28\.9 hours\)\. GraphMemory is slower during inference, however, requiring approximately 1\.8×\\timesas much time per test example\. This overhead arises because GraphMemory performs retrieval before generating each prediction, whereas ACE directly supplies its complete memory to the backbone\. A more efficient implementation ofϕ\\phi, such as an embedding\-based retriever, could reduce inference latency and further decrease training time\. We leave this investigation to future work\. Thus, GraphMemory trades a modest increase in per\-query latency for substantially lower context length, training cost, and test\-time token consumption\.

## 5Conclusion, Limitations, and Future Work

We cast agentic memory construction as iterative optimization over textual context, enabling a common analysis of flat and retrieval\-based memory\. We introduceGraphMemory, which organizes ACE\-style procedural knowledge as a graph and retrieves bounded, query\-relevant context\. Related memory systems include A\-MEM, which links episodic notes in a Zettelkasten\-inspired structure\[[21](https://arxiv.org/html/2610.02687#bib.bib23)\]; RIZZ, which organizes procedural rules into dynamic branches\[[7](https://arxiv.org/html/2610.02687#bib.bib24)\]; and HAGE, which learns graph traversal policies\[[9](https://arxiv.org/html/2610.02687#bib.bib25)\]\. GraphMemory learns relations between strategies from confidence\-weighted helpful and harmful feedback, supporting their composition without requiring predefined edge types or training a retrieval policy\. Our formulation shows how bounded retrieval changes memory\-context scaling from linear growth under append\-only prompting to a constant bound on retrieved content per query\. Across two financial tasks and two LLM backbones, GraphMemory remains competitive with ACE while reducing memory\-construction tokens by8181–85%85\\%, test\-time tokens by7979–92%92\\%, and estimated API cost similarly\. Learning trajectories suggest slower initial adaptation but greater stability and continued improvement\.

Our results remain preliminary, covering two related tasks, two models, and one primary baseline\. Broader evaluations, additional memory and prompt\-optimization baselines, and repeated runs are needed\. Retrieval overhead also makes individual test queries slower despite lower token usage, motivating embedding\-based and hybrid retrievers, caching, and improved graph routing\. Finally, longer continual\-learning streams and cross\-model transfer will test whether improvements persist beyond one epoch and whether memory built by larger models can efficiently adapt smaller ones\.

Table 2:Active wall\-clock time for offline training and held\-out test onFormulaandFiNER\. All figures are active wall clock\. Bold indicates the faster result\.
## References

- \[1\]L\. A\. Agrawal, S\. Tan, D\. Soylu, N\. Ziems, R\. Khare, K\. Opsahl\-Ong, A\. Singhvi, H\. Shandilya, M\. J\. Ryan, M\. Jiang, C\. Potts, K\. Sen, A\. G\. Dimakis, I\. Stoica, D\. Klein, M\. Zaharia, and O\. Khattab\(2026\)GEPA: reflective prompt evolution can outperform reinforcement learning\.External Links:2507\.19457,[Link](https://arxiv.org/abs/2507.19457)Cited by:[§A\.1](https://arxiv.org/html/2610.02687#A1.SS1.p2.2),[§1](https://arxiv.org/html/2610.02687#S1.p2.1),[§2\.1](https://arxiv.org/html/2610.02687#S2.SS1.p2.1)\.
- \[2\]Anthropic\(2025\)Claude Haiku 4\.5 System Card\.Technical reportAnthropic\.External Links:[Link](https://www.anthropic.com/claude-haiku-4-5-system-card)Cited by:[§4](https://arxiv.org/html/2610.02687#S4.p2.1)\.
- \[3\]T\. Brown, B\. Mann, N\. Ryder, M\. Subbiah, J\. D\. Kaplan, P\. Dhariwal, A\. Neelakantan, P\. Shyam, G\. Sastry, A\. Askell,et al\.\(2020\)Language models are few\-shot learners\.Advances in neural information processing systems33,pp\. 1877–1901\.Cited by:[§1](https://arxiv.org/html/2610.02687#S1.p2.1)\.
- \[4\]R\. Charakorn, E\. Cetin, S\. Uesaka, and R\. T\. Lange\(2026\)Doc\-to\-lora: learning to instantly internalize contexts\.External Links:2602\.15902,[Link](https://arxiv.org/abs/2602.15902)Cited by:[§1](https://arxiv.org/html/2610.02687#S1.p1.1)\.
- \[5\]C\. Cheng, A\. Nie, and A\. Swaminathan\(2024\)Trace is the next autodiff: generative optimization with rich feedback, execution traces, and llms\.Advances in Neural Information Processing Systems37,pp\. 71596–71642\.Cited by:[§A\.1](https://arxiv.org/html/2610.02687#A1.SS1.p3.1),[§2\.1](https://arxiv.org/html/2610.02687#S2.SS1.p3.2)\.
- \[6\]C\. Dun, M\. H\. Garcia, G\. Zheng, A\. H\. Awadallah, A\. Kyrillidis, and R\. Sim\(2025\)Sweeping heterogeneity with smart mops: mixture of prompts for llm task adaptation\.External Links:2310\.02842,[Link](https://arxiv.org/abs/2310.02842)Cited by:[§1](https://arxiv.org/html/2610.02687#S1.p1.1)\.
- \[7\]S\. Goel, P\. Vaidhyanathan, L\. Schorling, N\. Ares, and M\. Osborne\(2026\)RIZZ: routing interactions to near zero\-interference zones for continual adaptation of black\-box agents\.arXiv preprint arXiv:2606\.20638\.Cited by:[§5](https://arxiv.org/html/2610.02687#S5.p1.1)\.
- \[8\]E\. J\. Hu, Y\. Shen, P\. Wallis, Z\. Allen\-Zhu, Y\. Li, S\. Wang, L\. Wang, and W\. Chen\(2021\)Lora: low\-rank adaptation of large language models\.arXiv preprint arXiv:2106\.09685\.Cited by:[§1](https://arxiv.org/html/2610.02687#S1.p1.1)\.
- \[9\]D\. Jiang, Y\. Li, G\. Li, Q\. Li, and B\. Li\(2026\)Hage: harnessing agentic memory via rl\-driven weighted graph evolution\.arXiv preprint arXiv:2605\.09942\.Cited by:[§5](https://arxiv.org/html/2610.02687#S5.p1.1)\.
- \[10\]O\. Khattab, A\. Singhvi, P\. Maheshwari, Z\. Zhang, K\. Santhanam, S\. Vardhamanan, S\. Haq, A\. Sharma, T\. T\. Joshi, H\. Moazam, H\. Miller, M\. Zaharia, and C\. Potts\(2023\)DSPy: compiling declarative language model calls into self\-improving pipelines\.External Links:2310\.03714,[Link](https://arxiv.org/abs/2310.03714)Cited by:[§1](https://arxiv.org/html/2610.02687#S1.p2.1)\.
- \[11\]X\. L\. Li and P\. Liang\(2021\)Prefix\-tuning: optimizing continuous prompts for generation\.InProceedings of the 59th annual meeting of the association for computational linguistics and the 11th international joint conference on natural language processing \(volume 1: Long papers\),pp\. 4582–4597\.Cited by:[§1](https://arxiv.org/html/2610.02687#S1.p1.1)\.
- \[12\]L\. Loukas, M\. Fergadiotis, I\. Chalkidis, E\. Spyropoulou, P\. Malakasiotis, I\. Androutsopoulos, and G\. Paliouras\(2022\)FiNER: financial numeric entity recognition for xbrl tagging\.InProceedings of the 60th Annual Meeting of the Association for Computational Linguistics \(Volume 1: Long Papers\),pp\. 4419–4431\.Cited by:[§4](https://arxiv.org/html/2610.02687#S4.p3.1)\.
- \[13\]J\. Ni, Y\. Liu, X\. Liu, Y\. Sun, M\. Zhou, P\. Cheng, D\. Wang, E\. Zhao, X\. Jiang, and G\. Jiang\(2026\)Trace2skill: distill trajectory\-local lessons into transferable agent skills\.arXiv preprint arXiv:2603\.25158\.Cited by:[§1](https://arxiv.org/html/2610.02687#S1.p2.1)\.
- \[14\]K\. Opsahl\-Ong, M\. J\. Ryan, J\. Purtell, D\. Broman, C\. Potts, M\. Zaharia, and O\. Khattab\(2024\)Optimizing instructions and demonstrations for multi\-stage language model programs\.External Links:2406\.11695,[Link](https://arxiv.org/abs/2406.11695)Cited by:[§A\.1](https://arxiv.org/html/2610.02687#A1.SS1.p1.2),[§1](https://arxiv.org/html/2610.02687#S1.p2.1),[§2\.1](https://arxiv.org/html/2610.02687#S2.SS1.p2.1)\.
- \[15\]Qwen Team\(2026\)Qwen3\.8\-Max: a new bar for coding and cowork\.External Links:[Link](https://qwen.ai/blog?id=qwen3.8)Cited by:[§4](https://arxiv.org/html/2610.02687#S4.p2.1)\.
- \[16\]K\. Ramji, T\. Naseem, and R\. Astudillo\(2026\)Latent principle discovery for language model self\-improvement\.Advances in Neural Information Processing Systems38,pp\. 162283–162336\.Cited by:[§1](https://arxiv.org/html/2610.02687#S1.p2.1)\.
- \[17\]M\. Suzgun, M\. Yuksekgonul, F\. Bianchi, D\. Jurafsky, and J\. Zou\(2025\)Dynamic cheatsheet: test\-time learning with adaptive memory\.External Links:2504\.07952,[Link](https://arxiv.org/abs/2504.07952)Cited by:[§1](https://arxiv.org/html/2610.02687#S1.p2.1),[§2\.2](https://arxiv.org/html/2610.02687#S2.SS2.p2.1)\.
- \[18\]L\. Tang, C\. Rashtchian, C\. Ferng, A\. Tomkins, D\. Juan, and T\. Vu\(2026\)WikiSkill: compiling agent experience into persistent knowledge for skill evolution\.arXiv preprint arXiv:2608\.27454\.Cited by:[§1](https://arxiv.org/html/2610.02687#S1.p2.1)\.
- \[19\]D\. Wang, J\. Patel, D\. Zha, S\. Y\. Yang, and X\. Liu\(2025\)Finlora: benchmarking lora methods for fine\-tuning llms on financial datasets\.arXiv preprint arXiv:2505\.19819\.Cited by:[§4](https://arxiv.org/html/2610.02687#S4.p3.1)\.
- \[20\]Z\. Xi, W\. Chen, X\. Guo, W\. He, Y\. Ding, B\. Hong, M\. Zhang, J\. Wang, S\. Jin, E\. Zhou,et al\.\(2025\)The rise and potential of large language model based agents: a survey\.Science China information sciences68\(2\),pp\. 121101\.Cited by:[§1](https://arxiv.org/html/2610.02687#S1.p1.1)\.
- \[21\]W\. Xu, Z\. Liang, K\. Mei, H\. Gao, J\. Tan, and Y\. Zhang\(2026\)A\-mem: agentic memory for llm agents\.Advances in Neural Information Processing Systems38,pp\. 17577–17604\.Cited by:[§5](https://arxiv.org/html/2610.02687#S5.p1.1)\.
- \[22\]C\. Yang, X\. Wang, Y\. Lu, H\. Liu, Q\. V\. Le, D\. Zhou, and X\. Chen\(2024\)Large language models as optimizers\.InInternational Conference on Learning Representations,Vol\.2024,pp\. 12028–12068\.Cited by:[§A\.1](https://arxiv.org/html/2610.02687#A1.SS1.p3.1),[§2\.1](https://arxiv.org/html/2610.02687#S2.SS1.p3.2)\.
- \[23\]C\. Yang, X\. Wang, Y\. Lu, H\. Liu, Q\. V\. Le, D\. Zhou, and X\. Chen\(2024\)Large language models as optimizers\.External Links:2309\.03409,[Link](https://arxiv.org/abs/2309.03409)Cited by:[§1](https://arxiv.org/html/2610.02687#S1.p2.1)\.
- \[24\]M\. Yuksekgonul, F\. Bianchi, J\. Boen, S\. Liu, Z\. Huang, C\. Guestrin, and J\. Zou\(2024\)Textgrad: automatic" differentiation" via text\.arXiv preprint arXiv:2406\.07496\.Cited by:[§A\.1](https://arxiv.org/html/2610.02687#A1.SS1.p3.1),[§2\.1](https://arxiv.org/html/2610.02687#S2.SS1.p3.2)\.
- \[25\]Q\. Zhang, C\. Hu, S\. Upasani, B\. Ma, F\. Hong, V\. Kamanuru, J\. Rainton, C\. Wu, M\. Ji, H\. Li, U\. Thakker, J\. Zou, and K\. Olukotun\(2026\)Agentic context engineering: evolving contexts for self\-improving language models\.External Links:2510\.04618,[Link](https://arxiv.org/abs/2510.04618)Cited by:[§1](https://arxiv.org/html/2610.02687#S1.p2.1),[§2\.2](https://arxiv.org/html/2610.02687#S2.SS2.p2.1),[§4](https://arxiv.org/html/2610.02687#S4.p1.1)\.

## Appendix AAdditional Formalization

### A\.1Textual Optimization Oracles

Equation \([2](https://arxiv.org/html/2610.02687#S2.E2)\) suppresses how the candidate pool is constructed\. MIPROv2 searches over candidate instructions and demonstrations for each program module\. Ifℐj\\mathcal\{I\}\_\{j\}andℰj\\mathcal\{E\}\_\{j\}denote the instruction and demonstration candidates for modulejj, respectively, its search space can be abstracted as

𝒵=∏j=1m\(ℐj×ℰj\),z^T∈arg⁡minz∈𝒵T​L𝒟​\(c⁡\(z\)\),\\mathcal\{Z\}=\\prod\_\{j=1\}^\{m\}\\bigl\(\\mathcal\{I\}\_\{j\}\\times\\mathcal\{E\}\_\{j\}\\bigr\),\\qquad\\widehat\{z\}\_\{T\}\\in\\arg\\min\_\{z\\in\\mathcal\{Z\}\_\{T\}\}L\_\{\\mathcal\{D\}\}\\bigl\(c\(z\)\\bigr\),\(9\)where𝒵T⊆𝒵\\mathcal\{Z\}\_\{T\}\\subseteq\\mathcal\{Z\}contains the configurations evaluated within budgetTT, andc⁡\(z\)c\(z\)denotes their induced context\[[14](https://arxiv.org/html/2610.02687#bib.bib9)\]\.

GEPA constructs its candidate set adaptively rather than drawing it from a fully specified product space\. Starting from an archive𝒜0\\mathcal\{A\}\_\{0\}, it uses execution traces and feedback to reflect on selected candidates and add new proposals:

𝒜t\+1=𝒜t∪Propose⁡\(ct,τt\),c^T∈arg⁡minc∈𝒜T​L𝒟​\(c\)\.\\mathcal\{A\}\_\{t\+1\}=\\mathcal\{A\}\_\{t\}\\cup\\operatorname\{Propose\}\(c\_\{t\},\\tau\_\{t\}\),\\qquad\\widehat\{c\}\_\{T\}\\in\\arg\\min\_\{c\\in\\mathcal\{A\}\_\{T\}\}L\_\{\\mathcal\{D\}\}\(c\)\.\(10\)HerePropose\\operatorname\{Propose\}abstracts GEPA’s reflective mutation and candidate combination operations\[[1](https://arxiv.org/html/2610.02687#bib.bib10)\]\. Thus,𝒫T\\mathcal\{P\}\_\{T\}in Equation \([2](https://arxiv.org/html/2610.02687#S2.E2)\) may be either a searched subset of a larger predefined space, as in MIPROv2, or an archive grown during optimization, as in GEPA\. In both cases, we abstract the resulting optimized program or prompt as a contextccthat is fixed during test\-time inference\.

A second family uses Equation \([3](https://arxiv.org/html/2610.02687#S2.E3)\) to propose textual changes iteratively\. OPRO conditions the optimizer on previously proposed contexts and their scores\. TextGrad generates textual feedback and propagates it through the computation that produced the output\. TRACE uses output feedback together with execution traces to localize the part of the context to be modified\[[22](https://arxiv.org/html/2610.02687#bib.bib13),[24](https://arxiv.org/html/2610.02687#bib.bib14),[5](https://arxiv.org/html/2610.02687#bib.bib15)\]\. When restricted to context optimization, these methods can be viewed as different realizations of𝒪\\mathcal\{O\}\. The gradient\-descent analogy concerns the shared update structure, not differentiability or a convergence guarantee\. In particular,Δ​ct\\Delta c\_\{t\}is only a proposed direction unless an evaluation or acceptance step verifies that it reduces the objective\.

### A\.2Why Use a Local Context\-Block Surrogate?

Allowing a separateΔi\\Delta\_\{i\}for each example enlarges the search space and can produce a maximally biased solution: an unconstrained block could simply encode the answer to its source input\. Equation \([4](https://arxiv.org/html/2610.02687#S2.E4)\) is therefore not a reformulation with the same minimizer as Equation \([1](https://arxiv.org/html/2610.02687#S2.E1)\)\. It is a surrogate for constructing the elements of a reusable memory\.

The motivation is the asymmetry between classical optimization and textual optimization\. If a reliable descent direction for the global context were available, decomposing the problem into per\-example variables would offer little benefit and would create an obvious generalization problem\. In the black\-box setting, however, the update direction must itself be produced by an imperfect model\-based oracle\. Asking that oracle to extract one short lesson from one observed success or failure is a more localized generation task than asking it to rewrite a growing global context to improve average performance over all examples\.

Generalization is delegated to the memory interface\. Given a memory bankδ\\delta, a composer or retriever constructscϕ​\(x\)=ϕ⁡\(δ,x\)c\_\{\\phi\}\(x\)=\\phi\(\\delta,x\)for a new input\. A block is useful only when it encodes reusable information andϕ\\phiexposes it on inputs for which that information is relevant\. This is why context\-block quality cannot be judged only by Equation \([4](https://arxiv.org/html/2610.02687#S2.E4)\); final validation and test risk must still be measured using the composed or retrieved contexts, as in Equation \([16](https://arxiv.org/html/2610.02687#A1.E16)\) for GraphMemory\.

### A\.3Memory\-Context Scaling

LetL0=len⁡\(cδ\(0\)\)L\_\{0\}=\\operatorname\{len\}\(c\_\{\\delta\}^\{\(0\)\}\)andbi=len⁡\(Δi\)b\_\{i\}=\\operatorname\{len\}\(\\Delta\_\{i\}\)\. Under the append\-only update in Equation \([5](https://arxiv.org/html/2610.02687#S2.E5)\),

len⁡\(cδ\(i\)\)\\displaystyle\\operatorname\{len\}\\left\(c\_\{\\delta\}^\{\(i\)\}\\right\)=len⁡\(cδ\(i−1\)\)\+bi,\\displaystyle=\\operatorname\{len\}\\left\(c\_\{\\delta\}^\{\(i\-1\)\}\\right\)\+b\_\{i\},\(11\)len⁡\(cδ\(N\)\)\\displaystyle\\operatorname\{len\}\\left\(c\_\{\\delta\}^\{\(N\)\}\\right\)=L0\+∑i=1Nbi≤L0\+N​B=O⁡\(N\)\.\\displaystyle=L\_\{0\}\+\\sum\_\{i=1\}^\{N\}b\_\{i\}\\leq L\_\{0\}\+NB=O\(N\)\.If the blocks have positive average length bounded away from zero, the final memory\-context length isΘ⁡\(N\)\\Theta\(N\)\.

The cumulative number of memory\-context tokens exposed across theNNupdates obeys

∑i=1Nlen⁡\(cδ\(i\)\)\\displaystyle\\sum\_\{i=1\}^\{N\}\\operatorname\{len\}\\left\(c\_\{\\delta\}^\{\(i\)\}\\right\)=N​L0\+∑j=1N\(N−j\+1\)​bj\\displaystyle=NL\_\{0\}\+\\sum\_\{j=1\}^\{N\}\(N\-j\+1\)b\_\{j\}\(12\)≤N​L0\+B​N​\(N\+1\)2=O⁡\(N2\)\.\\displaystyle\\leq NL\_\{0\}\+\\frac\{BN\(N\+1\)\}\{2\}=O\(N^\{2\}\)\.This is a bound on memory tokens supplied to the model, not on all prompt and completion tokens used by the complete system\.

For retrieval\-based memory, each context is constructed afresh and does not contain the context retrieved for the preceding example\. Iflen⁡\(Δi\)≤B\\operatorname\{len\}\(\\Delta\_\{i\}\)\\leq Band at mostKKblocks are retrieved, then for everyii,

len⁡\(cϕ\(i\)​\(xi\)\)≤K​B=O⁡\(1\),∑i=1Nlen⁡\(cϕ\(i\)​\(xi\)\)≤N​K​B=O⁡\(N\)\.\\operatorname\{len\}\\left\(c\_\{\\phi\}^\{\(i\)\}\(x\_\{i\}\)\\right\)\\leq KB=O\(1\),\\qquad\\sum\_\{i=1\}^\{N\}\\operatorname\{len\}\\left\(c\_\{\\phi\}^\{\(i\)\}\(x\_\{i\}\)\\right\)\\leq NKB=O\(N\)\.\(13\)Consequently, the per\-query memory context isO⁡\(1\)O\(1\)\. AcrossNNexamples, the cumulative memory\-context exposure isO⁡\(N\)O\(N\)\. These bounds exclude the stored graph, condensed index, and any context consumed internally byϕ\\phi\.

### A\.4GraphMemory as Structured Retrieval

At steptt, GraphMemory stores the blocks inG\(t\)=\(V\(t\),E\(t\)\)G^\{\(t\)\}=\(V^\{\(t\)\},E^\{\(t\)\}\)\. A new nodev\(t\)v^\{\(t\)\}storesΔ\(t\)\\Delta^\{\(t\)\}, whileR\(t\)R^\{\(t\)\}contains the relations introduced or updated for that node\. Under the same append\-only simplification as Equation \([5](https://arxiv.org/html/2610.02687#S2.E5)\),

V\(t\+1\)=V\(t\)∪\{v\(t\)\},E\(t\+1\)=E\(t\)∪R\(t\)\.V^\{\(t\+1\)\}=V^\{\(t\)\}\\cup\\\{v^\{\(t\)\}\\\},\\qquad E^\{\(t\+1\)\}=E^\{\(t\)\}\\cup R^\{\(t\)\}\.\(14\)The implementation may additionally edit or merge nodes and revise edge scores; those operations do not alter the retrieval interface below\.

For an inputxx, the retriever selects a query\-dependent subset of nodes and serializes their blocks:

S\(t\)​\(x\)\\displaystyle S^\{\(t\)\}\(x\)=ϕ⁡\(G\(t\),x\)⊆V\(t\),\\displaystyle=\\phi\\bigl\(G^\{\(t\)\},x\\bigr\)\\subseteq V^\{\(t\)\},\(15\)cG\(t\)​\(x\)\\displaystyle c\_\{G\}^\{\(t\)\}\(x\)=⨁vj∈S\(t\)​\(x\)Δj\.\\displaystyle=\\bigoplus\_\{v\_\{j\}\\in S^\{\(t\)\}\(x\)\}\\Delta\_\{j\}\.For fixedϕ\\phi, the empirical risk of the graph\-induced contexts is

L𝒟graph​\(G\(t\)\)=1n​∑i=1n𝔼⁡\[ℓ⁡\(f⁡\(cG\(t\)​\(xi\),xi\),yi\)\]\.L\_\{\\mathcal\{D\}\}^\{\\mathrm\{graph\}\}\\bigl\(G^\{\(t\)\}\\bigr\)=\\frac\{1\}\{n\}\\sum\_\{i=1\}^\{n\}\\mathbb\{E\}\\left\[\\ell\\bigl\(f\(c\_\{G\}^\{\(t\)\}\(x\_\{i\}\),x\_\{i\}\),y\_\{i\}\\bigr\)\\right\]\.\(16\)GraphMemory constructsG\(0\),G\(1\),…G^\{\(0\)\},G^\{\(1\)\},\\ldotswith the aim of reducing this risk\. At the level of memory exposure, supplying the full memory is recovered as the special caseS\(t\)​\(x\)=V\(t\)S^\{\(t\)\}\(x\)=V^\{\(t\)\}for everyxx\. GraphMemory instead uses a bounded, query\-dependent set, so a specialized block affects only the inputs for which it is retrieved\.

## Appendix BImplementation Details

### B\.1Directed Evidence\-Weighted Memory Graph

GraphMemory maintains a directed graphG\(t\)=\(V\(t\),E\(t\)\)G^\{\(t\)\}=\(V^\{\(t\)\},E^\{\(t\)\}\)\. Each node stores a unique identifier, a short routing key, and the full ACE\-style bullet point used as context\. The routing index contains only the identifier and short key; full bullet\-point content is loaded only after graph retrieval\. A directed edgee=\(u,v\)e=\(u,v\)records that the knowledge in nodevvmay be useful after nodeuuhas been retrieved\. The implementation does not store a single mutable weight\. Instead, each directed edge stores two nonnegative, confidence\-weighted evidence counters:Se\(t\)S\_\{e\}^\{\(t\)\}for helpful transitions andFe\(t\)F\_\{e\}^\{\(t\)\}for harmful transitions\. If edgeeeis created at stepτe\\tau\_\{e\}, its counters are initialized as

Se\(τe\)=Fe\(τe\)=0\.S\_\{e\}^\{\(\\tau\_\{e\}\)\}=F\_\{e\}^\{\(\\tau\_\{e\}\)\}=0\.\(17\)We treat these counters as fractional pseudo\-counts under a uniformBeta⁡\(1,1\)\\operatorname\{Beta\}\(1,1\)prior\. Under this fractional\-observation interpretation, the edge parameter is

θe\|ℋt∼Beta⁡\(1\+Se\(t\),1\+Fe\(t\)\),\\theta\_\{e\}\\mid\\mathcal\{H\}\_\{t\}\\sim\\operatorname\{Beta\}\\\!\\left\(1\+S\_\{e\}^\{\(t\)\},\\,1\+F\_\{e\}^\{\(t\)\}\\right\),\(18\)whereℋt\\mathcal\{H\}\_\{t\}is the evidence accumulated through steptt\. The value used to rank the edge during retrieval is the posterior mean

we\(t\)=𝔼⁡\[θe∣ℋt\]=Se\(t\)\+1Se\(t\)\+Fe\(t\)\+2\.w\_\{e\}^\{\(t\)\}=\\mathbb\{E\}\[\\theta\_\{e\}\\mid\\mathcal\{H\}\_\{t\}\]=\\frac\{S\_\{e\}^\{\(t\)\}\+1\}\{S\_\{e\}^\{\(t\)\}\+F\_\{e\}^\{\(t\)\}\+2\}\.\(19\)Thus, a new edge has neutral weightwe\(τe\)=1/2w\_\{e\}^\{\(\\tau\_\{e\}\)\}=1/2even though no explicit weight field is stored\. Because the graph is directed,\(u,v\)\(u,v\)and\(v,u\)\(v,u\)have separate counters and can receive different retrieval weights\.

After generation, the Generator reports an ordered influence traceMt=\[n1,…,nk\]M\_\{t\}=\[n\_\{1\},\\ldots,n\_\{k\}\]containing the loaded memory nodes that it attributes as influential to its answer\. Only identifiers among the nodes loaded for that example are accepted\. Adjacent items define candidate directed transitions,

𝒯⁡\(Mt\)=\{\(n1,n2\),\(n2,n3\),…,\(nk−1,nk\)\}\.\\mathcal\{T\}\(M\_\{t\}\)=\\\{\(n\_\{1\},n\_\{2\}\),\(n\_\{2\},n\_\{3\}\),\\ldots,\(n\_\{k\-1\},n\_\{k\}\)\\\}\.\(20\)The Reflector labels each candidate as helpful, harmful, or neutral and returns an evidence strengthce\(t\)∈\[0,1\]c\_\{e\}^\{\(t\)\}\\in\[0,1\]\. For an existing edgeee, the evidence update is

\(Se\(t\+1\),Fe\(t\+1\)\)=\{\(Se\(t\)\+ce\(t\),Fe\(t\)\),ifeis helpful,\(Se\(t\),Fe\(t\)\+ce\(t\)\),ifeis harmful,\(Se\(t\),Fe\(t\)\),ifeis neutral\.\\left\(S\_\{e\}^\{\(t\+1\)\},F\_\{e\}^\{\(t\+1\)\}\\right\)=\\begin\{cases\}\\left\(S\_\{e\}^\{\(t\)\}\+c\_\{e\}^\{\(t\)\},F\_\{e\}^\{\(t\)\}\\right\),&\\text\{if $e$ is helpful\},\\\\ \\left\(S\_\{e\}^\{\(t\)\},F\_\{e\}^\{\(t\)\}\+c\_\{e\}^\{\(t\)\}\\right\),&\\text\{if $e$ is harmful\},\\\\ \\left\(S\_\{e\}^\{\(t\)\},F\_\{e\}^\{\(t\)\}\\right\),&\\text\{if $e$ is neutral\}\.\\end\{cases\}\(21\)The confidence value therefore controls the fractional amount of evidence contributed by one observation; neutral feedback andce\(t\)=0c\_\{e\}^\{\(t\)\}=0leave both counters unchanged, as do edges that were not observed on the example\. Hallucinated or unloaded node identifiers, duplicate pairs, invalid labels, and confidences outside\[0,1\]\[0,1\]are discarded before this update, so each unique transition is updated at most once per example\. Observing a transition does not implicitly create an edge: new edges can be introduced only by validated Curator operations, with both counters initialized to zero\. The Curator may likewise issue a separate validated edge\-removal operation when a relation should no longer be retained; deletion is not an automatic consequence of Equation \([19](https://arxiv.org/html/2610.02687#A2.E19)\)\. Node additions and revisions are also local, and new nodes are inserted into the routing index without rewriting the remainder of the graph\.

The retrieval weight is a smoothed estimate of how often the Reflector has judged an observed directed transition helpful under the current retrieval policy\. It should not be interpreted as a causal measure of interaction between two nodes or as a calibrated probability that retrieving the edge will improve accuracy\. Evidence is policy\-dependent because highly ranked edges are more likely to be observed again, and ranking by the posterior mean does not explicitly reward uncertainty\. These limitations are important when interpreting the learned graph\.

### B\.2Retrieval and Traversal

Retrieval has two stages\. First, an LLM Retriever reads the compact index and returns a structured selection of up to two index sections and at most six entry nodes\. Second, GraphMemory performs a weight\-prioritized breadth\-first traversal over outgoing edges\. Entry nodes have depth zero\. At each breadth level, active outgoing neighbors are ordered by decreasing posterior\-mean weight from Equation \([19](https://arxiv.org/html/2610.02687#A2.E19)\), with target\-node identifier used as a deterministic tie\-break, and at most the two highest\-scoring neighbors of a loaded node are considered\. Traversal is bounded by two hops from each entry node, at most 12 loaded nodes, and at most 2,500 tokens of serialized node content\. A node is not loaded if doing so would violate either the node or token budget\.

Algorithm[1](https://arxiv.org/html/2610.02687#alg1)gives the retrieval procedure\. The queue preserves breadth\-first depth order, while edge scores determine the priority among neighbors at the same expansion point\. Duplicate nodes reached from different entries are loaded only once\.

Algorithm 1Bounded posterior\-mean\-prioritized retrieval in GraphMemory0:Query

xx, directed graph

G=\(V,E\)G=\(V,E\), compact index

I⁡\(G\)I\(G\)
1:

A←LLMSelect⁡\(I⁡\(G\),x\)A\\leftarrow\\operatorname\{LLMSelect\}\(I\(G\),x\)\{at most 2 sections and 6 valid entry nodes\}

2:

Q←\[\(v,0\):v∈A\]Q\\leftarrow\[\(v,0\):v\\in A\],

L←\[\]L\\leftarrow\[\\,\],

Z←∅Z\\leftarrow\\varnothing
3:while

Q≠∅Q\\neq\\varnothingand

\|L\|<12\|L\|<12do

4:

\(v,d\)←popFront⁡\(Q\)\(v,d\)\\leftarrow\\operatorname\{popFront\}\(Q\)
5:if

v∉Zv\\notin Zthen

6:

Z←Z∪\{v\}Z\\leftarrow Z\\cup\\\{v\\\}
7:if

len⁡\(Ser⁡\(L∥\[v\]\)\)≤2500\\operatorname\{len\}\(\\operatorname\{Ser\}\(L\\mathbin\{\\\|\}\[v\]\)\)\\leq 2500then

8:append

vvto

LL
9:if

d<2d<2then

10:

Nv←Top2u:\(v,u\)∈Ew\(v,u\)N\_\{v\}\\leftarrow\\operatorname\{Top2\}\_\{u:\(v,u\)\\in E\}w\_\{\(v,u\)\}
11:append

\[\(u,d\+1\):u∈Nv\]\[\(u,d\+1\):u\\in N\_\{v\}\]to

QQ
12:endif

13:endif

14:endif

15:endwhile

16:return

Ser⁡\(L\)\\operatorname\{Ser\}\(L\)

The Retriever uses structured JSON output\. Invalid identifiers are discarded\. We use no full\-memory fallback: if the graph is empty or no valid entry node is selected, the retrieved memory is empty and generation proceeds without a memory block\. This choice prevents retrieval failures from silently reverting to the full\-playbook exposure that GraphMemory is designed to avoid\.

For each retrieval, the implementation records the selected section and entry identifiers, loaded node identifiers, considered and traversed edges, loaded memory tokens, maximum hop depth, traversal time, and whether a fallback was used\. These traces both support token and latency accounting and restrict relation updates to content that was actually available during generation\.

### B\.3Retrieve–Generate–Reflect–Curate Execution Order

For training example\(xt,yt\)\(x\_\{t\},y\_\{t\}\), GraphMemory first retrieves from the graph constructed from earlier examples,

ct=ϕ⁡\(G\(t\),xt\),y^t=f⁡\(ct,xt\)\.c\_\{t\}=\\phi\(G^\{\(t\)\},x\_\{t\}\),\\qquad\\widehat\{y\}\_\{t\}=f\(c\_\{t\},x\_\{t\}\)\.\(22\)Only after producingy^t\\widehat\{y\}\_\{t\}does the Reflector inspect the prediction, available feedback, and execution trace\. The Curator then emits local graph edits, which are applied to obtainG\(t\+1\)G^\{\(t\+1\)\}\. Consequently, information derived fromyty\_\{t\}cannot affect the prediction onxtx\_\{t\}; it becomes available only to subsequent examples\. The Generator and Reflector retain ACE’s core roles, with the additional memory\-use tracing and edge feedback described above, while the Retriever and graph\-valued Curator implement the two GraphMemory\-specific interfaces described in Section[3](https://arxiv.org/html/2610.02687#S3)\.

### B\.4Model and Evaluation Configuration

For the Qwen3\.8\-27B experiments, the model is loaded through Hugging Face\. We retain the checkpoint configuration except for three explicit runtime choices: 4\-bit quantization, scaled dot\-product attention \(SDPA\), and disabled thinking mode\. Disabling thinking prevents unnecessarily long reasoning outputs\. These model and inference settings are identical for ACE and GraphMemory\. For the Claude Haiku 4\.5 experiments, all model calls are made through LiteLLM using its default request configuration\. Within each dataset–backbone comparison, ACE and GraphMemory use the same backbone and model configuration; the method\-specific difference is the memory interface rather than the underlying language model\.

Each system processes the training split for one epoch, and the then\-current memory is evaluated on the validation split every 100 updates\. The checkpoint with the highest validation accuracy is selected for the held\-out test evaluation\. In the Claude experiments, ACE uses the 80,000\-token memory cap reported in the main text\. Formula uses 500/300/200 train/validation/test examples, and FiNER uses 1,000/500/441 examples\.

### B\.5Token and Latency Accounting

The bounded\-retrieval result in Proposition[2](https://arxiv.org/html/2610.02687#Thmproposition2)applies to the serialized node content supplied to the Generator\. It does not include the compact index read by the Retriever\. Because the present Retriever reads the complete index, its input grows with the number of indexed nodes\. Total system usage includes the Retriever’s index, retrieved node content, fixed instructions and query tokens, and the remaining input and output tokens from the Retriever, Generator, Reflector, and Curator\. Only the retrieved node content supplied to the Generator is covered by the constant retrieved\-content bound\. The wall\-clock measurements include the additional retrieval call made by GraphMemory, which explains why GraphMemory can use fewer tokens while having higher per\-query latency\.

相似文章