Dynamic Mixture of Latent Memories for Self-Evolving Agents

Dianzhi Yu, Vireo Zhang, Hongru Wang, Yanyu Chen, Minda Hu, Wanghan Xu, Siki Chen, Philip Torr, Zhenfei Yin, Irwin KingarXiv 2026 · arXiv

TL;DR

MoLEM (Mixture of Latent Memories) is a novel framework that allows large language model (LLM) agents to continually learn new domains without suffering from catastrophic forgetting. By keeping the base LLM frozen and dynamically recruiting domain-specific groups of latent memory experts routed via a task-ID-free autoencoder ensemble, MoLEM achieves a 10.40% accuracy boost over vanilla baselines while maintaining zero forgetting.

What Problem Does This Paper Address?

For an intelligent agent to truly "self-evolve," it must continuously accumulate new knowledge across a sequence of diverse tasks without erasing its previously acquired abilities.

Current approaches to this problem fall into two flawed categories:

  1. Parametric Memory (Fine-tuning): Modifying the model's core parameters directly to learn new tasks. This inevitably triggers catastrophic forgetting, where learning a new skill (like coding) severely degrades a previously learned skill (like mathematics).
  2. Retrieval-Based Memory: Storing experiences in external databases and fetching them at inference time. While this avoids forgetting, it amounts to mere context engineering; the model's intrinsic capabilities are never actually enhanced.

Recent "latent memory" methods attempt to bridge this gap by using continuous vectors as high-density internal memory carriers. However, they rely on static architectures that overwrite previous behaviors when reused across shifting task sequences. The authors of this paper introduce MoLEM to provide a flexible, extensible cognitive architecture that dynamically expands capacity while completely isolating learned skills.

Methods

MoLEM introduces a generative latent memory framework built on a dynamic Mixture-of-Experts (MoE) architecture. The framework operates via two main phases:

1. Stage-wise Evolutionary Training

The core reasoning LLM remains entirely frozen throughout the process. When the agent encounters a new domain (e.g., transitioning from Math to Science), it executes a Stage-wise Recruiting strategy:

  • It freezes all previously trained memory modules.
  • It recruits a fresh group of parameter-isolated LoRA adapters (the experts) and a corresponding domain router.
  • It trains only this new group using Supervised Fine-Tuning (SFT) combined with a Switch-style load-balance loss to ensure expert diversity.

2. Domain-Aware Inference & Latent Memory Injection

At inference time, the agent operates without explicit task labels (task-ID-agnostic). To determine which memory group to activate, each training stage is paired with a lightweight Autoencoder (AE) trained to reconstruct the prompt-end hidden states of the frozen LLM.

The inference pipeline proceeds as follows:

  • The input query is passed through the frozen LLM to extract its prompt-end feature vector.
  • This vector is fed into the ensemble of stage-wise autoencoders.
  • The routing group associated with the AE yielding the smallest reconstruction error is selected.
  • If the reconstruction errors for all AEs exceed a calibrated threshold, the input is flagged as Out-of-Distribution (OOD), and the system safely falls back to the vanilla pretrained model.
  • The selected router uses key-query matching (cosine similarity) to weight and aggregate the latent memories generated by individual experts, injecting the final representation back into the reasoning process.
Overview of the MoLEM framework showing stage-wise training (Part A) and domain-aware inference via an autoencoder ensemble (Part B).

Datasets

The authors evaluated MoLEM on a multi-stage continual learning sequence spanning three distinct domains:

  • Math: Mathematical reasoning questions drawn from Nemotron MATH.
  • Science: Multiple-choice scientific questions drawn from Nemotron Science.
  • Code: Code-generation problems drawn from KodCode.

The framework was tested across different sequential permutations (e.g., Math $\rightarrow$ Science $\rightarrow$ Code) to ensure stability against task-ordering variations.

