The design philosophy of DeepSeek Harness is “everything is a plugin.” When building long conversations or multi-turn tasks, maintaining cross-session context memory is a common need. dsh-plugin-xt-memory is a plugin ported from the XT-AGENT memory system into the DSH ecosystem. It provides Harness with persistent storage, relevance-based retrieval, and automatic extraction.
Core Capabilities¶
The plugin works through two dimensions: injection and tools. The injection part acts as a section provider and supplies retrieved memory snippets; the tools part provides read/write interfaces. The background component handles automatic extraction and lifecycle management.
1. Memory Injection (Section Provider)¶
The injection logic is based on the BM25 algorithm and supports CJK bigram tokenization. It includes the following features:
* Relevance scoring: Based on BM25 scoring (CJK 2-grams) + type weights + hit bonuses + time decay.
* Injection strategy: Selects the top-K entries within a budget and includes a disclaimer line stating that the content “does not constitute instructions” in the injected text.
* Edge cases: If memory is empty, it outputs an empty string.
2. Tools¶
The plugin provides three core tools:
* memory_read: Reads index and content, while recording hit metrics.
* memory_search: Scores and previews results based on BM25.
* memory_write: Performs sanitization, deduplication, and merging, then writes new memories into storage.
3. Background Extraction¶
The extraction process runs asynchronously in the background. The main steps are as follows:
* Interception: Intercepts the main message in llm/stream requests.
* Pre-screening: Applies heuristic rules for pre-filtering.
* Debouncing and limits: Extraction occurs at most every 60 seconds (debouncing), with a maximum of 2 records per extraction.
* Extraction and merging: Calls the LLM (purpose memory-extraction) to extract content, then applies sanitization and semantic deduplication/merging.
4. Lifecycle and Storage¶
- Storage location: Data is stored in
~/.dsh/memory/{project-slug}/*.md, withMEMORY.mdas the index file. The frontmatter format is compatible with XT. - Lifecycle: The system records the number of hits and last usage time. Entries unused for more than 30 days are automatically archived to the
archive/directory, but the original content is not deleted. - Archive configuration: Set
archiveDaysto 0 to disable archiving.
Installation and Enablement¶
Install the plugin under a profile, then restart Harness to make it take effect.
# 安装插件
dsh plugin --profile web add "github:chucan1/dsh-plugin-xt-memory"
# 验证安装
dsh --profile web --dump-config
The output should contain the # == dsh-plugin-xt-memory layer, indicating that the plugin has been loaded.
Configuration Options¶
The plugin supports override configuration under the profile’s cordis.patch.yml.
- id: memory
name: dsh-plugin-xt-memory
config:
dir: D:\custom\memory-root # 数据根目录(默认 ~/.dsh)
budgetChars: 4000 # 注入字符预算
topK: 5 # 注入条数上限
archiveDays: 30 # 0 = 关闭归档
maxPerTurn: 2 # 每次提取最多写入条数
debounceMs: 60000 # 提取防抖时间(毫秒)
merge: true # 启用语义去重/合并
extractor: true # 提取器总开关
provider: deepseek # 辅助提取模型路由
model: deepseek-chat
Usage Examples¶
Developers can directly invoke the tools above in prompts:
- Read memory: Call
memory_readto retrieve the index. - Search memory: Call
memory_searchto find related entries for specific keywords. - Write memory: Call
memory_writeto store key information from the current conversation into the memory store.
Known Limitations and Cautions¶
- Synchronous snapshot rendering: The section
textin dsh only supports synchronous functions. The injected content comes from an “asynchronously refreshed in-memory snapshot + synchronous two-phase selection.” This means that after a memory change, the snapshot refresh is typically delayed by less than one turn. - KV prefix handling: When injecting body text, frontmatter is stripped; hit metrics only modify frontmatter and do not affect injected text. Queries are based on the most recent user message.
- Extraction trigger conditions: Version v1 only extracts message text blocks (not including tool result details) and requires
messages.length >= 2to trigger extraction. - Permission control: On the XT side,
memory_writerequires specific permissions. dsh v1 is not integrated with the tool approval flow, but the write path already applies directory restrictions and sanitization. - Host dependencies: At runtime, only
@deepseek-ai/dsh-tools(peer dependency) is required; other host capabilities (such asctx.llm) are implemented through structured invocation.
Summary¶
dsh-plugin-xt-memory addresses DeepSeek Harness’s need for cross-session memory management. It provides a complete closed loop from storage and retrieval to automatic extraction, making it suitable for agent applications that require long-term memory capabilities.
- GitHub repository: https://github.com/chucan1/dsh-plugin-xt-memory
- Community catalog: https://www.skillhub.cn/plugins/chucan1/dsh-plugin-xt-memory