HasMem: Hard-Origin Adaptively Softened Memory for Long-Term LLM Agents
Organizations: The Hong Kong University of Science and Technology (Guangzhou) · University of Bristol · The Hong Kong University of Science and Technology
Abstract
Text-based memory and context compression support reuse of past interactions. Resizing continuous memory changes the input to a frozen LLM, coupling capacity allocation with readout. We propose Hard-Origin Adaptively Softened Memory (HasMem). Frozen hard-prompt embeddings provide a verifiable initial state. A controller adjusts memory widths, a Writer re-encodes resized entries, and Reader and Global provide readout adaptation and cross-turn state. On all questions in a reconstruction probe derived from the Multi-Session Chat (MSC) development split, the main configuration achieves lexical F1 of ( percentage points) at of the hard reference's framed memory positions. With approximately matched per-question target body budgets, six configurations at mean per-entry retention around -- exceed rule-based re-encoding by -- exact-match (EM) percentage points. With fixed model parameters and rule target width ratio , Global's EM gain passes a user-level exact paired test with Bonferroni correction over eight comparisons. On all LongMemEval-S questions, local lexical F1 rises from the hard reference's to , and answer negative log-likelihood (NLL) falls from to . F1 gains accompany lower EM on both evaluations.
Figures & tables
| Backbone | F1 HasMem / hard | EM HasMem / hard | NLL HasMem / hard | HasMem / hard | |
| Qwen2.5-7B | 2 | 86.7 / 87.6 | 69.6 / 84.7 | 0.463 / 0.416 | 0.900 / 1.000 |
| Qwen2.5-7B | 6 | 95.4 / 91.0 | 65.7 / 88.2 | 0.154 / 0.074 | 0.879 / 1.000 |
| Qwen2.5-7B | 8 | 95.3 / 90.9 | 84.3 / 88.1 | 0.115 / 0.074 | 0.936 / 1.000 |
| Qwen2.5-7B | 12 | 92.3 / 90.9 | 77.4 / 88.1 | 0.173 / 0.074 | 0.921 / 1.000 |
| Backbone | F1 HasMem / hard | EM HasMem / hard | NLL HasMem / hard | Cover HasMem / hard | Brief HasMem / hard | Local judge HasMem / hard | |
| Qwen2.5-0.5B | 8 | 5.4 / 5.6 | 0.00 / 1.00 | 4.663 / 3.649 | 8.4 / 8.8 | 0.6 / 8.4 | 10.8 / 10.6 |
| Qwen2.5-1.5B | 4 | 7.0 / 3.2 | 0.80 / 1.20 | 5.058 / 4.962 | 9.8 / 7.4 | 3.4 / 7.4 | 8.6 / 7.6 |
| Qwen2.5-1.5B | 8 | 1.3 / 3.6 | 0.40 / 1.40 | 5.931 / 4.911 | 1.4 / 8.2 | 1.0 / 8.2 | 5.0 / 8.4 |
| Qwen2.5-3B | 8 | 6.8 / 3.6 | 0.00 / 0.20 | 4.842 / 10.413 | 15.4 / 10.0 | 0.4 / 7.6 | 9.8 / 10.6 |
| Qwen2.5-7B | 2 | 0.5 / 1.2 | 0.00 / 0.20 | 8.805 / 13.200 | 0.0 / 7.6 | 0.0 / 7.0 | 2.2 / 7.6 |
| Qwen2.5-7B | 4 | 2.0 / 2.7 | 0.00 / 1.20 | 5.328 / 12.985 | 5.4 / 9.0 | 2.0 / 8.4 | 3.8 / 9.2 |
| 0.5B EM / | 1.5B EM / | 3B EM / | 7B EM / | 14B EM / | |
| 12.3 / 0.670 | 9.0 / 0.602 | 77.2 / 0.889 | 75.2 / 0.887 | 45.1 / 0.814 | |
| (default) | 7.1 / 0.604 | 17.0 / 0.665 | 72.0 / 0.892 | 38.4 / 0.788 | 49.8 / 0.814 |
| 9.9 / 0.632 | 28.2 / 0.714 | 77.8 / 0.915 | 80.0 / 0.917 | 84.3 / 0.916 | |
| 9.9 / 0.637 | 49.4 / 0.909 | 57.8 / 0.909 | 90.5 / 0.992 | 93.3 / 1.000 | |
| 63.2 / 0.924 | 79.9 / 0.957 | 80.6 / 0.973 | 86.0 / 0.970 | 91.8 / 0.974 | |
| Hard reference | 51.1 / 1.000 | 80.8 / 1.000 | 74.6 / 1.000 | 88.1 / 1.000 | 93.3 / 1.000 |
| Trained configuration | Learned | Learned F1 / EM | Rule-based | Rule-based F1 / EM | EM learned rule-based | Position gap (%) mean / maximum |
| Seed 2026091703 | 93.7 / 79.6 | 93.8 / 79.8 | 0.05 / 2.40 | |||
| Seed 2026091401 | 96.1 / 82.2 | 96.5 / 82.6 | 0.05 / 2.40 | |||
| Main run | 95.5 / 84.5 | 93.9 / 66.5 | 1.06 / 5.41 | |||
| Seed 2026091702 | 93.6 / 79.3 | 94.3 / 65.4 | 1.35 / 5.95 | |||
| Seed 2026091701 | 93.7 / 77.6 | 92.1 / 54.0 | 1.22 / 5.41 | |||
| full (fixed steps) | 94.1 / 75.0 | 93.9 / 55.5 | 1.64 / 5.13 |
Appendix figures & tables14 assets
Supplementary material from the paper’s appendix.
Appendix
| Configuration | MSC F1 | MSC EM | Writing and readout |
| Verbatim window | 93.04 | 86.19 | Verbatim text |
| BM25 retrieval ( ) | 87.91 | 78.73 | Verbatim text |
| Hard embedding retrieval | 87.86 | 77.99 | Verbatim text |
| A-MEM adaptation | 85.57 | 75.75 | One write per event |
| Mem0 adaptation | 5.65 | 0.00 | One write per event |
| LLMLingua-2 (official, single pass) | 19.67 | 0.00 | One token-pruning pass before readout at nominal retention |
| Method | Cover | Brief | Lexical F1 | Protocol |
| Hard reference, same retrieval width | 10.60 | 9.80 | 3.39 | Retrieval settings shared with HasMem |
| HasMem (main) | 14.20 | 5.60 | 8.94 | Learned softening with the configuration in Table 2 |
| LLMLingua-2 (official, single pass) | 26.20 | 1.80 | 9.23 | Whole-context compression at nominal ratio |
| Method | Backbone | Memory form | Position ratio | MSC F1 | F1 | MSC EM | EM |
| Hard reference (HasMem) | Qwen2.5-7B | Token embeddings | 90.87 | — | 88.06 | — | |
| HasMem (main) | Qwen2.5-7B | Continuous slots | 95.29 | 84.33 | |||
| Hard embedding retrieval | Qwen2.5-7B | Text tokens | 87.86 | — | 77.99 | — | |
| LLMLingua-2 (official, single pass) | Qwen2.5-7B | Text tokens | (nominal) | 19.67 | 0.00 | ||
| Hard embedding retrieval | Mistral-7B | Text tokens | 72.11 | — | 31.34 | — | |
| ICAE v2, one bank per context | Mistral-7B | Continuous slots | 28.45 | 10.26 |
| Backbone ( ) | F1 | EM | NLL | Hard reference F1 / EM / NLL | F1 / EM | ||
| 0.5B | 69.8 | 12.3 | 1.065 | 59.4 / 51.1 / 0.187 | / | ||
| 0.5B | 58.9 | 7.1 | 1.598 | 59.4 / 51.1 / 0.187 | / | ||
| 0.5B | 62.5 | 9.9 | 1.349 | 59.4 / 51.1 / 0.187 | / | ||
| 0.5B | 61.1 | 9.9 | 1.417 | 59.4 / 51.1 / 0.187 | / | ||
| 0.5B | 91.5 | 63.2 | 0.197 | 59.4 / 51.1 / 0.187 | / | ||
| 1.5B | 63.0 | 9.0 | 1.362 | 90.4 / 80.8 / 0.039 | / |
| Seed | Selected update | F1 | EM | Answer NLL | |
| 385 | 90.9 | 88.1 | 0.074 | ||
| 411 | 96.1 | 82.3 | 0.110 | ||
| 4906 | 93.5 | 77.4 | 0.161 | ||
| 3801 | 93.6 | 79.3 | 0.134 | ||
| 417 | 93.7 | 79.7 | 0.095 | ||
| 422 | 96.0 | 86.6 | 0.072 |
| Configuration | All questions EM [95% interval] | Subset questions / owners | Equal-position subset EM [95% interval] |
| Seed 2026091703 | -0.19 [-1.12, 0.75] | 511 / 256 | +0.00 [-0.59, 0.59] |
| Seed 2026091401 | -0.37 [-1.12, 0.37] | 512 / 256 | -0.20 [-0.59, 0.00] |
| Original configuration | +17.94 [14.55, 21.39] | 236 / 118 | +8.05 [3.81, 12.29] |
| Seed 2026091702 | +13.83 [10.09, 17.54] | 248 / 124 | +6.45 [1.61, 11.29] |
| Seed 2026091701 | +23.55 [19.66, 27.43] | 253 / 127 | +17.79 [12.20, 23.62] |
| full (fixed update count) | +19.44 [15.54, 23.26] | 177 / 89 | +12.43 [5.17, 19.66] |
| Backbone | Training updates | |
| Qwen2.5-0.5B | 8 | 5683 |
| Qwen2.5-1.5B | 4 | 2907 |
| Qwen2.5-1.5B | 8 | 4949 |
| Qwen2.5-3B | 8 | 5065 |
| Qwen2.5-7B | 2 | 5879 |
| Qwen2.5-7B | 4 | 5825 |
| Configuration | Seed | Updates evaluated / completed | F1 | EM | NLL | |
| full + always-on readout gate | 2026091331 | 5465 / 5465 | 95.1 | 80.0 | 0.135 | |
| Additional hard anchoring | 2026091401 | 426 / 5465 | 94.3 | 81.0 | 0.100 | |
| Additional hard anchoring | 2026091701 | 428 / 5465 | 92.5 | 78.2 | 0.114 | |
| Additional hard anchoring | 2026091702 | 422 / 5465 | 97.0 | 89.7 | 0.059 | |
| Additional hard anchoring | 2026091703 | 433 / 5465 | 93.7 | 82.6 | 0.091 | |
| Final target frequency | 2026091701 | 4896 / 5465 | 92.7 | 84.0 | 0.096 |
| Method | Action rule | F1 | EM | |
| HasMem (original main run) | Controller-selected actions | 95.3 | 84.3 | |
| Hard reference | Original token embeddings | 90.9 | 88.1 | |
| Fixed | SHRINK at every step | 80.0 | 22.9 | |
| Random | Uniform sampling over three actions | 90.6 | 50.4 |
| Configuration | Training and deployment | MSC F1 | MSC EM | MSC NLL | Memory vectors | LME-S F1 | LME-S NLL |
| Hard reference | Original token embeddings, without softening | 90.9 | 88.1 | 0.074 | 101.1 | 3.4 | 12.257 |
| full (fixed update count) | HasMem, updates including policy updates, final checkpoint | 94.0 | 74.8 | 0.172 | 89.8 | 9.8 | 5.260 |
| Gaussian-input training | Gaussian inputs during training and hard initialization at evaluation | 93.6 | 58.4 | 0.250 | 87.9 | 8.7 | 5.481 |
| Fixed-ratio rule training ( ) | Rule-based training with action imitation and Controller at evaluation | 98.5 | 78.4 | 0.067 | 91.9 | 9.1 | 4.794 |
| Retention-based rule training ( ) | Highest-retention entry selection during training and Controller at evaluation | 97.7 | 73.7 | 0.099 | 91.9 | 9.5 | 5.065 |
| Configuration | Training intervention | NLL |
| Full HasMem | Full curriculum and all modules | 0.115 |
| No forced softening or target band | Remove forced softening and the target-band penalty | 0.621 |
| No forced softening | Remove forced softening | 0.571 |
| No target band | Remove the target-band penalty on non-KEEP prediction frequency | 0.285 |
| Frozen Writer without hinge | Freeze the warmed-up Writer and disable Writer hinge, retaining forward re-encoding | 0.488 |
| No Writer hinge | Disable Writer hinge, with an all-KEEP evaluation trajectory | 0.074 |
| Category | Setting | Default |
| Architecture | Global/shared feature dimension and Controller MLP hidden dimension | and |
| Reader and Global readout adaptation | Attention output projections in final layers, rank | |
| Added parameters and policy-phase trainable parameters | and | |
| Maintenance | Width adjustment and minimum body width | ( before rounding) and |
| KEEP-streak clipping and round-robin interval | and | |
| Post-write maintenance steps | for Qwen2.5-0.5B/1.5B, for Qwen2.5-3B/7B/14B and Mistral-7B |
| Rule target ratio | Readout | F1 | EM | NLL | Wrong right / right wrong | EM [95% interval] | Adjusted | |
| All enabled | 95.8 | 60.1 | 0.182 | Reference | — | — | ||
| No Reader | 95.0 | 58.2 | 0.224 | / | [ ] | 0.1702 | ||
| No Global | 95.0 | 58.2 | 0.234 | / | [ ] | 0.2471 | ||
| All enabled | 91.1 | 41.6 | 0.438 | Reference | — | — | ||
| No Reader | 90.7 | 40.5 | 0.565 | / | [ ] | 1.0000 | ||
| No Global | 90.5 | 40.5 | 0.588 | / | [ ] | 1.0000 |
| Readout at inference | F1 | EM | NLL | Wrong right / right wrong | EM [95% interval] | Adjusted |
| All enabled | 95.46 | 84.49 | 0.1123 | Reference | — | — |
| No Reader | 95.46 | 84.11 | 0.1274 | / | [ ] | 1.0000 |
| No Global | 95.25 | 83.36 | 0.1315 | / | [ ] | 0.1406 |