Designing a Local Long-Term Memory Plugin: Architecture and Early Implementation
\
Designing a Local Long-Term Memory Plugin: Architecture and Early Implementation
1. The Problem: Why Context Disappears Once a Session Ends
In AI coding tools and conversational development environments, one pain point keeps resurfacing: amnesia the moment a session ends. Conclusions, preferences, project constraints, workflow methods, and lessons learned from failures accumulate over hours or even weeks of collaboration, then get pushed out as the context window scrolls forward. The next conversation starts from scratch, with everything explained all over again.
There are usually three ways to address this. One is to keep expanding the context window, which is expensive and adds noise. Another is to stuff material into a retrieval store and recall fragments, which lacks structured accumulation. The third is to maintain a readable, editable, traceable memory document locally, with a plugin maintaining it automatically during sessions. This article covers the third approach: a local long-term memory plugin (early implementation) designed for highly customizable conversational environments.
Its positioning fits in one sentence: use edge compute to perform periodic memory management. All memory is stored as local documents, processing is handled by a local model, and users can inspect, edit, and roll back — no remote service required.
2. Why a Local Small Model Is Required
This is the most important engineering judgment in the early implementation, and it deserves a separate argument.
The plugin works by “assembling context + prompting the model to process it”: every time a memory write or summarization is triggered, the current memory context and the target fragment are concatenated into the prompt. This means the request prefix keeps changing as memory grows, so the prefix cache miss rate is close to 100%. With a pay-per-use remote large model, cost rises linearly with memory volume and trigger frequency, quickly becoming unacceptable.
A locally deployed small model in the 7B to 9B range is sufficient for this kind of task, for three reasons:
- Narrow task boundary. Memory organization is extraction, categorization, and rewriting rather than complex reasoning, and small models are stable enough here.
- Data stays in domain. Project constraints, internal processes, and failure lessons are often sensitive, and local processing inherently avoids the risk of sending them out.
- Controllable latency. Periodic summarization is a background activity, so throughput fluctuations in local inference do not block interaction.
The engineering recommendation is to assign a separate model endpoint to memory tasks, decoupled from the main conversation model, so they do not compete for VRAM and compute.
3. Four-Layer Memory Structure: Traceable at Every Level
The early implementation organizes memory into four layers, with one core design principle: every layer can answer where it came from.
- Raw layer: key fragments marked during sessions are stored in chronological order, unprocessed, keeping only locating information.
- Topic layer: raw fragments are clustered by topic, for example “build process,” “code style,” “API conventions.”
- Conclusion layer: reusable judgments and constraints are distilled from the topic layer, and each conclusion points back to the topic layer and the raw layer.
- Summary layer: a global view generated by periodic summarization, injected quickly at session start to control context size.
The direct benefit of this layering is that conflicts can be located. When two conclusions contradict each other, following the reference chain back to the raw fragments shows whether requirements changed or an early judgment was wrong, instead of having the model “guess” which one is newer.
A schematic data structure can be expressed like this:
{"id": "mem_0042","layer": "conclusion","topic": "build","content": "Full static checks must run before release","sources": ["topic_build", "raw_0311", "raw_0287"],"updated_at": "cycle-2024-06-11"}
4. Dual-Track Maintenance: Conversation Tracking and Periodic Summarization
Memory maintenance uses a dual-track approach to avoid the two extremes of “real-time writes are too noisy” and “catching up afterward is too late.”
Conversation tracking is the lightweight track. During a session, the plugin identifies content types worth keeping — conclusions, preferences, project constraints, workflow methods, lessons from failures — writes them to the raw layer first, and tags them with type and topic. No rewriting happens at this stage, so information stays lossless.
Periodic summarization is the heavyweight track. Triggered by a fixed number of turns or a time window, the local model reads new raw fragments and existing conclusions and does three things: merge synonymous entries, resolve conflicts, and compress the summary layer. It is advisable to keep a change log for the summarization process, recording three kinds of actions — added, modified, deprecated — for manual review.
Thresholds for both tracks should be configurable. Too low, and memory gets drowned out by chitchat; too high, and key constraints get missed. The early implementation exposes all of these parameters in the settings UI, leaving tuning to the user according to the project’s pace.
5. Plugin Architecture and Module Decoupling
The early implementation uses a three-part layout: core plugin + settings UI plugin + pure function modules.
- The core plugin mounts memory-related commands, intercepts session events, and schedules periodic tasks.
- The settings UI plugin provides visual configuration, including a UI entry script, a client script, and a package manifest.
- The pure function modules hold side-effect-free logic such as memory parsing, deduplication, sorting, and reference validation, making them easy to test in isolation.
The settings UI plugin must be loaded as a package, so a directory junction must be created at the dependency location in the config directory, or a copy placed there directly. This is the most error-prone step in the early implementation, especially in environments where paths contain spaces or permissions are restricted.
To enable it, append entries as a patch in the environment config file, declaring the core plugin and the settings UI plugin separately. Save, then restart the host environment. The whole process does not modify the host’s own code, so conflicts when upgrading the host are minimal.
6. Installation Paths and Troubleshooting Common Issues
The recommendation is to place files manually first, get the chain working, and only then consider automation.
- Symptom: no entry in the settings UI. Check that the UI plugin exists in the dependency directory as a package structure, not just in the plugin directory.
- Symptom: memory commands are not registered. Confirm the indentation and identifiers of the entries in the config file, and whether the restart actually completed.
- Symptom: poor summarization quality. First reduce the number of fragments per summarization pass, or switch to a slightly larger local model.
- Symptom: context bloat. Shorten the summary layer and raise the merge threshold for the conclusion layer.
For automation, the installation instructions can be handed directly to a running session, and the model assistant can complete the download, placement, and enablement step by step, but the config and restart result still need manual verification afterward.
7. Boundaries of the Early Implementation and How to Contribute
The boundaries should be stated plainly: the author of the early implementation has not systematically studied the relevant scripting language, nor completed formal testing over long-horizon data accumulation. The management workflow was mainly refined through repeated iteration in a highly customizable environment, drawing on engineering experience from other languages. Its current state is therefore “it runs, the structure is clear, it can be modified” — not a validated, stable solution.
If you run into duplicate entries, broken references, or summarization drift, the most valuable ways to contribute are submitting reproducible problem descriptions, adding test cases for the pure function modules, or proposing improvements to the conclusion-layer strategy. The quality of a memory system ultimately depends on its maintenance rules, not model size — which is also why the early implementation exposes all rules as configurable items.
