TL;DR
MemFactory is the first unified, highly modular training and inference framework designed specifically for memory-augmented LLM agents. By abstracting the memory lifecycle into plug-and-play atomic components and natively integrating memory-efficient Group Relative Policy Optimization (GRPO), it allows researchers to easily build, fine-tune, and evaluate complex memory management policies on a single GPU.
What Problem Does This Paper Address?
While Large Language Models (LLMs) excel at short-term reasoning, transforming them into autonomous, long-term agents requires robust memory management (extracting, updating, and retrieving information over time). Recently, researchers have turned to Reinforcement Learning (RL) to let agents autonomously learn optimal memory strategies rather than relying on rigid, heuristic rules.
However, the current Memory-RL ecosystem is highly fragmented. Existing implementations (like Memory-R1 or MemAgent) are deeply coupled with specific tasks and scattered across isolated repositories, making it incredibly difficult to reproduce results or mix-and-match different memory strategies. Furthermore, standard LLM fine-tuning frameworks are built for stateless sequence-to-sequence tasks and lack the architectural primitives required to manage stateful, long-context memory lifecycles. MemFactory bridges this gap by providing a standardized, "Lego-like" infrastructure for agent memory.
Methods
MemFactory introduces a highly modular architecture divided into four distinct layers:
- Module Layer: Deconstructs the memory pipeline into standardized, atomic operations: Extractors (parsing raw context into facts), Updaters (managing CRUD operations like ADD, DELETE, UPDATE), Retrievers (fetching relevant memories, including LRM-based reranking), and unified Agent Modules for end-to-end recurrent memory states.
- Agent Layer: Acts as the central policy executor, assembling the atomic modules to implement diverse memory strategies and handle prompt padding and action masking during training.
- Environment Layer: Functions as both a dataloader and reward manager, standardizing raw data into unified states. It features two primary environments:
MemoryBankEnvfor explicit, updatable long-term memory, andLongcontextEnvfor short-term, history-based memory. - Trainer Layer: Optimizes the agent's internal memory policies using Group Relative Policy Optimization (GRPO). Unlike traditional PPO, GRPO eliminates the need for a separate critic network. This significantly reduces the memory footprint, which is critical since memory-augmented agents already saturate context windows with long dialogue histories.
The framework provides out-of-the-box support for cutting-edge paradigms including Memory-R1, MemAgent, and RMM.
Datasets
The authors validated the framework using the publicly available training and evaluation datasets from the MemAgent release. To improve training efficiency while preserving the long-context nature of the tasks, they simplified the training samples by reducing the context length to roughly one-third of the original (resulting in 50 to 80 documents per sample).
Evaluation was conducted across three specific test sets from the MemAgent data:
- Two main-task datasets:
eval_50andeval_100 - One out-of-distribution (OOD) dataset:
eval_fwe_16384
Key Insights and Ideas
- The "Lego" Paradigm for Memory: By decoupling the memory lifecycle into atomic components with standardized interfaces (
generate,rollout,inference), researchers can seamlessly swap out components—for instance, replacing a naive retriever with an LRM-based reranker without rewriting the training pipeline. - GRPO is a Game-Changer for Memory-RL: Training memory agents is computationally expensive because of long context windows filled with historical data. Natively integrating GRPO allows the framework to bypass the massive memory overhead of a critic model, democratizing this research so it can run on a single GPU.
Key Results
The authors empirically tested MemFactory by training MemAgent-style agents using two base models: Qwen3-1.7B and Qwen3-4B-Instruct. The entire pipeline was executed on a single NVIDIA A800 80GB GPU.
- Qwen3-1.7B: Achieved a 14.8% relative increase in average score, driven by substantial gains in the main-task settings (
eval_50andeval_100), though OOD performance saw a slight decrease. - Qwen3-4B-Instruct: Demonstrated more robust and uniform improvements, achieving a 7.3% relative increase on average, including consistent gains on the OOD benchmark. This indicates that larger models effectively transfer learned recurrent memory policies to unseen settings.
| Model | Setting | eval_50 | eval_100 | eval_fwe_16384 | Average |
|---|---|---|---|---|---|
| Qwen3-1.7B | Base | 0.4727 | 0.4297 | 0.0332 | 0.3118 |
| + MemFactory RL | 0.5684 | 0.4863 | 0.0195 | 0.3581 | |
| Qwen3-4B-Instruct | Base | 0.6523 | 0.5645 | 0.6270 | 0.6146 |
| + MemFactory RL | 0.7051 | 0.6309 | 0.6426 | 0.6595 |
Limitations and Future Work
While MemFactory successfully unifies several prominent memory paradigms, the authors note that the current version only covers a limited set of representative architectures (Memory-R1, MemAgent, and RMM). Additionally, there is still room for further optimization regarding training efficiency. Future iterations will likely expand support to a broader range of emerging memory paradigms and focus on scaling up training throughput.
Summary updated