把腾讯云开源的四层记忆系统(TDAI Agent Memory)移植进 DSH:自动捕获对话、用 LLM 提取事实/偏好/画像,下次对话时按当前消息自动召回注入;旧记忆目录可继续使用。
- 语言
- JavaScript
- License
- MIT
- 分支
- main
安装
$ dsh plugin --profile web add dsh-tdai-memory在终端中运行以上命令,通过 dsh CLI 安装此插件。可在右上角切换 Profile。 第一次用 dsh?看这篇新手教程
对话式安装
帮我安装 DeepSeek Harness 插件 Scorp1o117/dsh-tdai-memory:先查看仓库 https://github.com/Scorp1o117/dsh-tdai-memory 确认安全性,然后执行安装命令并验证插件加载成功。
把这段指令粘贴给 DSH Web GUI 里的助手,由它代你完成安装与验证。
一句话定位
把腾讯云开源的四层记忆系统(TencentDB Agent Memory,原 OpenClaw 插件)整体搬进 DeepSeek Harness:自动保存每一轮对话、用 LLM 抽取事实/偏好/画像,下次提问时按当前消息自动把相关记忆塞进提示词里,让模型"凭空想起"过去的事。
核心能力
- 自动保存每一轮对话到本地 SQLite + JSONL + FTS + 向量索引(L0 原始捕获)
- 后台用 LLM 从对话里抽取事实、偏好、事件,写入结构化记忆库(L1)+ 自动生成用户画像和场景块(L2/L3)
- 每次发送消息前,按当前用户输入自动检索相关记忆,作为动态上下文注入提示词(无需手动搜)
- 模型可主动调用
tdai_memory_search(结构化记忆检索)和tdai_conversation_search(原文对话检索)两个工具 - Web UI 设置页自带「记忆」栏,可视化编辑所有配置(数据目录、提取模型、Embedding、开关),密钥写空即保留原值
- 数据目录复用
~/.memory-tencentdb/memory-tdai,腾讯云版旧记忆直接迁移可用
技术实现
- 语言: JavaScript(ESM,Node 原生,TypeScript 仅用于 vendored 核心)
- 关键依赖:
@deepseek-ai/schemastery(配置 schema)、@deepseek-ai/dsh-tools(工具注册)、@tencentdb-agent-memory/tcvdb-text(向量库绑定)、sqlite-vec(本地向量检索)、@node-rs/jieba(中文分词) - 架构模式: Cordis 插件(profile bundle)。
index.js监听session/event+session/flush做捕获,监听system-prompt/assemble做召回注入;client.js渲染 Web UI 设置栏;recall-inject.js作为预设行级别的备用召回注入器。底层核心TdaiCore来自 vendored 腾讯云版,零改动通过StandaloneHostAdapter直连 OpenAI 兼容 LLM/Embedding - 入口文件:
index.js(宿主侧 Cordis 插件)+client.js(浏览器侧 ModuleLoader 插件)+recall-inject.js(agent 预设内备用行)
适用场景
在 DSH 里长期使用同一个对话/Agent、想让模型记住你说过的事实(项目背景、个人偏好、历史决定)的用户;或者希望"问一句就能想起上次聊过什么",而不是每次都重述背景。一次性问答场景用不到此插件,需要一个长会话/长 Agent 才会有感知。
前置依赖与兼容性
| 依赖 | 最低版本 | 说明 |
|---|---|---|
| DSH | 0.1.0-rc.7+ | peerDependencies 声明,已对 rc.7 / rc.8 / 0.1.1-rc.1 实测(README.md:112-115);用 rc.6 须锁插件版本到 0.2.11 |
| Node | >=22.18 | engines.node |
| 平台 | 跨平台 | 纯 JS + 可选本地原生构建,无 OS 限制 |
| 原生模块 | node-llama-cpp(可选) | 仅当选择完全本地 embedding 后端时需要,默认装包不触发原生构建(package.json:70-74) |
| Web UI | React 18.2+ | peerDependencies 声明,由 DSH 宿主提供 |
安装方式
dsh plugin --profile web add github:Scorp1o117/dsh-tdai-memory
配置项
| 配置 | 类型 | 说明 | 默认值 |
|---|---|---|---|
| 数据目录 | 字符串 | 记忆数据库存放路径。留空使用 ~/.memory-tencentdb/memory-tdai,保持与腾讯云版兼容 | 空(默认上面路径) |
| 提取 LLM Base URL | 字符串 | 用于 L1/L2/L3 抽取的 OpenAI 兼容接口地址 | 空(fallback 到 TDAI_LLM_BASE_URL 环境变量) |
| 提取 LLM API Key | 字符串(密码) | 上述接口的密钥,写空保持原值 | 空 |
| 提取 LLM 模型 | 字符串 | 模型名;deepseek-v4-flash 输出不合规,推荐 mimo-v2.5 | deepseek-v4-flash |
| 提取 LLM 最大输出 Tokens | 数字 | 单次抽取响应上限 | 4096 |
| 提取 LLM 超时(毫秒) | 数字 | 单次 LLM 调用超时 | 120000 |
| Embedding Base URL | 字符串 | 向量接口地址(OpenAI 兼容 /v1/embeddings) | http://127.0.0.1:8088/v1 |
| Embedding API Key | 字符串(密码) | 向量接口密钥 | 空 |
| Embedding 模型 | 字符串 | 向量模型名 | Qwen3-Embedding-0.6B |
| 向量维度 | 数字 | embedding 输出维度 | 1024 |
| 请求带 dimensions 参数 | 布尔 | 是否在请求里带 dimensions 字段(部分服务需要) | false |
| 捕获对话(L0) | 布尔 | 是否把每轮对话写入原始存储 | true |
| 结构化提取(L1) | 布尔 | 是否启用 LLM 自动抽取事实/偏好/事件 | true |
| 冲突检测 | 布尔 | 写入前用 LLM 检查重复;额外 LLM 调用且解析不稳,默认关闭 | false |
| 召回注入 | 布尔 | 是否在提示词组装时自动塞入相关记忆 | true |
| 最大召回条数 | 数字 | 单次召回返回的记忆条目上限 | 5 |
| 相似度阈值 | 数字 | 召回的最低相似度分,低于此分数的结果丢弃 | 0.3 |
| 召回超时(毫秒) | 数字 | 单次召回超时 | 3000 |
| 注册搜索工具 | 布尔 | 是否注册 tdai_memory_search 和 tdai_conversation_search 给模型调用 | true |
常见问题
Q: 安装命令跑完后还要不要手改 cordis.patch.yml?
A: 不用。cordis.patch.yml 里的 - insert 声明已经把 tdai-memory 注册成 profile bundle,装包时由 dsh plugin 自动合并挂载。
Q: 设置页面改完怎么没生效?
A: TdaiCore 在插件启动时构建一次,运行时改 settings 不会重建。修改后必须重启 dsh web 才会真正生效(index.js:380 也有 warn 提示)。
Q: 提取模型用 deepseek-v4-flash 行不行?
A: 不推荐。它的 JSON 输出经常不合规,会导致 L1 一条都提不出来;README 默认改用 mimo-v2.5,单次 20–30s 但跑在后台不阻塞对话。
Q: 一定要装 node-llama-cpp 吗?
A: 不必须。它只是「完全本地 embedding」后端的可选 peer,peerDependenciesMeta 标为 optional;用 OpenAI 兼容远程 embedding(默认)不需要它。
Q: 旧机器上用腾讯云版积累过的记忆会丢吗?
A: 不会。数据目录固定为 ~/.memory-tencentdb/memory-tdai,腾讯云版写的内容原样保留,新插件直接复用。
Q: 模型能主动搜旧记忆吗?
A: 可以。tdai_memory_search(L1 结构化检索)和 tdai_conversation_search(L0 原文检索)注册后会出现在工具列表,模型可主动调用。
Q: 卸载插件数据还在吗?
A: 还在。dsh plugin remove 只卸包和解除挂载,~/.memory-tencentdb/memory-tdai 不会被清;想彻底删需手动 rm 该目录。
上手难度
进阶 — 需要自行选择并接入一个 OpenAI 兼容的提取 LLM 和 embedding 服务(默认 http://127.0.0.1:8088 的 Qwen3-Embedding 不一定存在),理解四层记忆架构的 L0/L1/L2/L3 才能调好参数;装上就能跑,但想榨出价值需要挑对模型和 embedding 后端。
已知问题与限制
- 提取模型
deepseek-v4-flash输出 JSON 不合规,会出现 L1 一条都提不出来的情况;默认推荐mimo-v2.5(20–30s/次,后台执行)(README.md:125-127) - 冲突检测(dedup)的 LLM 输出解析不稳,曾导致
stored=0,默认关闭,开启需换更可靠的模型(README.md:128-129 / index.js:63) mimo-v2.5单次提取 20–30s,长会话多轮时整体 L1 抽取耗时可观(README.md:125)- L0 向量写入走后台任务,headless 一次性任务退出时由
destroy()drain,任务量过大可能丢失尾部(README.md:130-131) - Vendored 核心里的
seed-runtime.js标注了 FIXME:teardown 只等 L1 闲下来就销毁,L2/L3 管线可能未跑完就被打断(vendor/tdai/core/seed/seed-runtime.js:8-14) - Vendored 核心里的
tcvdb.js标注了 TODO:向量集合创建未延迟到首次使用,启动期可能阻塞插件初始化(vendor/tdai/core/store/tcvdb.js:178) - Web 设置页面改完配置必须重启
dsh web才生效,运行时改 settings 仅写盘不重建核心(README.md:111 / index.js:379-382) - 升级后若拉取新的上游代码,需要在 tdai 项目目录重跑
npx tsc -p dsh-tsconfig.json(README.md:132-133)
dsh-tdai-memory
GitHub: Scorp1o117/dsh-tdai-memory · npm: dsh-tdai-memory
Part of the DeepSeek Harness Enhancement Suite — Vision · Soul/Persona · Long-term Memory · Plugin Marketplace.
A port of TencentDB Agent Memory (Tencent Cloud's open-source four-layer memory system, originally an OpenClaw plugin) into DeepSeek Harness.
Features
- L0 conversation capture: every turn (turn end, request boundary) is written to raw conversation storage (JSONL + SQLite + FTS + vectors)
- L1 structured memory: a background pipeline uses an LLM to extract
facts / preferences / events (persona / episodic / instruction) from
conversations, stored in
records/+ SQLite + FTS + vectors - L2 scenes / L3 persona: scene blocks and user profile generation (pipeline-scheduled)
- Automatic recall injection: on every prompt assembly, relevant memories and the user profile are retrieved by the current user message and injected as dynamic context (the model "just remembers")
- Tools:
tdai_memory_search(L1 structured search),tdai_conversation_search(L0 raw-text search)
The data directory reuses the existing ~/.memory-tencentdb/memory-tdai, so
previously accumulated memories carry over seamlessly.
Architecture (porting approach)
| Layer | Content |
|---|---|
| Core | The host-neutral core of tdai-memory-openclaw-plugin (src/core, src/utils), tsc-compiled to ESM (dist-dsh/), zero changes |
| Host adapter | StandaloneHostAdapter (official standalone mode, direct OpenAI-compatible calls) |
| dsh shell | index.js: config mapping, session/event + session/flush capture, system-prompt/assemble recall injection on agent.ctx, tool registration, lifecycle |
| Fallback | recall-inject.js: preset-row recall injection (used when mounted inside an agent preset) |
Hard-won wiring details:
- Capture:
session/flushlistener (await semantics; must complete before headless exits);turn/starttimestamps as the L0 cursor floor; turn-id dedup - Headless one-shot runs: wait for
core.handleSessionEnd()inside flush (L1 extraction finishes before exit; otherwise the 5s shutdown timeout kills it) - Recall injection: must be registered on
agent.ctx(assembly runs in the agent scope; root listeners never see it); attach one tick aftersession/createdby resolving the agent from theagentsservice
Configuration (profile patch + settings)
Configuration is settings-namespace driven: the profile patch is the base
layer, and the tdai-memory: section of $DSH_HOME/settings.yaml overrides it
(LLM/embedding keys live in settings.yaml). The Web UI Settings → 记忆
section edits every field (v0.2.0, write-only keys); TdaiCore is built at
startup, so changes apply after a restart.
# $DSH_HOME/settings.yaml
tdai-memory:
llm:
apiKey: 'sk-...'
embedding:
apiKey: 'local-no-key'
# profile patch (base layer)
- id: tdai-memory
name: 'dsh-tdai-memory'
config:
extraction:
enabled: true
enableDedup: false # dedup LLM output parsing is flaky; off by default
llm: # L1/L2/L3 extraction model (OpenAI-compatible)
baseUrl: 'https://opencode.ai/zen/go/v1'
model: 'mimo-v2.5' # deepseek-v4-flash produces invalid extraction JSON
embedding: # vectors (OpenAI-compatible /v1/embeddings)
baseUrl: 'http://127.0.0.1:8088/v1'
model: 'Qwen3-Embedding-0.6B'
dimensions: 1024
sendDimensions: false
Install
dsh plugin --profile web add dsh-tdai-memory
then mount it in $DSH_HOME/profiles/web/cordis.patch.yml:
- insert:
- id: tdai-memory
name: 'dsh-tdai-memory'
config: {} # keys can live in settings.yaml instead
and restart dsh web. LLM/embedding API keys can be set in the Web UI
settings page (记忆 / Memory) or directly in settings.yaml under
tdai-memory:.
Note for users
- This plugin is a standard profile bundle (
dsh.bundle.patch):dsh plugin --profile web add dsh-tdai-memoryinstalls and mounts it in one step — no manualcordis.patch.ymledits needed.- The settings section needs the
dsh-host-apiproxynamespace allowlist; the plugin patches it automatically on first start — restartdsh webonce more and the section appears. A dsh update overwrites the patch; the next plugin start re-applies it.- Settings changes apply after a restart (TdaiCore is built at startup).
- Tested against DSH
0.1.0-rc.6,0.1.0-rc.7, and0.1.0-rc.8.
Known trade-offs
- Extraction model:
mimo-v2.5extracts correctly but takes 20-30s per call (background execution, does not block the conversation);deepseek-v4-flashis fast but its JSON output is non-compliant (extracts 0) - dedup: LLM conflict-detection output parsing is unstable (once caused stored=0); off by default; enable only with a more reliable model
- L1 memory vectors: written with storage (8088 embedding is fast); L0
vectors run as a background task, drained by
destroy()on headless exit - Upgrades: after pulling new upstream code, rerun
npx tsc -p dsh-tsconfig.jsonin the tdai project dir (output indist-dsh/)
License
MIT
查看使用指南 →
该插件的安装步骤、关键要点、FAQ 与兼容性说明(基于已收录字段派生)。
收录徽章
[](https://deepseek-plugin.org/plugins/Scorp1o117/dsh-tdai-memory)把这段 markdown 粘贴到你的 GitHub README,链接回本插件详情页。徽章只声明已被本站收录,不代表安全认证。