Manuscript Offprint

arXiv:2609.37930

Learning What to Remember: Long-horizon Counterfactual Memory Optimization

Jiaming Tang, Mingyan Liu, Armin Sarabi

ABSTRACT

Persistent textual memory allows language models to carry information across long interactions, but learning what to remember is fundamentally a credit-assignment problem. A memory rewrite may only become useful many steps later, while much of the observed utility may be inherited from information already stored before the rewrite. We introduce Memory Gain Policy Optimization (MGPO), which isolates the incremental value of each memory rewrite by crediting it for its marginal contribution to current and future downstream utility. This turns delayed memory utility into a direct learning signal for optimizing what information should persist. We study MGPO on document-level information extraction, where structured supervision makes the effects of individual memory updates directly measurable. MGPO improves extraction while reducing average memory length by nearly 80% relative to the initial memory policy before optimization. The learned memory policy also supports reuse and transfer across domains, downstream models without further training. These results show that effective memory learning depends not only on preserving useful information, but on identifying which memory updates create lasting incremental value.

1 INTRODUCTION

Persistent memory allows language models to maintain information across interactions, but limited capacity requires them to selectively retain, revise, or discard stored content (Toshniwal et al., 2020; Wang et al., 2023; Yu et al., 2026a; Zhou et al., 2026). Learning such update decisions is challenging because information that appears irrelevant at the time of writing may become useful only much later (Arjona-Medina et al., 2019; Han et al., 2019; Hung et al., 2019). Moreover, even when a memory proves useful for a downstream task, its utility may be largely attributable to information inherited from the preceding memory state rather than to the most recent revision. As a result, the utility of the resulting memory does not by itself reveal how much the latest update contributed (Setlur et al., 2025). Learning what to remember thus means learning not only whether a memory update is useful now, but also its incremental value for the future beyond what the memory already knows.

Existing memory systems support selective retention through retrieval (Guo et al., 2025), explicit memory management (Chhikara et al., 2025; Xu et al., 2026; Yu et al., 2026b), and learned policies that construct and revise persistent memory (Yu et al., 2026a; Yan et al., 2026a; Zhou et al., 2026). Yet these approaches largely leave a central learning problem unresolved. It remains unclear whether a memory update actually creates downstream value. To make the effect of memory updates measurable, we optimize a persistent memory writer against a fixed downstream reader, following prior work on upstream adaptation against frozen downstream models (Xu et al., 2024; Yang et al., 2023; Yoon et al., 2024). This leads to a more fundamental credit-assignment problem: when an updated memory improves downstream utility, how much of that utility is created by the latest rewrite, rather than inherited from the memory that already existed?

To answer this question, consider a reader working through a long document with a small notebook. A natural way to assess a notebook revision is to retain both versions and compare how well the same reader performs on the same downstream tasks using each. Information already present contributes to both evaluations, so their difference isolates the change in utility attributable to the revision, following the broader principle (Tumer et al., 2002; Harutyunyan et al., 2019; Foerster et al., 2018) of

Figure

Figure 1: Overview of our methodology. A trainable writer sequentially updates a persistent memory state, while a frozen reader evaluates its downstream utility. A counterfactual comparison evaluates the pre- and post-rewrite memories on the same current and future targets. Summing these utility differences yields the Memory Gain, which serves as the learning signal for optimizing the writer.

counterfactual credit assignment. Persistent memory also has value through future reuse. A recorded detail may offer little immediate benefit yet help interpret subsequent evidence after the original passage has left the reader's context. This motivates long-horizon counterfactual credit assignment, where the pre- and post-rewrite memories are evaluated with the same reader and downstream target, and the paired comparison is propagated across subsequent targets that reuse the updated memory.

We propose the Memory Gain Policy Optimization (MGPO), which trains the memory writer using counterfactual utility differences measured by the frozen reader across current and future downstream targets. MGPO uses these differences to credit each rewrite for its current and future utility, with policy-gradient returns accounting for subsequent rewrites along the memory trajectory. We show that the resulting return decomposes into the cumulative downstream utility minus the inherited utility of the pre-rewrite memory over the same remaining horizon. Because this inherited component is independent of the current rewrite, MGPO preserves the expected policy gradient of the underlying factual objective while changing how credit is assigned to individual memory rewrites.

We evaluate MGPO on document-level information extraction (IE), where predictions often depend on evidence distributed across distant passages (Yao et al., 2019; Tan et al., 2022; Jain et al., 2020), providing a natural setting for studying the value of memory through later reuse. Our experiments demonstrate that MGPO learns compact, effective memories that support the integration of evidence across distant passages and improve downstream extraction performance. The learned writer also transfers across unseen readers, domains, and downstream tasks, showing that the benefits of memory construction extend beyond the reader and task used during training.

The main contributions of this paper are as follows:

• We identify inherited utility as a central challenge in persistent memory learning. The utility of a memory state may largely reflect previously stored information, obscuring the contribution of individual memory rewrites.

• We introduce Memory Gain Policy Optimization (MGPO), which assigns each rewrite long-horizon counterfactual credit. MGPO preserves the original downstream objective while providing a more informative learning signal for memory updates.

• We show that MGPO learns compact and selective memories, improves document-level information extraction, and generalizes beyond its training setting through reuse across readers and transfer across downstream domains.

References (84)