Shanghai AI Lab's LatentMem Gives Multi-Agent AI Personalized Memory at 2x Speed
LatentMem gives each agent its own compressed, role-aware memory using latent tokens, cutting inference costs in half while boosting multi-agent system performance by up to 19%
ProTakeaways
- What: LatentMem gives each agent in a multi-agent system its own role-specific memory encoded as 8 latent tokens, not text.
- Problem solved: Existing MAS memory systems suffer from memory homogenization (all agents share the same context) and information overload from verbose multi-level text stores.
- Key results: Up to 19.36% performance gain over no-memory baselines, 50% fewer tokens, ~2x faster inference vs. competing memory methods.
- How it works: A small LoRA-trained memory composer compresses retrieved past trajectories + agent role profiles into a fixed-length latent matrix injected into hidden states.
- Training: LMPO, a token-level RL algorithm, trains the composer end-to-end using task correctness as reward, with agent backbones frozen.
- Available now: Code on GitHub and a trained checkpoint on HuggingFace (Qwen3-4B).
Multi-agent systems (MAS) are getting smarter, but their memory is holding them back. A new paper from researchers at Shanghai AI Lab, CUHK, and Tongji University introduces LatentMem, a learnable memory framework that gives each agent in a system its own compact, role-specific memory -- encoded not as text, but as a small matrix of latent vectors injected directly into the model's hidden states. The result is a system that outperforms every existing memory baseline across six benchmarks, while using half the tokens and running roughly 2x faster.
Why agent memory is broken right now
When you build a multi-agent pipeline -- say, a coder agent, a reviewer agent, and a planner agent -- they all typically share the same memory pool. Whatever gets stored gets retrieved by everyone, regardless of role. This creates two compounding problems:
- Memory homogenization: Every agent gets the same memories, even when those memories are irrelevant to their specific role. A reviewer agent doesn't need the same context as a code generator.
- Information overload: Modern memory systems try to solve this by storing memories at multiple levels of abstraction (raw logs, summaries, high-level insights). But this just floods agents with more text, overwhelming their context windows and burying the signal in noise.
The limiting factor in agentic systems is increasingly not raw model capability but memory: how agents encode, retain, retrieve, and consolidate experience into useful knowledge for future decisions. The field has been building increasingly elaborate text-based memory hierarchies -- but LatentMem takes a fundamentally different approach: skip the text entirely.
The core idea: memory as latent tokens
LatentMem has two components that work together. The first is an experience bank -- a lightweight store of raw interaction trajectories from past MAS runs. No summarization, no insight extraction, no human-engineered structure. Just the raw logs, retrieved via cosine similarity using a MiniLM embedding model when a new query arrives.
The second component is the memory composer -- a small transformer (initialized from the same backbone LLM and fine-tuned with LoRA) that takes those retrieved trajectories plus the current agent's role profile and outputs a fixed-length latent memory matrix of shape L' x D, where L' is set to just 8 tokens and D is the model's hidden dimension. This matrix gets concatenated directly to the agent's hidden states before the forward pass -- no extra text in the prompt, no token overhead from verbose memory entries.
Crucially, because the latent memory is a differentiable tensor in the forward pass, gradients can flow back through it to train the composer. This is what makes the third piece possible.
Training the composer: LMPO
The memory composer is trained with Latent Memory Policy Optimization (LMPO), a variant of GRPO (Group Relative Policy Optimization -- a reinforcement learning algorithm that scores outputs relative to other outputs in the same batch, rather than against an absolute reward). LMPO propagates task-level reward signals -- did the MAS get the right answer? -- back through the agent's forward pass and through the latent memory matrix to update the composer's weights.
One key design choice: LMPO uses a token-level objective rather than a trajectory-level one. In long multi-agent interactions, trajectory-level RL treats every token equally regardless of sequence length, which means tokens in short exchanges get disproportionately large gradient contributions. The token-level formulation normalizes across the total token count, making the signal more stable for long-horizon MAS tasks.
The training pipeline looks like this:
- Run the MAS on training data (TriviaQA, KodCode, StrategyQA, PopQA) using AutoGen and MacNet frameworks, collecting 40,580 raw trajectories into the experience bank.
- Train the memory composer via LMPO on the same data, using task correctness as the reward signal. Agent backbone weights stay frozen throughout.
- At inference time, retrieve the top-K most similar trajectories from the bank, compress them into 8 latent tokens per agent via the composer, and inject those tokens into each agent's hidden states.
What the numbers show
LatentMem achieves high performance, improving state-of-the-art MAS by up to 16.20% and 18.45% in knowledge QA and code generation tasks respectively, while using 50% fewer tokens and reducing inference time to approximately 2/3 compared to mainstream memory designs. On out-of-domain benchmarks like PDDL (symbolic planning) and BigCodeBench, where most memory methods actually hurt performance, LatentMem still gains. Competing methods like MetaGPT and Voyager dropped by up to 4.44% on PDDL -- LatentMem improved by 7.10%.
The generalization story is particularly notable. LatentMem was trained on AutoGen and MacNet, but was also tested on CAMEL and DyLAN -- frameworks it had never seen. LatentMem boosts CAMEL on KodCode by 7.05%, whereas nearly all baselines decline. The role-aware memory generalizes to new agent roles and collaboration patterns because the composer learns to condition on agent profiles, not on framework-specific quirks.
The team also compared LatentMem directly against MARTI, a multi-agent fine-tuning baseline trained under identical compute budgets. LatentMem outperformed it consistently -- by 11.73% on TriviaQA with AutoGen -- suggesting that training a small memory module is more sample-efficient than fine-tuning the full agent backbones.
What it's good at -- and where it has limits
LatentMem shines in scenarios where:
- Agents have distinct roles that benefit from personalized context (coding vs. reviewing vs. planning)
- Tasks repeat across sessions and past trajectories are informative
- Token budget is a constraint -- the 8-token latent memory adds negligible overhead
- You want to plug memory into an existing MAS without modifying the agent architecture
There are real constraints worth knowing. The latent memory approach requires that the backbone LLM be accessible at the hidden-state level -- you can't inject latent tokens into a closed API like GPT-4o. The framework also requires a training phase: you need enough trajectories to train the memory composer, which means cold-start performance on entirely new domains will be weaker until the bank populates. The ablation study confirms this: disabling real-time experience bank updates causes a 7.63% drop on PDDL, the most out-of-distribution benchmark.
The fixed memory length of 8 tokens is also a deliberate compression. The ablation shows performance improves with longer L' but with diminishing returns -- so there's a tradeoff between expressiveness and efficiency that practitioners will need to tune for their use case.
The real unlock: plug-and-play memory that learns
The extension of memory to multi-agent systems introduces unique challenges distinct from single-agent memory. Most existing approaches solve this with increasingly complex text hierarchies that require careful engineering and break down on new domains. LatentMem's approach -- compress everything into a small differentiable matrix, train it end-to-end with RL -- is more in the spirit of learned representations than hand-crafted knowledge systems.
The practical implication is that you can drop LatentMem into AutoGen, MacNet, CAMEL, or DyLAN without touching a single agent prompt or system architecture. The code is available on GitHub and a trained model checkpoint (LatentMem-Qwen3-4B) is on HuggingFace, built on Qwen3-4B-Instruct. LatentMem adopts a two-stage training pipeline: in the first stage, raw trajectories are collected on the training split and stored in an experience bank; in the second stage, the memory composer is trained using the LMPO algorithm.
As agent pipelines grow more complex and role-specialized, the question of how each agent maintains its own relevant context -- without drowning in everyone else's -- becomes increasingly central. LatentMem offers a concrete, trainable answer to that question.