Key Insights and Ideas

  • Inherent Discriminability of LLM Hidden States: Rather than training a complex, joint domain classifier, MoLEM leverages the fact that a pretrained LLM naturally clusters different domains within its internal representation space. A simple ensemble of independent, lightweight autoencoders is sufficient to accurately route inputs based purely on reconstruction error.
t-SNE visualization showing that the frozen reasoner's hidden states naturally separate into distinct clusters for math, science, and code.
  • Spontaneous Expert Diversity: Even though the roles of individual experts within a domain pool are not manually defined, the combination of key-query routing and load-balancing losses forces the experts to specialize in distinct sub-features of the input domain.
Overall expert usage across the three datasets, demonstrating input-dependent expert preferences and spontaneous specialization.
  • OOD Protection via Fallback: By allowing unfamiliar inputs to bypass the memory modules entirely, MoLEM ensures that the agent's baseline general-purpose competence is never corrupted by irrelevant or harmful expert memories.

Key Results

MoLEM demonstrates a clear advantage over standard fine-tuning and alternative memory baselines after completing the full training sequence (Math $\rightarrow$ Science $\rightarrow$ Code):

  • Superior Accuracy: MoLEM achieved a final average accuracy of 73.93% across all test sets, outperforming the Vanilla baseline (63.53%), standard SFT (34.40%), and the latent-memory baseline MemGen (63.47%).
  • Zero Catastrophic Forgetting: While standard SFT's performance on the Math test set collapsed from 57.20% at Stage 1 down to 12.80% at Stage 3 due to parameter overwriting, MoLEM maintained a strict 0.00% forgetting rate across all stages.
  • Order Invariance: The performance gains remained highly consistent regardless of the training order (e.g., Code $\rightarrow$ Science $\rightarrow$ Math), proving that the framework effectively isolates cross-domain parameter interference.

Limitations and Future Work

The primary limitation acknowledged by the authors is parameter overhead. Because each new domain requires recruiting a new set of experts, routers, and autoencoders, the total parameter count scales linearly with the number of training stages.

Although these modules utilize parameter-efficient fine-tuning (PEFT) and remain compact relative to the frozen backbone, scaling the system to dozens or hundreds of highly granular tasks will eventually demand more sophisticated expert-pruning, consolidation, or sharing mechanisms.

Summary updated

Abstract

Achieving self-evolution in intelligent agents requires the continual accumulation of new knowledge across changing task sequences without forgetting previously acquired abilities. Existing approaches either internalize knowledge by updating model parameters, which induces catastrophic forgetting, or rely on external memory, which fails to genuinely enhance the model's intrinsic capabilities. We propose MoLEM, a generative mixture of latent memory framework based on a dynamic mixture-of-experts (MoE). We treat multiple experts as independent carriers to generate memory. A router selects and weights experts through key-query matching, and the aggregated latent memory is injected into the reasoning process. The base model for reasoning remains entirely frozen, with all experiential knowledge internalized into the additional modules, avoiding catastrophic forgetting. For continual learning, each training stage is paired with a lightweight autoencoder that selects the appropriate routing group at inference, and inputs that match no stage fall back to the pretrained model. Experiments train the framework on continual-learning sequences spanning math, science, and code domains. After training, we evaluate the framework on the corresponding test sets to measure task learning and competence preservation across continual adaptation stages. After the full continual-learning sequence, our method improves the average accuracy by 10.40% over the Vanilla pretrained baseline, while none of the competing methods consistently exceed this baseline across different training orders.
BibTeX
@misc{yu2026dynamic,
  author = {Dianzhi Yu and Vireo Zhang and Hongru Wang and Yanyu Chen and Minda Hu and Wanghan Xu and Siki Chen and Philip Torr and Zhenfei Yin and Irwin King},
  title = {{Dynamic Mixture of Latent Memories for Self-Evolving Agents}},
  year = {2026},
  eprint = {2605.21951},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2605.21951},
}

Loading related content...

Figure