Wink Pings

Long-Term Memory for Agents: The Nine Modules Are Elegant, but Don't Rush to a Vector Database

@meow2149 breaks down the memory mechanisms of products such as Codex, Claude Code, and OpenClaw into nine modules. The comments are even more worth reading: write quality, summary size, and cache prefix determine whether the system is usable far earlier than swapping in a vector database.

Building long-term memory for an Agent can easily turn into a database project. You add tables, indexes, vectors, and task queues, only to find that what actually ruins the experience is dirty writes, overly long summaries, and bringing things that shouldn't be there into the start of every session.

An Agent's context window per session is limited, and long-term memory is responsible for bringing back preferences, facts, and task experience from across sessions. X user @meow2149 recently went through the memory mechanisms of products such as Codex, Claude Code, OpenClaw, and Hermes Agent, and presented a nine-module design: memory admission, tiered memory, dual-path writes, active retrieval, background consolidation, temporal memory and forgetting, isolation and security governance, procedural memory, and storage architecture. The original tweet included a structural diagram.

九模块 Agent 记忆系统设计

What this design really puts effort into is controlling how memories enter, how they are retrieved, and how they expire; storing more is just a side effect. For example, L0 holds core memories and a navigation index, L1 holds structured facts and task experience, and L2 keeps raw session and tool-call records. New sessions load only permission-filtered L0 by default, retrieve L1 on demand, and use L2 to trace back evidence. Core memory has a fixed token budget to prevent the always-on context from expanding with the total volume of memory. This detail is closer to the actual cost than 'how many memories are supported.'

The write path is also split into synchronous and asynchronous. When the user explicitly asks to save, correct, or delete something, it is submitted synchronously; ordinary sessions are extracted asynchronously by a background Worker. Each memory has an ID, source, scope, version, and status. Conflict handling identifies conflicts by subject, attribute, applicable conditions, and valid time; if there is not enough evidence, it keeps a disputed state. Deletion uses a Tombstone: first block reads and context injection, then asynchronously clean up indexes, caches, and derived data. There is an easily overlooked boundary here: deletion constraints must cover raw evidence fragments and derived relationships; otherwise, old tasks may write the same memory back under a different ID.

The background consolidation part borrows ideas from Sleep-time Compute and OpenClaw's Dreaming. An independent Worker performs merging, reflection, promotion, and demotion. Promotion depends on evidence and reuse needs, not on recall count. The reason is very practical: recall feedback forms a loop—the same memory is repeatedly extracted and consolidated, making it look as if new evidence has been obtained. OpenClaw's documentation calls this the recall feedback loop, and structurally prevents content that has already been injected from being extracted again as new memory.

Temporal memory uses a bitemporal model. Valid Time is the interval during which a fact is valid in reality; Transaction Time is the interval during which the system records, supersedes, or retracts it. Querying current facts, historical facts, and the information the system had at a past point in time are three different questions. Deletion and revocation are based on the current state at read time. This distinction may be abstract for ordinary users, so consider a daily scenario: the user said last year that 'the project uses Postgres' and this year changed it to 'uses SQLite.' The system cannot treat both as preferences, nor can it pretend during an audit of old decisions that the new fact had always existed.

One sentence in the security and permissions section deserves to be called out separately: factual credibility and instruction execution permission are separated. Derived memories inherit the original source category and permission constraints; unconfirmed external statements cannot directly become user preferences, and memory content cannot raise its own instruction permissions. This guards against persistent memory poisoning. If Prompt Injection can only affect one turn of conversation, the damage is limited; once it is written into long-term memory through memory extraction, background consolidation, and cross-session recall, it becomes a persistent problem.

Procedural memory distills validated task experience into reviewable Skills, uses Git to manage versions, and uses SQLite to manage active versions, enabled status, scope, and authorization. File changes do not directly change the Skill version currently used by the Agent, avoiding conflicts between background organization and online execution.

The storage architecture is local-first. SQLite is the single source of truth for memory records, permissions, and active status; Markdown is a rebuildable view; FTS5 handles BM25 full-text search; sqlite-vec handles vector search; RRF fuses the two ranked lists; a SQLite-backed Task Queue runs background jobs; and Git manages Skill files. The benefit of this combination is that you don't need to separately deploy a vector database, search engine, and message queue. For personal projects and small teams, operational complexity drops by an order of magnitude.

The comments bring the topic back down to earth. One commenter said that sqlite-vec is sufficient in practice, and unless the scale reaches tens of millions, there is no need to bring in a vector database. Another commenter was more direct: for personal experimentation, don't use a vector database in the early stage; keep L0 under 1,000 characters, and pure file search will hold up for a long time. Someone else warned that the worst thing when building memory is changing the prefix midway—once you touch it, the cache is invalidated and you burn through your quota twice as fast. These lessons aren't advanced, but they're expensive.

On layering, one commenter split memory into one core file plus more than a dozen scenario files, and when starting a new task, first reads the corresponding one by scenario. Before splitting, contexts often got mixed, and over time rules from other scenarios were carried over. Another commenter took a more restrained approach: first do only two things—SQLite stores the single source of truth, and at the start of a session read a summary of no more than 800 characters according to scenario. A single task context is 60,000 tokens; reloading everything once triples the cost, while the summary hit rate is actually higher. The boundary is the number of projects: once scenario files reach a dozen or so, choosing which one to read itself becomes a new problem, and you have to route by task type first.

Summary maintenance has pitfalls too. One commenter added: don't let the main Agent rewrite the summary every time, because it will copy the previous version in as fact. Instead, at task wrap-up append only three lines: what decision was changed, which path was rejected, and which file to look at first next time. If it exceeds 800 characters, replace the whole paragraph rather than patching locally.

There are also voices against overdesign. One commenter believes that embedding-based retrieval plus exponential decay is the most stable and easiest to maintain. When there are many large documents, embed them by logical paragraph; the biggest drawback is that ingestion is a bit expensive. The two views correspond to different stages: one talks about long-term maintenance cost, the other about retrieval effectiveness.

Cross-tool collaboration is another dimension. One commenter is building a local governance foundation for multi-AI collaboration and mentioned that when the workflow expands from the long-term memory of a single Agent Harness to Codex, Claude, and Gemini jointly advancing the same project, the ledger cannot be confined inside just one Harness. They added three boundaries: share the ledger across tools, avoiding locking memory in a Harness's private directory; split status evidence into published, retrieved, and actually read back; keep execution state and experience layer lightweight first—progress stop points, WIP protection, and after interruption only filling in unfinished steps should be handled by a deterministic state machine, without spinning up an extra model to do Dreaming.

多 AI 协作的本地账本闭环

This nine-module design is suitable for the cognition and knowledge accumulation of a single Agent; cross-tool collaboration still requires a deterministic project ledger and a handoff protocol. Only when the two are layered together does it come close to the complete problem of 'multiple Agents working on the same project.'

Some commenters raised the question to a higher level: the essence of intelligence is information compression, and memory is part of that. Others said the most important thing is still the separation between global memory and personal memory, and the balance between personal assistant and task layers. These judgments don't provide implementation plans, but they explain why the most expensive parts of the nine modules are admission, consolidation, and forgetting.

Reference links from replies to the original post:

If you remember only one sentence: what is truly hard about Agent long-term memory is write quality, compression strategy, deletion, and permissions. Retrieval can be optimized later; memory admission and summary governance are best in place on day one.

发布时间: 2026-11-29 14:30