Preface

DeepSeek Harness (DSH) includes a built-in chat agent, but each new session starts from scratch. The dsh-memory-amem plugin injects A-MEM-style long-term agent memory into DSH. Every user message is captured as a structured note, automatically linked to existing memories through LLM-driven evolution steps, and reinjected into the system prompt in each turn, allowing the model to recall prior conversations.

Core Features and Architecture

This plugin implements the core A-MEM pipeline and combines DSH session events with system prompt injection mechanisms to build a complete memory loop.

Workflow

The memory engine operates in six steps:
1. Admission gate: First, a rule-based filter (such as sensitive words and oversized text blocks) plus semantic deduplication and trust score checks are used to filter noise. Messages that do not meet the requirements terminate the flow immediately.
2. Analyze content: Use an LLM to extract keywords, a one-sentence context, and tags from the message. If LLM output is unavailable, fall back to the TF algorithm.
3. Retrieve neighbors: Retrieve from the stored note corpus by hybridizing BM25 (k₁=1.5, b=0.75) and TF-IDF cosine similarity, returning Top-K relevant notes.
4. Decide evolution: The LLM selects one of NO_EVOLUTION, STRENGTHEN, UPDATE_NEIGHBOR, or STRENGTHEN_AND_UPDATE based on the analysis and retrieval results.
5. Apply evolution: STRENGTHEN increases links and tags; UPDATE_NEIGHBOR rewrites the context and tags of related notes.
6. Persist notes: Notes are written to ~/.dsh/memory-amem/notes/*.json, flushed every 5 seconds, and the index is reloaded on the next initialization.

Hybrid Retrieval and Defense

  • Hybrid retrieval: Combining BM25 and TF-IDF, with strategies such as entity boosting, significantly improves recall in multi-hop reasoning scenarios.
  • Prompt injection defense: The plugin includes built-in defenses against system prompt injection, ensuring safe injection of memory content.

Model-facing Tools

The plugin exposes four tools to DSH’s model:
* memory_search: Search the memory store.
* memory_add: Manually add a memory.
* memory_recent: Get recent memories.
* memory_stats: Memory store statistics.

Installation and Activation

The plugin follows DSH’s community plugin standard model. During installation, the --profile web parameter must be specified so that the dsh plugin command reads package configuration and injects it into the DSH main process and Web GUI.

dsh plugin --profile web add

LoCoMo Benchmark Evaluation

The author evaluated the plugin on the LoCoMo dataset (1 conversation × 199 QA pairs), using deepseek-chat and deepseek-reasoner as downstream models.

Evaluation Results (v0.2.0):

Category Description deepseek-chat deepseek-reasoner
1 Single-hop facts 21.9% 25.0%
2 Multi-hop reasoning 45.9% 37.8%
3 Temporal/counterfactual 0.0% 7.7%
4 Yes/No 44.3% 47.1%
5 Open-ended 4.3% 4.3%
Overall Overall 28.6% 29.1%

Key observations:
* Using smaller DeepSeek models can surpass GPT-4’s closed-book benchmark performance (about 37%).
* The multi-hop reasoning category benefits from improved BM25 recall and entity weighting, improving from 0% to 46%.
* Category 3 (Temporal/counterfactual) and Category 5 (Open-ended) still perform poorly. Failures in Category 3 are mainly due to the relative nature of LoCoMo annotated answers (such as “the week before 9 June 2023”), while the retriever lacks date arithmetic capabilities.

Use Cases and Considerations

  • Use cases: DeepSeek Harness scenarios requiring long-context retention, multi-turn dialogue memory, and reasoning based on historical information.
  • Considerations: This plugin runs with the permissions of the current DSH process. It is recommended to review the source code and license (MIT) before installation. Because an admission gate exists, certain specific types of conversations (such as greetings only) may not be captured as structured memories.