Structured Distillation for Personalized Agent Memory: 11x Token Reduction with Retrieval Preservation
Abstract
Long conversations with an AI agent create a simple problem for one user: the history is useful, but carrying it verbatim is expensive. We study personalized agent memory: one user's conversation history with an agent, distilled into a compact retrieval layer for later search. Each exchange is compressed into a compound object with four fields (exchange_core, specific_context, thematic room_assignments, and regex-extracted files_touched). The searchable distilled text averages 38 tokens per exchange. Applied to 4,182 conversations (14,340 exchanges) from 6 software engineering projects, the method reduces average exchange length from 371 to 38 tokens, yielding 11x compression. We evaluate whether personalized recall survives that compression using 201 recall-oriented queries, 107 configurations spanning 5 pure and 5 cross-layer search modes, and 5 LLM graders (214,519 consensus-graded query-result pairs). The best pure distilled configuration reaches 96% of the best verbatim MRR (0.717 vs 0.745). Results are mechanism-dependent. All 20 vector search configurations remain non-significant after Bonferroni correction, while all 20 BM25 configurations degrade significantly (effect sizes |d|=0.031-0.756). The best cross-layer setup slightly exceeds the best pure verbatim baseline (MRR 0.759). Structured distillation compresses single-user agent memory without uniformly sacrificing retrieval quality. At 1/11 the context cost, thousands of exchanges fit within a single prompt while the verbatim source remains available for drill-down. We release the implementation and analysis pipeline as open-source software.
Figures & tables
| Component | Source | Content | Analogy |
|---|---|---|---|
| exchange_core | LLM | What was accomplished (1–2 sentences) | Commit message |
| specific_context | LLM | One distinguishing technical detail | The diff |
| room_assignments | LLM | 1–3 thematic rooms (type, key, label) | Directory tree |
| files_touched | Regex | File paths referenced in exchange | Changed files |
| Statistic | Value |
|---|---|
| Total conversations | 4,182 |
| Total exchanges | 14,340 |
| Distilled objects | 12,427 |
| Avg. verbatim length | 371 tokens |
| Avg. distilled length | 38 tokens |
| Compression ratio | 11 ∗ |
| Family | Configuration | MRR |
|---|---|---|
| Best verbatim | Full Text / BM25-FTS | 0.745 |
| Best pure distilled | Distill Core+Rooms / Exact / Weighted | 0.717 |
| Best cross-layer | Cross: BM25(V)+HNSW(D) / BM25-FTS + HNSW / CombMNZ | 0.759 |
| Measure | Value |
|---|---|
| Fleiss’ across all graders | 0.175 (Slight), over 3,672 items |
| Best pairwise | Phi-3.5-Mini / Qwen3-8B: 0.260 (Fair) |
| Worst pairwise | Mistral-7B / Phi-3.5-Mini: 0.131 (Slight) |
| Mechanism | Significant | Non-significant |
|---|---|---|
| HNSW | 0/10 | 10/10 |
| Exact | 0/10 | 10/10 |
| BM25-Okapi | 10/10 | 0/10 |
| BM25-FTS | 10/10 | 0/10 |
Appendix figures & tables5 assets
Supplementary material from the paper’s appendix.
Appendix
| Mode | Mech | Fus | MRR | Grade | 95% CI | P@1 | nDCG |
|---|---|---|---|---|---|---|---|
| Cross: BM25(V)+HNSW(D) | BM25-FTS + HNSW | CMZ | 0.759 | 2.237 | [2.20, 2.28] | 0.622 | 0.667 |
| Cross: BM25(V)+HNSW(D) | BM25-FTS + HNSW | W70 | 0.758 | 2.261 | [2.22, 2.30] | 0.622 | 0.675 |
| Cross: BM25(V)+HNSW(D) | BM25-FTS + HNSW | W90 | 0.757 | 2.235 | [2.20, 2.27] | 0.632 | 0.667 |
| Cross: BM25(V)+HNSW(D) | BM25-Okapi + HNSW | W70 | 0.754 | 2.182 | [2.14, 2.22] | 0.642 | 0.650 |
| Cross: BM25(V)+HNSW(D) | BM25-FTS + HNSW | W95 | 0.751 | 2.234 | [2.20, 2.27] | 0.617 | 0.666 |
| Cross: BM25(V)+HNSW(D) | BM25-FTS + HNSW | Add | 0.750 | 2.254 | [2.22, 2.29] | 0.612 | 0.671 |
| Query type | Stronger setup | Mean grade | Comparison setup | Mean grade |
|---|---|---|---|---|
| Exact term | Core+Files / HNSW / Wt | 2.08 | Full Text / HNSW | 1.93 |
| Conceptual | Full Text / HNSW | 2.08 | Core+Files / HNSW / RRF | 1.96 |
| Mode | Mechanism | Fusion | Conceptual | Phrase | Exact Term |
|---|---|---|---|---|---|
| Cross: BM25(V)+HNSW(D) | BM25-FTS + HNSW | CombMNZ | |||
| Cross: BM25(V)+HNSW(D) | BM25-FTS + HNSW | W70 | |||
| Cross: BM25(V)+HNSW(D) | BM25-FTS + HNSW | W90 | |||
| Cross: BM25(V)+HNSW(D) | BM25-Okapi + HNSW | W70 | |||
| Cross: BM25(V)+HNSW(D) | BM25-FTS + HNSW | W95 | |||
| Cross: BM25(V)+HNSW(D) | BM25-FTS + HNSW | Additive |
| Measure | Value |
|---|---|
| Fleiss’ (all 5 graders) | 0.175 (Slight) |
| Mean pairwise Cohen’s | 0.192 (Slight) |
| Best pair (Phi-3.5-Mini Qwen3-8B) | 0.260 (Fair) |
| Worst pair (Mistral-7B Phi-3.5-Mini) | 0.131 (Slight) |
| Items rated by all 5 graders | 3,672 |
| Mechanism | Mode | Fusion | ||||
|---|---|---|---|---|---|---|
| HNSW | ||||||
| D Core † | — | 0.052 | 1.93 | 0.055 | 0.14N | |
| D Core+F | Add | +0.105 | 3.07 | 0.0025** | 0.22S | |
| D Core+F | RRF | +0.089 | 2.73 | 0.0068** | 0.19N | |
| D Core+F † | Wt | 0.028 | 1.00 | 0.319 | 0.07N | |
| D Core+R | Add | +0.014 | 0.52 | 0.601 | 0.04N | |
LLM Agent Memory
Large language model agent memory lets agents retain, organize, retrieve, and update information across interactions and long-running tasks.
See all 373 papers