Introduction¶
When used across sessions, DeepSeek Harness (DSH) agents often lack the ability to reuse historical experience, causing them to repeatedly solve the same problems. The dsh-self-memory plugin automatically records session traces and solutions, provides offline retrieval and closed-loop write-back capabilities, and helps agents directly apply past experience in subsequent conversations.
Prerequisites¶
Before using this plugin, ensure the following environment requirements are met:
- Node.js version >=22
- DSH version @deepseek-ai/dsh 0.1.x
Install and Enable¶
Install the plugin from a local directory. Hot mounting is supported.
dsh plugin --profile web add <本目录>
After installation, verify the plugin status with the following command:
selfmem_status
The response should include information such as plugin=v0.3.0. After code updates, you can use dev_reload_package dsh-self-memory or restart DSH to complete the setup.
Core Capabilities¶
The plugin mainly addresses the following five issues:
- Multi-keyword relevance: Weighted keyword matching improves retrieval relevance.
- Detail suppression to enhance generalization: When recording, it automatically generates
abstractProblem; during retrieval, it matches both the raw text and the generalized text. - Fast retrieval over large case sets: It uses an inverted index to filter candidate sets and supports large-scale records.
- Conflicting results under different preconditions: Record-level
preconditionsand solution-levelappliesToandconflictsWithsupport precondition-based filtering and conflict annotation. - Unified keyword normalization: It includes a built-in synonym table, and retrieval and storage use a unified normalization path.
Usage¶
The plugin completes closed-loop memory management through a series of tool commands.
Automatic injection and daily closed-loop¶
The plugin enables automatic capture and automatic injection by default. After each user message is sent, the system automatically retrieves historical solutions and injects the context via a <selfmem_memory> fence. When solving new problems, the agent should follow the workflow: “Check records first → If found, try it → Record the root cause of success/failure → If not found, solve independently → Finally write back”.
Command Tools¶
selfmem_status: View plugin status and scale statistics.selfmem_search: Retrieve existing solutions, withcontextprecondition filtering.selfmem_record: Record or append solutions; supports multiple solutions, preconditions, and keyword weights.selfmem_hit/selfmem_fail: Mark a solution as successful or failed and record the root cause.selfmem_import: Import solutions from external sources.selfmem_trace: View automatically captured session traces.
Usage Examples¶
Record a solution with preconditions:
selfmem_record {"problem":"断网时如何安装插件","solution":"解压本地包 → dsh plugin add <目录> → pnpm install → dev_install_package 热挂载","keywords":{"plugin":1,"network":0.6},"appliesTo":{"network":"no"}}
Sample precondition-aware retrieval:
selfmem_search {"query":"如何识图","context":{"model_vision":"no"}}
Configuration¶
You can adjust plugin behavior by overriding the profile’s cordis.patch.yml.
| Config Key | Default Value | Description |
|---|---|---|
autoRecall |
true |
Whether to automatically retrieve and inject historical solutions for each user message |
recallBudget |
600 |
Token budget for recall injection (CJK-aware) |
captureEnabled |
true |
Whether to automatically capture session traces |
dataDir |
~/.dsh/self-memory |
Storage directory for records, traces, and the pending write queue |
Configuration example:
- insert:
- id: self-memory
name: dsh-self-memory
config:
autoRecall: true
recallBudget: 800
captureEnabled: true
Notes¶
- Zero runtime dependencies: The plugin runs entirely locally, does not rely on external services, and supports offline use.
- Retrieval mechanism: Current retrieval is based on keywords, generalized text, and inverted indexes; vector semantic retrieval is not yet supported.
- Record distillation: Session traces are captured automatically, but they are not automatically distilled into records; manual tool invocations are required to write them back.
- Precondition definitions: For multiple solutions to the same problem,
appliesTostill needs to be manually specified when recording to distinguish them. - Storage limits: Storage is currently a single-file JSON store; consider migrating to SQLite after reaching tens of thousands of records.
Conclusion¶
dsh-self-memory provides a basic cross-session memory capability for DSH agents through structured records and closed-loop write-back. For more details, refer to the project documentation: