Introduction¶
The core philosophy of DeepSeek Harness (DSH) is “everything is a plugin.” When building agents based on DSH, cross-session persistent memory is a common pain point. Traditional vector-retrieval solutions often rely on external databases or require additional model calls, which increases system complexity and latency.
The dsh-long-term-memory plugin aims to solve this problem. It provides DSH with hierarchical and deterministic long-term memory capabilities. It stores data in JSONL files, uses a CJK-aware BM25 algorithm for deterministic recall, and automatically injects memory summaries before each request assembly. The plugin does not depend on vector databases, does not require additional model calls, and does not require a self-hosted SQLite instance or external server. It is fully composed based on existing DSH extension points.
Core Features¶
This plugin provides the following core capabilities:
- Three-tier hierarchical storage: Memory is divided into three scopes, each using one JSONL file.
user: User profile information (name, role, preferences).global: Cross-project facts and decisions.workspace: Project-specific memory.
- Deterministic recall: Retrieval uses the BM25 algorithm. Chinese is matched by character bigrams; Japanese and Korean follow a similar approach; English is matched by words. Results are explainable and replayable.
- Automatic injection and calibration: Before each request assembly, memory summaries are injected via
systemPrompt.context(). The injected block is wrapped with<long_term_memory>tags, clearly stating the source and uncertainty, guiding the model to judge relevance and ignore irrelevant content. - Safety mechanisms:
- Threat scanning: Lightweight pattern detection is applied to written content and injection snapshots. If a threat is detected, the write is rejected or replaced with a placeholder.
- Write guardrails: Atomic writes are performed using temporary files plus rename, combined with cross-process file locks to prevent data corruption.
- Correction loop: A
memory_correcttool is provided to correct outdated facts. Old records are marked assupersededand are automatically excluded from subsequent recall and injection.
Installation and Enabling¶
Run the following commands in the plugin directory:
cd dsh-long-term-memory
dsh plugin --profile web add .
After installation, dsh web needs to be restarted.
⚠️ Note: The
dsh plugin addcommand has previously broken relative paths inlink:(causing related plugins to be moved out of bundles). This plugin has been fixed using an absolute pathlink:/Users/.... Do not rely on relative paths for new plugins.
Usage¶
The plugin provides two types of usage entry points: model tools and slash commands.
Model Tools¶
The model can read and write memory through registered tools:
memory_write(content, scope?, tags?): Write a memory entry.scopecan beuser/global/workspace, defaulting toworkspace.memory_recall(query, scope?, limit?): BM25 retrieval, returning scored matching records.memory_list(scope?, limit?): List recent memories by update time.memory_get(id): View a single memory entry.memory_forget(id, scope?): Delete a memory entry by ID.memory_correct(claim, truth, evidence?): Record a factual correction.
Slash Commands¶
Users can directly use slash commands in the input box (without going through the model):
/memory list [user|global|workspace|all]: List recent memories./memory search <query>: BM25 retrieval./memory get <id>: View a single memory entry./memory forget <id>: Delete a single memory entry./memory export [|markdown]: Export the memory bundle.
Configuration¶
Behavior can be controlled by overriding cordis.patch.yml or settings.yaml. Below are the key configuration items:
- Injection strategy (
injectContext):recent(default): Inject a few of the most recent memory entries from each scope per turn.full: Inject all memories (subject to the character budget).off: Disable automatic injection.
- Tag filtering (
injectTags): Inrecentmode, inject only memories that carry specified tags (such asdecision,constraint), filtering out trivial entries. - Write approval (
requireApprovalForWrite): Optional. When enabled, writes require human confirmation through the DSH approval extension point before completion. - Threat scanning (
scanThreatsOnWrite): Enabled by default. Performs lightweight threat pattern detection on written content. - Character budget (
charLimit): The maximum number of characters per scope. When exceeded, automatic compression is attempted first, and the write is rejected if it still fails.
Technical Details and Cautions¶
- Synchronous injection: The DSH prompt assembler calls relevant functions synchronously. If injection rendering follows an asynchronous path (returning a Promise), it will cause a crash. The plugin has changed all injection rendering to a synchronous path (with asynchronous store prewarming before the first assembly).
- Zero external dependencies: The plugin internally implements the BM25 tokenizer and JSONL read/write logic, and does not depend on external vector databases.
- Conservative threat scanning: The scanning patterns are intentionally narrowed to detect only instruction override/system prompt leakage/role hijacking/markup injection, avoiding false positives on normal notes. Injection snapshots use placeholders rather than directly deleting the original content, preserving it for user handling.
- Storage paths:
user:$DSH_HOME/dsh-memory/user.jsonlglobal:$DSH_HOME/dsh-memory/global.jsonlworkspace:<workspaceRoot>/.dsh/memory.jsonl
Appropriate Scenarios¶
This plugin is suitable for scenarios that require cross-session memory, user preference management, historical decision tracing, and strict data safety controls in DSH agents.
- Memory accumulation: During conversations, the model uses
memory_writeto persist important information. - Deterministic recall: When the model needs to query historical constraints or facts, it uses
memory_recallto obtain highly relevant results. - Knowledge base management: Use
/memory listand tag filtering to organize project documentation or user profiles.