MemGen: Weaving Generative Latent Memory for Self-Evolving Agents

Guibin Zhang, Muxin Fu, Shuicheng Yan

TL;DR

MemGen introduces a dynamic, generative memory framework for LLM agents that seamlessly interweaves reasoning with memory using "machine-native" latent tokens. By utilizing a reinforcement-learned memory trigger and a memory weaver, agents can decide when to reflect and how to synthesize bespoke memories on the fly, leading to significant performance gains and the spontaneous emergence of human-like cognitive hierarchies.

What Problem Does This Paper Address?

Current Large Language Model (LLM) agents typically handle memory in two ways, both of which have significant drawbacks. Parametric memory involves fine-tuning the model's weights on new experiences, which often leads to "catastrophic forgetting" of general knowledge. Retrieval-based memory (like RAG) stores experiences in external text databases, but this process is often rigid and "non-invasive," meaning the retrieved context doesn't always integrate fluidly with the agent's internal reasoning process.

Comparison of memory paradigms

The authors argue that human cognition doesn't just "fetch" text; it reconstructs and weaves memories into the current train of thought. MemGen aims to bridge this gap by allowing agents to generate and use latent memory—high-density vector representations that exist in the model's native embedding space—enabling a more natural, "reconstructive" form of machine intelligence.

Methods

MemGen consists of two synergistic components implemented as lightweight LoRA adapters attached to a frozen "reasoner" LLM:

MemGen Architecture
  1. Memory Trigger ($\mathcal{T}$): This acts as a metacognitive monitor. As the agent generates tokens, the trigger observes the internal hidden states. At semantically significant boundaries (like periods or commas), it decides whether to INVOKE a memory or SKIP. It is trained via Reinforcement Learning (RL) to be "sparse but strategic," using a reward-adaptive penalty to avoid unnecessary compute.
  2. Memory Weaver ($\mathcal{W}$): When the trigger fires, the weaver takes the current hidden state as a "hook" and synthesizes a sequence of $K$ latent tokens. These are not text; they are embeddings that are prepended to the agent's current context to enrich its reasoning.

The system is trained using a variant of Group Relative Policy Optimization (GRPO). Crucially, the core LLM remains frozen, which prevents the erosion of its base capabilities while the weaver learns to "internalize" experiences into its own parameters.

Datasets

The authors evaluated MemGen across nine benchmarks spanning five diverse domains:

  • Web Search: TriviaQA and PopQA.
  • Embodied Action: ALFWorld (interactive environment tasks).
  • Math Reasoning: AQuA, GSM8K, and MATH.
  • Scientific Reasoning: GPQA (graduate-level science questions).
  • Coding: KodCode and BigCodeBench.

Key Insights and Ideas

  • Machine-Native, Human-Unreadable: The latent tokens generated by the weaver are "machine-native." When forcibly decoded into text, they appear as gibberish (e.g., [...]SOC or [...] pick). However, visualizations show these tokens form distinct, structured clusters that the LLM uses to navigate complex reasoning.
  • Spontaneous Cognitive Hierarchy: Without explicit supervision, MemGen spontaneously evolved three distinct types of memory:
  • Planning Memory: Supports high-level task decomposition.
  • Procedural Memory: Facilitates task-specific skills like tool usage and formatting.
  • Working Memory: Maintains coherence and consistency over long contexts.
  • Cross-Domain Synergy: The authors found that training MemGen on one domain (like math) often boosted performance in others (like science or coding), suggesting the weaver learns generalizable "reasoning-augmentation" strategies.
  • Mitigating Forgetting: Because the core model is frozen and only the weaver/trigger are updated, MemGen is remarkably resistant to catastrophic forgetting during continual learning across multiple tasks.

Key Results

  • Performance Gains: MemGen outperformed leading external memory systems like ExpeL and AWM by up to 38.22% on ALFWorld.
  • Superior to Standard RL: It exceeded standard GRPO training by up to 13.44% on reasoning tasks.
  • Efficiency: Despite the overhead of generating latent tokens, MemGen often reduced total inference time. On the KodCode benchmark, it achieved a 75.4% reduction in latency compared to the vanilla model because the enriched context allowed the agent to reach correct answers with fewer reasoning steps.
  • Generalization: When trained on ALFWorld, MemGen improved KodCode performance from 24.55% to 58.16%, demonstrating powerful zero-shot transfer capabilities.

Limitations and Future Work

  • Interpretability: Because the latent tokens are unreadable to humans, it is difficult to "debug" exactly what the agent is remembering or why it made a specific decision.
  • Fixed Memory Length: The current implementation uses a fixed number of latent tokens ($K$). The authors suggest that dynamic-length memory sequences could further optimize the balance between performance and compute.
  • Multi-Agent Scaling: The paper focuses on individual agents; exploring how "woven" latent memories might be shared or communicated between multiple agents is a promising future direction.

Summary updated

BibTeX
@inproceedings{zhang2026memgen,
  author = {Guibin Zhang and Muxin Fu and Shuicheng YAN},
  title = {{MemGen: Weaving Generative Latent Memory for Self-Evolving Agents}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=vI56m4Iu4e},
}
Figure