ElasticMem: Latent Memory as a Learnable Resource for LLM Agents

Tao Feng1 Chongrui Ye1 Fangxu Yu2 Tianyang Luo1 Jingjun Xu1 Xueqiang Xu1 Haozhen Zhang3 Weizhi Zhang4 Zijie Lei1 Jiaxuan You1
1University of Illinois Urbana-Champaign  2University of Maryland, College Park  3Nanyang Technological University  4University of Illinois Chicago
0.742
Qwen2.5-3B
0.832
Qwen2.5-7B
Weighted QA Accuracy
+26.2% and +24.6% over the strongest baseline (0.588 / 0.668).
0.449
Qwen2.5-3B
0.529
Qwen2.5-7B
Weighted ALFWorld Success
+66.3% and +27.2% over the strongest baseline (0.270 / 0.416).
11.9K
Qwen2.5-3B
9.0K
Qwen2.5-7B
ALFWorld Tokens / Episode
Lowest weighted token consumption of all compared methods.

Abstract

Memory Should Scale with What the Query Needs

Long-term memory is essential for LLM agents to reason coherently across extended interactions, personalize responses, and reuse past experience. Existing memory-augmented methods typically treat memory as a fixed resource: text-space approaches concatenate retrieved memories into the context window, causing substantial token overhead and sensitivity to noisy evidence, while latent-space approaches reduce textual cost but still rely on rigid retrieval or fixed-capacity memory interfaces. This creates a mismatch between query-dependent memory utility and fixed memory allocation.

We propose ElasticMem, a memory-augmented LLM framework that learns to use memory as an elastic latent resource. ElasticMem builds an offline latent memory bank with retrieval keys and content caches, retrieves memories adaptively from the reasoner's hidden state, assigns each retrieved memory a variable latent budget through a learned policy, and injects selected latent states as soft memory tokens for generation. The full memory-use process is optimized with downstream task rewards through group-relative policy optimization.

On MemorySuite, covering memory-intensive QA and embodied agent control, ElasticMem improves weighted QA accuracy by 26.2% and 24.6%, and ALFWorld success rate by 66.3% and 27.2%, over the strongest baselines with Qwen2.5-3B-Instruct and Qwen2.5-7B-Instruct, while achieving the lowest weighted-average ALFWorld token consumption.

How It Works

Retrieve Adaptively, Allocate Elastically, Train End-to-End

Memories are encoded once into a frozen latent bank. At query time, the LoRA-adapted reasoner emits a retrieval-control token whose hidden state drives retrieval; a budget policy decides how many latent states each retrieved chunk contributes; and a projector turns those states into soft memory tokens. Reasoner, policy, and projector are trained jointly with GRPO on task reward.

ElasticMem overview: offline latent memory bank construction; per-query retrieval from the reasoner's hidden state, elastic latent budget allocation, and latent memory injection; GRPO training loop.
Overview of ElasticMem. Left: each memory chunk (dialogue, passage, or skill card) is encoded once by a frozen LLM into a retrieval key ki and a content cache Ci. Right: the reasoner's query state retrieves the top-Z chunks, the budget policy assigns each chunk bj latent tokens, and the projector injects them as soft memory tokens. Bottom: the reasoner, budget policy, and projector are optimized with group-relative policy optimization.
1
Latent Memory Bank

Each chunk is encoded once by a frozen LLM: its last hidden state is the retrieval key, its last Nc states form the content cache. The bank is never updated during training.

2
Query-Conditioned Retrieval

The reasoner samples a retrieval-control token; the resulting hidden state is the query, so retrieval is learned with the task rather than fixed to an external encoder.

3
Elastic Budget Allocation

A Transformer policy reads the query state, keys, similarities, and earlier decisions, and gives each retrieved chunk a budget bj ∈ {0, …, Bmax}. Useful evidence gets more capacity; weak chunks are compressed or dropped.

4
Injection + GRPO

The last bj cached states of each chunk are projected into soft memory tokens. Reward (exact match for QA, expert-action agreement for ALFWorld) trains reasoner, policy, and projector together.

Main Results

Best Accuracy and Success Across MemorySuite

We compare against seven text-space memory methods (MemoryBank, A-MEM, LightMem, Mem0, MemoryOS, MemP, LangMem) and three latent-space methods (MemGen, AutoCompressor, M+), all on the same backbones. Latent-space baselines are retrained on each task's training split with the same supervision. Scores are means over five training seeds; bold marks the best and underline the second best within each backbone.

Memory QA — Accuracy and Tokens

MethodPersonaMem-32KPersonaMem-128KLoCoMoLongMemEvalAvg.
Acc. ↑#Tok. ↓Acc. ↑#Tok. ↓Acc. ↑#Tok. ↓Acc. ↑#Tok. ↓Acc. ↑#Tok. ↓
Qwen2.5-3B-Instruct
Text-space memory
MemoryBank0.502,4730.334,6180.412,2020.299,5910.374,089
A-MEM0.484,8990.383,5300.393,3480.4515,6250.405,282
LightMem0.468510.351,3060.403,4680.441,2480.392,239
Mem00.427780.396620.338360.332,8430.361,062
MemoryOS0.484,4190.329,4400.334,4200.4013,8540.357,452
MemP0.4212,0020.3829,5670.265,1400.4126,5710.3316,873
LangMem0.406750.301,6260.409360.286870.351,112
Latent-space memory
MemGen0.625020.583930.601980.552420.59291
AutoCompressor0.487170.451,1270.472340.449980.46677
M+0.564470.523500.541540.501980.53247
ElasticMem0.745370.776820.745770.684330.74589
Qwen2.5-7B-Instruct
Text-space memory
MemoryBank0.532,6390.354,7240.402,3010.3910,8220.394,358
A-MEM0.529,7310.3711,0980.423,2890.5031,4890.4210,408
LightMem0.528640.331,2280.413,7020.539390.412,275
Mem00.547940.396760.389210.483,2020.411,157
MemoryOS0.524,6950.389,7480.424,9980.5314,4890.437,926
MemP0.5211,9640.4029,5810.225,3820.4826,5800.3416,985
LangMem0.681,3590.423,0970.351,4780.427810.411,911
Latent-space memory
MemGen0.705020.663930.681980.632420.67291
AutoCompressor0.567170.521,1270.552340.519980.54677
M+0.644470.593500.621540.571980.60247
ElasticMem0.904830.845570.843620.764100.83443

