TokMem: One-Token Procedural Memory for Large Language Models

AuthorsZijun Wu, Yongchang Hao, Lili Mou

2025

TL;DR

TokMem encodes reusable task procedures into single trainable memory tokens, letting a frozen LLM match or beat LoRA and RAG (e.g., 67.0 ROUGE-L vs 66.5 Replay Memory on 1,000 SNI tasks).

SharePost on XLinkedIn

Read our summary here, or open the publisher PDF on the next tab.

THE PROBLEM

Long prompts and RAG still waste context and compute

Prompting and RAG rely on long textual instructions that must be reprocessed for every query, increasing quadratic self attention cost and truncation risk.

On Super Natural Instructions with 1,000 tasks, Sentence BERT retrieval accuracy drops to 79.7%, causing noisy procedure selection and degraded task performance for RAG style systems.

HOW IT WORKS

TokMem: One token procedural memory

TokMem introduces a Memory Bank of trainable memory tokens and uses memory routing plus conditional generation to encode each reusable procedure into a single token.

You can think of TokMem like a CPU instruction cache: each memory token is a compact opcode that triggers a full multi step skill without re reading a long prompt.

This renormalization stabilized memory bank lets TokMem chain procedures at inference, add new skills continually, and avoid context window bloat that plain prompting or RAG cannot escape.

DIAGRAM

TokMem inference flow for multi step procedures

This diagram shows how TokMem routes queries to memory tokens and chains procedures during inference, as described in Section 2.3.

DIAGRAM

TokMem training and evaluation pipeline

This diagram shows how TokMem is trained on procedure response pairs and evaluated on SNI and APIGen benchmarks.

PROCESS

How TokMem Handles a Query with Procedural Recall

  1. 01

    Textualized context engineering

    TokMem starts from a standard Transformer input sequence and avoids expanding prompts, replacing long textual instructions with compact memory tokens from the Memory Bank.

  2. 02

    TokMem procedural memory as a token

    TokMem concatenates the query with a memory token and response tokens, training the Memory Bank embeddings via next token prediction while keeping the backbone frozen.

  3. 03

    Inference with memory tokens

    TokMem uses memory routing to select the most probable memory token for the query, appends it, and runs conditional generation, optionally chaining multiple procedures.

  4. 04

    Stabilizing new memories

    TokMem applies renormalization to newly added memory embeddings, aligning their norms with existing tokens to prevent routing domination and catastrophic forgetting.

KEY CONTRIBUTIONS

Key Contributions

  • 01

    One token procedural memory

    TokMem encodes each reusable task procedure into a single trainable memory token in a Memory Bank, enabling constant size overhead even across 1,000 SNI tasks.

  • 02

    Frozen backbone with modular skills

    TokMem keeps the LLM backbone frozen and stores procedural knowledge entirely in memory tokens, supporting continual learning without degrading existing procedures.

  • 03

    Superior recall and compositional tool use

    TokMem achieves up to 67.0 ROUGE L on 1,000 SNI tasks and 99.1 tool selection F1 on APIGen, surpassing RAG and LoRA fine tuning with far fewer parameters.

RESULTS

By the Numbers

ROUGE L Avg

67.0

+0.5 over Replay Memory on Llama 3.1 8B (66.5)

Routing Accuracy 1000 tasks

97.5%

+17.8 points vs Sentence BERT retriever at 79.7%

Tool Selection F1 Avg

99.1

+1.0 over Fine Tuning on Llama 3.1 8B (98.1)

Trainable Params TokMem 8B

0.20M

vs 3.41M for LoRA fine tuning on Llama 3.1 8B

On Super Natural Instructions (atomic recall) and APIGen (compositional tool use), TokMem demonstrates high quality procedural recall and routing. These results show TokMem can rival or exceed LoRA and RAG while using an order of magnitude fewer trainable parameters.

BENCHMARK

By the Numbers

On Super Natural Instructions (atomic recall) and APIGen (compositional tool use), TokMem demonstrates high quality procedural recall and routing. These results show TokMem can rival or exceed LoRA and RAG while using an order of magnitude fewer trainable parameters.

BENCHMARK

Atomic recall performance on SNI (ROUGE L, Llama 3.1 8B, 1,000 tasks)

ROUGE L score on Super Natural Instructions after learning 1,000 tasks.

BENCHMARK

Compositional tool use on APIGen (Tool Selection F1 Avg, Llama 3.1 8B)

Average tool selection F1 across 2–4 calls on APIGen.

KEY INSIGHT

The Counterintuitive Finding

TokMem with only 0.20M trainable parameters on Llama 3.1 8B reaches 99.1 tool selection F1, beating LoRA fine tuning with 3.41M parameters.

This is surprising because parameter efficient fine tuning is expected to be strictly stronger than a few learned embeddings, yet TokMem’s routed tokens capture richer procedural control.

WHY IT MATTERS

What this unlocks for the field

TokMem makes it practical to attach thousands of reusable procedures as single tokens to a frozen LLM, with high routing accuracy and minimal forgetting.

Builders can now grow modular skill libraries, chain procedures like tools, and personalize behavior via user specific memory banks without retraining or blowing up context windows.

~12 min read← Back to papers

Related papers

BenchmarkAgent Memory

Active Context Compression: Autonomous Memory Management in LLM Agents

Nikhil Verma

· 2026

Focus Agent adds start_focus, complete_focus, a persistent Knowledge block, and an optimized Persistent Bash plus String-Replace Editor scaffold to actively compress context during long software-engineering tasks. On five hard SWE-bench Lite instances against a Baseline ReAct agent, Focus Agent achieves 22.7% token reduction (14.9M → 11.5M) while matching 3/5 = 60% task success.

Questions about this paper?

Paper: TokMem: One-Token Procedural Memory for Large Language Models

Answers use this explainer on Memory Papers.

Checking…