Agent memory and context

MIT-MI/

MEM1

RL-trained 7B model that consolidates memory at each turn, cutting context growth while improving multi-hop QA accuracy.

What’s new here

MEM1 trains the model itself, via reinforcement learning, to maintain a compact shared state that is rewritten at each turn. Irrelevant or redundant information gets dropped during the update, not after the fact. The result is constant memory use regardless of how many turns the task runs. The internal state jointly supports memory consolidation and reasoning, so both happen in one pass rather than as separate stages.

What it does

MEM1 is an end-to-end RL training framework for 7B-scale LLMs. At each turn of a multi-turn task, the model reads its current internal state plus the new observation and produces an updated state. That state carries both the memory of prior turns and the reasoning context needed for the next step.

Training uses PPO over multi-turn environments built by composing existing QA datasets into longer task sequences. The paper reports results on three domains: internal retrieval QA, open-domain web QA, and multi-turn web shopping.

The released checkpoint is Mem-Lab/Qwen2.5-7B-RL-RAG-Q2-EM-Release on Hugging Face. According to the paper, MEM1-7B reaches 3.5x better performance than Qwen2.5-14B-Instruct on a 16-objective multi-hop QA task while using 3.7x less memory, and it generalizes beyond the training horizon.

Who it’s for

Researchers working on long-horizon agent memory or context efficiency who want to reproduce or extend the MEM1 results. Also useful for anyone running multi-turn retrieval agents who can afford to fine-tune a 7B model and wants to avoid unbounded context growth at inference time. The setup requires CUDA and GPU hardware; this is a training framework, not a drop-in library.

Try it

You need Python 3.9+, CUDA 12.1, and two conda environments: one for training (mem1) and one for the optional local retriever.

# Install requirements. This may take a few minutes to complete.
conda create -n mem1 python=3.9
conda activate mem1
# install torch [or you can skip this step and let vllm to install the correct version for you]
pip install torch==2.4.0 --index-url https://download.pytorch.org/whl/cu121
# install vllm
pip3 install vllm==0.6.3 # or you can install 0.5.4, 0.4.2 and 0.3.1
 
# install other dependencies
pip install -r requirements.txt
 
# install verl locally
cd Mem1/train
pip install -e .
 
# install flash attn
pip3 install flash-attn --no-build-isolation

Then download data, preprocess, and launch a retrieval server before running bash train_ppo.sh. To evaluate without training, serve the released checkpoint via start_vllm.sh and run python inference/generate_rollout.py with the --use_mem1 flag.

How mature is it

344 stars, 21 forks, 2 contributors, 0 releases. Created July 2025; last pushed January 2026. No commits in the past 90 days. The repo has 8 open issues and no open PRs. Accepted at ICLR 2026 and received Best Paper Award at the NeurIPS 2025 MTI-LLM Workshop. Licensed MIT.