
HasMem: Hard-Origin Adaptively Softened Memory for Long-Term LLM Agents
HasMem (Hard-Origin Adaptively Softened Memory) is a proposed memory architecture for long-term LLM agents that decouples capacity allocation from readout by using frozen hard-prompt embeddings as a verifiable initial state, then adaptively resizing entries via a Writer/Reader/Global controller system. On a 535-question reconstruction probe derived from the Multi-Session Chat (MSC) dev split it reaches 95.3 lexical F1 (+4.4pp over baseline), and on all 500 LongMemEval-S questions it raises local lexical F1 from 3.4 to 8.9 while cutting answer negative log-likelihood from 12.257 to 5.274, outperforming rule-based re-encoding baselines by 8.0–23.6 EM percentage points across several configurations.
What it claims
HasMem stores each past record for a frozen LLM as a variable-width continuous "slot" that starts as the record's exact token embeddings. A learned controller then shrinks or expands slots over time. If no slot is ever resized, the model's logits are provably identical to plain text-in-context retrieval (the "hard reference"). The paper presents this as a safe starting point that softening can only move away from deliberately.
The catch the summary omits: exact match is lower than the hard reference on both evaluations. The gains are in lexical F1 and answer NLL. The 8.0–23.6 EM wins are against rule-based re-encoding at matched budgets, not against the unsoftened baseline.
How it works
- Write. A new record's body tokens are embedded with the frozen embedding table, so slot width equals token count. Role-framing tokens stay as fixed token IDs around the slot.
- Soften. Each time a new record arrives, at most one entry is revisited, chosen round-robin. A Controller decides KEEP, SHRINK or EXPAND. It is a two-layer Tanh MLP over the slot features, the latest record's features, age, current retention K/L, step and KEEP streak.
- Width changes by ⌈ηK⌉ and stays within [K_min, original length].
- The final layer is zero-initialised, and ties resolve to KEEP.
- Re-encode. On a width change, the Writer applies adaptive average pooling (to shrink) or linear interpolation (to expand), then adds a zero-initialised residual conditioned on Global state.
- Retrieve. Entries are ranked by cosine similarity between the mean slot vector and the mean question embedding. The top-k are spliced in arrival order. Because softening changes the retrieval keys, it can change which entries get retrieved.
- Read.
- Reader is a LoRA on selected attention output projections.
- Global is a gated GRU state across records that drives a hypernetwork-generated LoRA up-projection.
- Both are gated off until the first width change occurs.
- Timing. Widths are decided from history before the question arrives.
flowchart LR
R[New record] --> E[Frozen embeddings]
E --> B[Soft Bank]
B --> C{Controller}
C -->|KEEP| B
C -->|SHRINK / EXPAND| W[Writer re-encode] --> B
Q[Question] --> T[Cosine top-k]
B --> T --> L[Frozen LLM + Reader/Global LoRA]Training keeps the backbone W0 frozen and uses QA supervision from the MSC training split, with roughly a six-hour wall-clock budget.
- Objective: answer NLL, plus a hinge on NLL damage relative to the hard reference, plus a cost on cumulative framed positions.
- Controller labels: come from bounded search for SHRINK-containing sequences that cut positions within an NLL tolerance.
Evidence
The default backbone is frozen Qwen2.5-7B-Instruct with k=8.
- MSC-derived probe (535 questions, 268 owners): F1 95.3, which is +4.4pp over the hard reference, using 93.6% of the hard reference's framed positions.
- Learned vs rule re-encoding: six configurations at mean per-entry retention of about 0.83–0.91 beat rule-based re-encoding by 8.0–23.6 EM, with approximately matched per-question body budgets.
- Global ablation: with parameters and positions fixed and a rule target ratio of 0.75, Global raises EM by 2.24pp. This passes an owner-level exact paired test (Bonferroni p=0.0146 over eight comparisons).
- LongMemEval-S (all 500 questions): local lexical F1 rises from 3.4 to 8.9, and answer NLL falls from 12.257 to 5.274. Both sets of absolute F1 values are very low.
How to use it
Code is at https://github.com/ZihongHe/HasMem. The page gives:
- no install or run commands
- no licence
- no release of trained weights
You need the frozen Qwen2.5-7B-Instruct backbone; cross-family runs used Mistral-7B-Instruct. Defaults are in the paper's Tables G1 and E1, and the main run uses seed 2026091331.
Limits
- EM drops versus the hard reference on both datasets. If your task needs exact answers, softening is a regression.
- The MSC probe is synthetic and easy. It is built from templated tag/value records, with at most 7 records per owner, so k=8 retrieves everything and retrieval is not exercised. A plain tag-lookup baseline scores 100 F1/EM.
- The probe is the development split, used for configuration and checkpoint selection. The test split is held out, and no test results appear in the fetched text.
- Costs are unmeasured. Latency and GPU memory are not reported ("depend on implementation"). Storage also includes module parameters and metadata on top of slot vectors.
- The Global significance result covers one setting (rule ratio 0.75).
- The fetched text truncates partway through the setup. Mistral cross-family numbers and appendix comparisons with external memory systems were not visible.
Organisations named here
- LongMemEval-S
- Multi-Session Chat
Technologies named here
- Transformer
Techniques named here
- HasMem
- Hard-origin embeddings
- Controller
- Writer
- Reader
- Global
- Rule-based re-encoding
Related in research