ALFWorld — Success Rate and Tokens

MethodALF-SeenALF-UnseenAvg.
SR ↑#Tok. ↓SR ↑#Tok. ↓SR ↑#Tok. ↓
Qwen2.5-3B-Instruct
Text-space memory
MemoryBank0.0676,0160.0971,1730.0873,648
A-MEM0.0417,2390.0514,2480.0415,776
LightMem0.1413,2520.1712,6170.1512,941
Mem00.1443,0550.1243,6770.1343,359
MemoryOS0.1168,1310.1365,8450.1267,013
MemP0.11101,5800.10110,0190.11105,707
LangMem0.2012,2760.1112,4490.1512,361
Latent-space memory
MemGen0.2914,7080.2514,4160.2714,565
AutoCompressor0.1621,1450.1321,5710.1421,353
M+0.2014,2460.1614,2330.1814,240
ElasticMem0.4911,0280.4112,8460.4511,917
Qwen2.5-7B-Instruct
Text-space memory
MemoryBank0.1136,6020.1939,3850.1537,963
A-MEM0.0629,5430.0929,5310.0729,537
LightMem0.3311,1500.3710,6170.3510,889
Mem00.4326,1650.4027,3270.4226,733
MemoryOS0.3860,1290.4050,2380.3955,292
MemP0.24143,7680.22115,4920.23129,940
LangMem0.409,7350.2810,1400.349,933
Latent-space memory
MemGen0.3912,9330.3413,5510.3613,235
AutoCompressor0.2419,8750.2019,3170.2219,602
M+0.3212,5200.2813,3820.3012,942
ElasticMem0.569,0350.499,0310.539,033

#Tok. counts task-text input, injected memory, and generated output. Avg. columns are weighted by test-set size.

ElasticMem is the best method on every split with both backbones. On ALFWorld it pairs the highest success rate with the lowest token consumption. On QA it uses far fewer tokens than text-space memory and somewhat more than MemGen and M+ (weighted 423 vs. 291 and 247), trading a modest token budget for a large accuracy gain.

Controlled Comparison

Not Just GRPO, Not Just More Parameters

With Qwen2.5-7B-Instruct, all variants share data splits, source memory, retrieval count, training examples, and update count. Swapping SFT for GRPO and enlarging LoRA both help a text-memory model, but neither closes the gap to ElasticMem; replacing the learned projector with direct state injection also costs accuracy.

VariantObjectiveLoCoMo Acc.ALFWorld SR
LoRA + text memorySFT0.5990.380
LoRA + text memoryGRPO0.6500.420
Higher-rank LoRA + text memoryGRPO0.6820.449
ElasticMem with identity projectorGRPO0.7390.460
Full ElasticMemGRPO0.8410.529

ALFWorld SR is weighted over Seen and Unseen episodes.

Ablations

Each Design Choice Earns Its Place

On Qwen2.5-7B-Instruct across all five settings, the learned Transformer budget policy beats random, uniform, and MLP allocation; retrieval from the control-token state beats semantic, frozen-state, and query-only retrieval; and a per-chunk cap of Bmax = 20 works best among 10–40.

Radar chart: ElasticMem vs Random, Uniform, and MLP budget policies across five settings.
(a) Budget policy. The Transformer policy, which conditions on the whole retrieved set, allocates latent capacity better than random, uniform, or MLP budgets.
Radar chart: ElasticMem vs semantic, frozen-state, and query-state retrieval.
(b) Retrieval design. Trainable reasoner-state retrieval with a sampled retrieval-control token beats semantic, frozen-state, and query-state retrieval.
Performance as a function of the maximum per-chunk latent budget.
(c) Maximum budget. With Nc = Bmax, a cap of 20 latent tokens per chunk performs best; a larger allocation space does not help a policy trained on a finite budget.

Transfer. With learned components frozen, checkpoints trained on PersonaMem-128K or ALFWorld beat the corresponding MemGen checkpoints on LoCoMo and LongMemEval by 7.3–8.9 accuracy points; only the target memory bank is rebuilt. Llama-3.2-3B and Llama-3.1-8B runs also favor ElasticMem on both PersonaMem datasets.

BibTeX

@article{feng2026elasticmem,
  title   = {ElasticMem: Latent Memory as a Learnable Resource for LLM Agents},
  author  = {Feng, Tao and Ye, Chongrui and Yu, Fangxu and Luo, Tianyang and Xu, Jingjun and Xu, Xueqiang and Zhang, Haozhen and Zhang, Weizhi and Lei, Zijie and You, Jiaxuan},
  journal = {arXiv preprint arXiv:2605.30690},
  year    = {2026}
}