This repo is the official implementation of MemGen: Weaving Generative Latent Memory for Self-Evolving Agents
Inspired by the human brain’s ability to dynamically integrate memory and reasoning, MemGen introduces a novel framework that empowers AI agents to evolve through experience—without relying on rigid parameter updates or external databases.
Unlike traditional approaches, MemGen generates latent memory tokens directly within the model’s reasoning stream. It features:
- A Memory Trigger that decides when to recall memory.
- A Memory Weaver that synthesizes past experiences into compact, latent sequences—seamlessly enriching ongoing reasoning.
Create and activate the MemGen environment:
Option 1: Install via requirements.txt
conda create -n memgen python=3.10
conda activate memgen
pip install -r requirements.txt
Option 2: Install via memgen.yml
conda env create -f memgen.yml
conda activate memgen
Please follow the instructions in the Search-R1 to configure the retriever environment (optional).
MemGen consists of two modules: Weaver and Trigger.
We follow a two-stage training approach, training each module separately.
-
Train the Weaver model
bash weaver_train.sh
-
Evaluate the Weaver model
Before running, make sure to updateLOAD_MODEL_PATHineval.shto point to the trained checkpoint:<weaver_dir>bash eval.sh
- Train the Trigger model
bash trigger_train.sh
- Evaluate the Trigger model
Before running, make sure to updateLOAD_MODEL_PATHineval.shto point to the trained checkpoint:<trigger_dir>bash eval.sh
The current repository supports the following features:
- Basic MemGen model implementation
- Single/Multi-turn SFT weaver training
- Trigger RL training
Additional features are planned and will be introduced gradually as they are finalized for public release.
- Single/Multi-turn GRPO weaver training
- Integration with retrieval-based memory systems
- Baseline suite
We sincerely appreciate your patience, interest, and support as we continue to enhance the project and make components more efficient.
If you find this repository helpful, a citation to our paper would be greatly appreciated:
@article{zhang2025memgen,
title={MemGen: Weaving Generative Latent Memory for Self-Evolving Agents},
author={Zhang, Guibin and Fu, Muxin and Yan, Shuicheng},
journal={arXiv preprint arXiv:2509.24704},
year={2025}
}
