在 DeepSeek Harness (DSH) 的使用中,會話通常是獨立的,Agent 很難跨對話保留上下文。dsh-memory 插件爲此提供瞭解決方案,它將所有會話連接到一個共享的持久存儲中。
這是一個 DSH 插件,由 joyiok 維護。它爲所有會話(web、headless 等)創建一個共享記憶庫,存儲在 $DSH_HOME/storages/dsh-memory.json。所有會話都可以讀取和寫入同一份數據。
核心功能¶
共享記憶庫¶
Web、headless 和任何工作目錄的會話都讀寫同一份數據。這意味着 Agent 在一個會話中寫入的信息可以在後續會話中直接檢索。
Agent 工具¶
插件提供了四個核心工具:
* memory_add:寫入一條共享記憶。
* memory_search:搜索內容、標籤或分類。
* memory_list:列出記憶。
* memory_remove:按 id 刪除記憶。
Agent 在新會話裏會自動先檢索記憶,遇到值得記住的事實會主動寫入。
Web 側邊欄¶
在 Web 界面中,左下角有一個 Memory 按鈕。點擊後打開的面板支持查看、搜索、添加和刪除記憶。
原子寫入¶
插件使用臨時文件 + 重命名的方式實現原子寫入,確保跨進程寫入安全;讀取時基於文件修改時間感知外部更新。
安裝¶
cd /home/joy/Documents
dsh plugin --profile web add /home/joy/Documents/dsh-memory-plugin
dsh plugin --profile headless add /home/joy/Documents/dsh-memory-plugin
安裝完成後重啓 dsh web:
dsh web
驗證:運行 dsh --profile web --dump-config,配置中應出現以下內容:
# == dsh-memory
- id: memory
name: dsh-memory
典型用法¶
讓 Agent 記憶¶
用戶可以直接告訴 Agent 需要記住的內容,Agent 會調用工具將其存入共享庫。
用戶:記住:我們的正式語言是中文,token 預算每月 5000 萬
Agent:調用 memory_add(content: ..., tags: ["preference", "budget"])
讓 Agent 回憶¶
在新的會話中,Agent 可以先檢索記憶,再進行回答。
(新會話)
用戶:我們之前說過 token 預算多少?
Agent:調用 memory_search(query: "預算") 後回答
Web 面板操作¶
在 Web 界面左下角點擊 Memory 按鈕:
1. 在輸入框中輸入內容。
2. 使用逗號分隔標籤(例如:工作, 待辦)。
3. 點擊保存。
4. 在列表中可以搜索、刪除記憶。
工具參數¶
| 工具 | 參數 | 說明 |
|---|---|---|
memory_add |
content 必填;tags / category 可選 |
寫入一條共享記憶 |
memory_search |
query 必填;limit 可選 |
搜索內容 / 標籤 / 分類 |
memory_list |
category / tags / limit 可選 |
列出記憶 |
memory_remove |
id 必填 |
按 id 刪除記憶 |
配置¶
可在 profile 的 cordis.patch.yml 中覆蓋配置:
- id: memory
config:
file: /path/to/shared-memory.json # 默認 $DSH_HOME/storages/dsh-memory.json
maxContentChars: 20000 # 單條記憶最大字符數
defaultSearchLimit: 20
maxToolLimit: 100
如需禁用插件,可在配置中添加:
- id: memory
disabled: true
注意事項¶
- 敏感信息:記憶內容對所有會話可見,請勿寫入密鑰、口令等敏感信息。
- 文件損壞:如果 JSON 文件損壞,插件會把損壞文件備份爲
dsh-memory.json.corrupt-<ts>並重新開始。
總結¶
dsh-memory 通過提供共享、持久的上下文層,彌合了 DSH 會話之間的間隙。它允許 Agent 主動記憶和檢索信息,而無需人工干預。