MemPilot: Learning Transferable Latent Memory Mechanisms for LLM Reasoning

Changlong Shi, Linhao Luo, Shigeng Chen, Guibin Zhang, Yi Chang, Shirui Pan, Chengqi ZhangNeurIPS 2026

TL;DR

Giving Large Language Models (LLMs) a memory usually means choosing between stuffing raw text into the prompt (flexible, but bloated and distracting) or fine-tuning knowledge into the weights (deep, but rigid and prone to overfitting). MemPilot introduces a decoupled "latent memory" middle ground: it compresses past reasoning experiences into compact vector banks and teaches a frozen LLM how to read them. Because the memory content is separated from the skill of using memory, you can adapt the model to an entirely new domain in seconds just by swapping out the memory bank—zero retraining required.

What Problem Does This Paper Address?

For LLM agents to solve multi-step problems, they need to learn from past successes and failures. Historically, we’ve handled this in two ways:

  1. Explicit text memory (like RAG): Store past reasoning traces as text and paste them into the prompt. It’s easy to edit, but long trajectories blow up inference costs and create "lexical traps"—where a retrieved example looks superficially similar to the current problem, distracting the model onto the wrong reasoning path.
  2. Parametric memory (like fine-tuning): Bake past experiences directly into the model’s weights. This guides internal reasoning deeply without prompt bloat, but updating it requires expensive retraining. Worse, it tangles domain-specific quirks with general reasoning, causing catastrophic forgetting or negative transfer on new tasks.

Recent "latent memory" methods try to store compressed continuous vectors externally, but they usually train the memory encoder and the LLM end-to-end. As a result, the system overfits to task-specific shortcuts rather than learning a universal way to read memory. The authors ask: Can we teach a frozen LLM a general, reusable skill for consulting external latent memories, keeping the memories themselves completely swappable?

Methods

MemPilot splits memory-augmented reasoning into two strictly decoupled phases while keeping the base LLM reasoner completely frozen:

Figure 1: Overview of the proposed MemPilot framework.
  • Offline Memory Construction: A separate memory encoder (initialized from the base LLM and lightly tuned via LoRA using a contrastive retrieval loss—never the downstream generation loss) compresses full text reasoning trajectories into a tiny sequence of continuous vectors (defaulting to $S=8$ latent tokens per trajectory). Each entry is stored in an external bank alongside a pooled summary vector acting as a retrieval key.
  • Coarse-to-Fine Retrieval & Gated Fusion: At inference time, right before the frozen LLM's final language-modeling head, MemPilot pools the query's hidden states to fetch the top-$K$ ($K=4$) relevant memory entries. A lightweight cross-attention module then lets the LLM’s active hidden states "read" the fine-grained latent tokens. Crucially, before adding this signal into the LLM's residual stream, it passes through a learned gating mechanism—a dynamic filter that dials down the external memory if it doesn't match the current reasoning step.

To deploy on a brand-new domain, you freeze everything, run the new domain's trajectories through the encoder to build a fresh memory bank, and plug it in.

Datasets

The authors evaluate MemPilot across five established benchmarks spanning three distinct reasoning modalities (no new datasets are introduced):

  • Mathematical Reasoning: GSM8K and MATH.
  • Question Answering: HotpotQA and TriviaQA.
  • Executable Code Synthesis: KodCode.

Key Insights and Ideas

  • Coupled memory causes severe negative transfer: When existing latent/parametric methods (like MemGen) are trained on HotpotQA and tested out-of-domain on MATH, accuracy collapses from a 36.63% vanilla baseline down to 2.14%. Decoupling the memory bank prevents the model from memorizing source-domain habits.
  • The gate acts as an out-of-domain immune system: Why doesn't MemPilot break on unfamiliar tasks? When given mismatched memories, the learned gate automatically suppresses them.
Figure 2: Mean gate value across domains, show- ing adaptive suppression in OOD scenarios.
  • Base LLMs naturally cluster reasoning modalities: Even without LoRA-tuning the memory encoder, MemPilot scores huge gains (jumping from 24.5% to 53.3% on KodCode). A t-SNE visualization reveals that frozen LLMs naturally organize math, code, and QA trajectories into cleanly separated latent clusters.
  • Procedural affinity matters: Cross-domain transfer works best when underlying logic aligns—for instance, a memory reader trained on algorithmic coding (KodCode) transfers remarkably well to formal math (GSM8K), suggesting MemPilot genuinely learns to extract procedural structure rather than surface facts.

Key Results

Tested on Qwen2.5-1.5B-Instruct and Qwen3-8B, MemPilot achieves the highest overall in-domain accuracy (58.06% and 77.06%, respectively), beating SFT, text-retrieval (ExpeL, MemoryBank), and latent baselines (SoftCoT, MemGen).

  • Zero-Update Transfer: Trained solely on KodCode (1.5B backbone) and handed a GSM8K memory bank, MemPilot hits 63.01% on GSM8K—beating the vanilla model (56.79%), MemGen (33.87%), and SFT (8.12%) without a single parameter update. Across 12 cross-domain pairs, MemPilot averages 43.96%, outperforming target-domain text RAG baselines like MemoryBank (42.92%).
  • Speed & Adaptation Efficiency: On KodCode, MemPilot runs 5.2x faster than text RAG (1.12s vs. 5.87s per example) by avoiding ~2,000 tokens of prompt bloat, and even runs faster than the vanilla model (3.51s) because latent guidance helps it generate more concise solutions. Adapting to a new domain takes just 45 seconds to encode a new bank, compared to 2.1–2.5 hours of retraining for SFT or MemGen.

Limitations and Future Work

While the authors do not include a dedicated limitations section, they explicitly note a boundary in cross-domain transfer: gains depend on the structural affinity between source and target reasoning modalities. When transferring from multi-hop QA (HotpotQA) to advanced competition math (MATH), improvements become much more modest—though the gating mechanism still prevents the catastrophic collapse seen in fine-tuned baselines. Furthermore, in the current setup, retrieval is triggered only once at the start of generation rather than dynamically re-querying mid-thought, leaving room for more adaptive multi-step retrieval in future iterations.

Summary updated

Abstract

Integrating external memory into Large Language Models (LLMs) typically faces a trade-off between flexibility and depth. Explicit text-based retrieval keeps memory editable, but often acts as a static prompt prefix, increasing context length and interacting with the reasoning process only indirectly. Conversely, parametric memory can influence internal computation more deeply, but updating memory content usually requires additional optimization and may couple domain-specific information with the model's general reasoning behavior. In this work, we introduce MemPilot, a decoupled latent memory framework that dynamically guides the hidden reasoning states of frozen LLMs. MemPilot constructs an external bank of compact latent representations from offline reasoning trajectories, retrieves candidate memory entries, and integrates their latent memory tokens into hidden states via cross-attention and gated residual fusion. By separating domain-specific memory content from the learned memory-use mechanism, MemPilot enables target-domain adaptation through offline memory-bank substitution without updating the base model. Experiments across QA, coding, and mathematical reasoning benchmarks show that MemPilot achieves strong in-domain performance and more robust cross-domain transfer than other memory-augmented baselines. These results suggest that LLMs can benefit from reusable latent memory-use mechanisms while keeping memory content external and replaceable.
BibTeX
@inproceedings{shi2026mempilot,
  author = {Changlong Shi and Linhao Luo and Shigeng Chen and Guibin Zhang and Yi Chang and Shirui Pan and Chengqi Zhang},
  title = {{MemPilot: Learning Transferable Latent Memory Mechanisms for LLM Reasoning}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=BSzhr7UWqR},
}
Figure