Plugin-Based Long-Term Memory Management with Local Small Models
This article presents a plugin-based approach to long-term memory management for AI coding assistants. It explains why local 7B–9B open-source models are used for memory extraction and summarization, describes a four-layer memory structure designed for traceability and auditability, outlines installation and integration steps, and covers the memory write and maintenance workflow. It also discusses engineering considerations such as cost control, privacy, conflict handling, current limitations, and future improvements including vector retrieval, cross-project isolation, and backup strategies.
Plugin-Based Long-Term Memory Management with Local Small Models
1. Background and Design Motivation
In intelligent coding tools built on large language models, conversation context is usually one-off: once a session ends, information such as project constraints, coding preferences, and debugging lessons is destroyed with the context, and users must restate it in the next interaction. This model creates three typical pain points:
- High repeated communication cost. Users need to explain the same project background, technology choices, and code conventions to the model again and again.
- Experience cannot accumulate. Process methods and lessons learned during debugging lack a structured place to be stored.
- Cloud-based memory is costly and raises privacy concerns. If a paid cloud model is used to maintain memory, the full memory context must be carried in every new request. Cache hit rates are extremely low, and token consumption is high. At the same time, storing memory data in the cloud raises concerns about privacy and auditability.
The approach discussed in this article is to make memory management a pluggable plugin that runs in a highly customizable local coding assistant. It uses edge compute—locally deployed open-source small models in the 7B–9B range—to handle memory extraction, summarization, and updates, while memory documents are stored locally throughout the process. The core idea can be summarized as “assemble context + prompt the model to process it”: during a session, the plugin captures content worth retaining, concatenates the current memory document as context, prompts the local model to make judgments and rewrite the content, and then writes the result back to local files.
The cost issue deserves special attention. Because every memory-processing step carries the full current memory as context, cache hits are almost impossible. If a token-billed paid model were used, costs would expand rapidly. However, tasks such as memory extraction, classification, and summarization do not require strong reasoning capabilities, and local small models are fully adequate. This is the core value of using edge compute for periodic memory management.
2. Memory Structure: Four Layers with Traceability at Every Level
Memory is not a pile of scattered notes but a structured document tree. This approach divides memory into four layers, each of which can be traced upward to its source session, ensuring that memory is searchable, auditable, and rollback-capable.
Raw Entries. This is the bottom layer of memory and stores raw fragments captured from sessions, along with timestamps, session identifiers, and the reason for capture—whether it is a conclusion, preference, constraint, or debugging lesson. This layer is append-only and is never modified. It is the traceability basis for all higher layers of memory.
Topic Memory. The local model periodically classifies, merges, and deduplicates raw entries to form memory paragraphs organized by topic, such as “project build constraints,” “user code style preferences,” and “debugging methodology.” Each topic memory retains references to raw entries, preventing the model from “tampering with history” during summarization.
Summary. This layer compresses topic memory at a higher level into a short “user profile + project profile” that serves as fixed context injected at the start of each session. This layer directly determines the experience of the assistant “understanding you better the more you use it.”
Meta. This layer records the memory document’s version, update time, statistics, and configuration items, such as summarization intervals, maximum length per memory entry, and topic types to ignore. It supports subsequent maintenance, backup, and rollback.
The benefit of this layered design is separation of responsibilities: the raw layer ensures traceability, the topic layer ensures organization, the summary layer ensures injectability, and the meta layer ensures operability. If any summary memory becomes inaccurate, the original entries can be traced back through the reference chain and corrected manually.
3. Installation and Integration
The plugin is provided as two relatively independent modules: the memory core plugin handles session listening, memory extraction, and periodic summarization; the settings UI plugin handles parameter configuration and visual inspection of memory documents. The integration steps are as follows:
Place the plugin files in the plugin directory of the coding assistant profile. This includes the core plugin script, the settings UI directory (with its entry script and dependency manifest), and several pure-function modules. Logic such as memory deduplication, summarization, and formatting is extracted into pure functions to facilitate unit testing and reuse.
Mount the settings UI directory under the profile’s
node_modules. On Windows, a directory junction link is recommended to avoid synchronization issues caused by copying:mklink /J "your-profile\node_modules\mm-settings" "your-profile\plugins\mm-settings"
On other platforms, the directory can be copied directly or a symbolic link can be used.
Enable both plugins in the profile’s patch configuration file, for example:
insert:- id: motion-memoryname: ./plugins/motion-memory.js- id: mm-settingsname: mm-settings
Restart the coding assistant. The memory tools (the toolset named with
memory_*) and the settings UI then take effect.
In addition to manual installation, the above steps can be sent directly to a running coding assistant session, allowing the model assistant to complete the download, placement, and enablement on the user’s behalf. This also serves as a test of the plugin’s capabilities.
4. Memory Write and Maintenance Workflow
The memory lifecycle consists of three stages:
In-session extraction. During a conversation, the plugin identifies content worth retaining. Typical categories include conclusions (technology choices, finalized plans), preferences (naming style, commenting habits), project constraints (dependency versions, deployment environment limitations), process methods (build and release steps), and debugging lessons (error symptoms and solutions). Identification is driven by prompt engineering: the plugin assembles “current memory + recent conversation” as context, prompts the local model to determine whether there are new or revised entries, and outputs structured memory entries.
Periodic summarization. Based on a configured time interval or entry-count threshold, the plugin triggers a periodic summarization. The local model classifies and merges raw entries and updates topic memory and summary memory. Summarization follows a strategy of “adding references only and not changing the original text,” reducing the risk of information distortion.
Conflict and expiration handling. When a new entry conflicts with existing memory, the plugin tends to retain both and mark the conflict for the user to adjudicate in the settings UI, rather than letting the model decide on its own. Entries that have not been referenced for a long time can be marked for archiving and moved into an archive file after user confirmation.
5. Engineering Considerations and Future Directions
First, model selection. The core of memory tasks is information extraction and rewriting, not complex reasoning, so local small models are sufficient. Paid models should not be used; otherwise, context cache misses will lead to uncontrolled costs.
Second, privacy and controllability. Memory documents are all local plaintext files. Users can view, edit, back up, or delete them entirely at any time. This better meets the security audit requirements of enterprise environments than black-box cloud-based memory.
Third, current limitations. This approach is an initial release (the author calls it the “initial version”): it has not yet undergone systematic testing with long-term data accumulation, and some implementation details may not be robust enough. Future directions worth improving include vector retrieval for memory entries to reduce injection length, cross-project memory isolation, periodic backup based on object storage, and automated evaluation of summarization quality.
Overall, this approach validates a pragmatic path: use edge compute to handle high-frequency, low-complexity memory maintenance tasks; use a clear layered structure to ensure memory is traceable and correctable; enable the coding assistant to truly “understand you better the more you use it”; and keep both cost and privacy local. Developers interested in contributing are welcome to join and help make the memory workflow more robust.
