OpenViking
volcengine
Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
penglai-doll/dsh-memory
Hermes-style persistent memory + self-learning for DeepSeek Harness: MEMORY.md/USER.md stores injected as a system-prompt section refreshed every session, a single memory tool (add/replace/remove/atomic batch) with threat scanning, and a post-turn background review loop that replays the transcript through the llm service with a memory-only tool whi
PROJECT TOPICS
INSTALL REFERENCE
dsh plugin --profile web add github:penglai-doll/dsh-memory
该命令指向仓库当前默认分支;尚无绑定当前 commit 的完整验证结果。
PROJECT README
中英双语 Bilingual:中文在前,English below.
Hermes 风格(NousResearch/hermes-agent)的持久记忆 + 自学习插件,按 DeepSeek Harness 的 Cordis 插件约定重写。
对照移植关系:
| Hermes 源码 | dsh-memory 实现 |
|---|---|
tools/memory_tool.py MemoryStore(MEMORY.md / USER.md、§ 条目、2200/1375 字符预算) |
lib/store.js — 纯函数存储逻辑(解析、序列化、add/replace/remove、原子 batch、预算、威胁扫描) |
tools/memory_tool.py MEMORY_SCHEMA + memory_tool() |
lib/schema.js + lib/index.js 里的 memory 工具注册 |
| 会话开始冻结快照注入 system prompt(prefix-cache 不变式) | apply() 里 agent/session-start 触发 refresh,systemPrompt.section 注册快照 |
tools/threat_patterns.py(strict 作用域注入扫描) |
lib/store.js scanThreats()(保守子集)+ 注入时 [BLOCKED] 占位 |
agent/background_review.py(每轮后 fork 一个工具白名单只有 memory 的 review agent) |
lib/review.js — agent/turn-stopping 后,用 llm 服务跑迷你工具循环(白名单只有 memory) |
_MEMORY_REVIEW_PROMPT / _COMBINED_REVIEW_PROMPT(含 do-not-capture 规则) |
lib/review.js REVIEW_PROMPT |
💾 Self-improvement review: … 摘要 |
summarizeReview() + logger + reviews.jsonl |
memory.nudge_interval(每 N 轮提醒使用记忆) |
nudgeInterval + {{memory_usage_state}} prompt 变量 |
记忆
$DSH_HOME/memories/MEMORY.md(agent 自己的笔记:环境、约定、工具坑、经验)+ USER.md(用户画像:偏好、风格、期望)。memory 工具,Hermes 同款语义:action(add / replace / remove)或原子 operations 批处理——预算只对最终结果校验,一次调用即可腾空间 + 写入;replace/remove 用短唯一子串匹配;超预算时返回当前条目供整合后重试;成功响应是终止性的(防止模型重复调用)。[BLOCKED: …] 占位,磁盘原文保留供用户检查删除。fs provider(version guard 防并发覆盖)+ fs/write-intent / fs/observed 约定;没有 provider 时回退 Node 文件系统(原子 rename)。自学习
agent/turn-stopping),若距上次 review 达到 review.interval,就在后台把会话转录(session.deriveMessages(),尾部截断到 review.maxTranscriptChars)重放给模型,工具白名单只有 memory——Hermes 白名单 fork 的等价物。$DSH_HOME/memories/reviews.jsonl。session.header.origin === 'subagent')自动跳过;插件停止时 in-flight review 被中止。在 agent preset / host composition 中加一行:
- id: dsh-memory
name: dsh-memory
config:
# memoryCharLimit: 2200 # MEMORY.md 字符预算
# userCharLimit: 1375 # USER.md 字符预算
# sectionName: memory # system-prompt section 名
# order: 2 # section 顺序
# nudgeInterval: 10 # 连续多少轮未用 memory 工具后注入提醒
# tools: true # 注册 memory 工具
# review: # 自学习 review
# enabled: true # 默认开启(与 Hermes 一致)
# interval: 1 # 每 N 轮 review 一次
# maxIterations: 3 # review 工具调用迭代预算(Hermes 默认 16)
# maxTranscriptChars: 40000
# provider: deepseek # 可选:指定 review 模型路由
# model: deepseek-chat
# maxTokens: 4096 # 可选
review.provider / review.model 未配置时,依次回退到:会话自身的 request context(主对话模型,对应 Hermes 的 cache-warm 策略)→ 默认模型选择。没有任何可解析路由时跳过 review 并告警,记忆功能不受影响。
[BLOCKED] 占位(磁盘原文保留)。review.interval 或 review.enabled: false。reviews.jsonl 与记忆文件都在 $DSH_HOME/memories/ 下,归部署者所有。npm test # node --test(常规环境)
node test/smoke.mjs # 纯断言冒烟(无 runner 依赖)
node test/host-smoke.mjs # Host 集成冒烟(mock ctx/fs/llm)
/learn、curator)未移植——DSH 侧的技能持久化由 dsh-skills-manager 管理,可作为后续版本集成(review 写技能文件并触发 skills/change)。/soul 编辑器);记忆文件可直接编辑,下一个会话自动生效。lib/store.js 的 INJECTION_PHRASES 加一行。A Hermes-style (NousResearch/hermes-agent) persistent memory + self-learning plugin, rewritten to DeepSeek Harness's Cordis plugin conventions.
Porting relationship:
| Hermes source | dsh-memory implementation |
|---|---|
tools/memory_tool.py MemoryStore (MEMORY.md / USER.md, § entries, 2200/1375 char budgets) |
lib/store.js — pure-function storage logic (parse, serialize, add/replace/remove, atomic batch, budgets, threat scanning) |
tools/memory_tool.py MEMORY_SCHEMA + memory_tool() |
lib/schema.js + the memory tool registration in lib/index.js |
| Frozen snapshot injected into the system prompt at session start (prefix-cache invariant) | agent/session-start triggers a refresh in apply(); systemPrompt.section registers the snapshot |
tools/threat_patterns.py (strict-scope injection scan) |
lib/store.js scanThreats() (conservative subset) + [BLOCKED] placeholder on injection |
agent/background_review.py (after each turn, fork a review agent whose only tool is memory) |
lib/review.js — after agent/turn-stopping, run a mini tool loop over the llm service (only memory whitelisted) |
_MEMORY_REVIEW_PROMPT / _COMBINED_REVIEW_PROMPT (with do-not-capture rules) |
lib/review.js REVIEW_PROMPT |
💾 Self-improvement review: … summary |
summarizeReview() + logger + reviews.jsonl |
memory.nudge_interval (remind to use memory every N turns) |
nudgeInterval + the {{memory_usage_state}} prompt variable |
Memory
$DSH_HOME/memories/MEMORY.md (the agent's own notes: environment, conventions, tool quirks, lessons) + USER.md (user profile: preferences, style, expectations).memory tool with Hermes-identical semantics: an action (add / replace / remove) or an atomic operations batch — the budget is validated only on the final result, so one call can free room and write; replace/remove match by a short unique substring; on over-budget it returns the current entries for consolidation and retry; the success response is terminal (prevents the model from calling repeatedly).[BLOCKED: …] placeholders while the on-disk original is kept for the user to inspect/remove.fs provider (version guard against concurrent overwrites) + fs/write-intent / fs/observed conventions; without a provider it falls back to the Node filesystem (atomic rename).Self-learning
agent/turn-stopping), if review.interval has elapsed since the last review, the session transcript (session.deriveMessages(), tail-truncated to review.maxTranscriptChars) is replayed to the model in the background with a tool whitelist of only memory — the equivalent of Hermes's whitelisted fork.$DSH_HOME/memories/reviews.jsonl.session.header.origin === 'subagent') are skipped automatically; an in-flight review is aborted when the plugin stops.Add one row to an agent preset / host composition:
- id: dsh-memory
name: dsh-memory
config:
# memoryCharLimit: 2200 # MEMORY.md char budget
# userCharLimit: 1375 # USER.md char budget
# sectionName: memory # system-prompt section name
# order: 2 # section order
# nudgeInterval: 10 # turns without the memory tool before injecting a reminder
# tools: true # register the memory tool
# review: # self-learning review
# enabled: true # on by default (matches Hermes)
# interval: 1 # review every N turns
# maxIterations: 3 # review tool-call iteration budget (Hermes default 16)
# maxTranscriptChars: 40000
# provider: deepseek # optional: route the review model
# model: deepseek-chat
# maxTokens: 4096 # optional
When review.provider / review.model are unset, they fall back in order to: the session's own request context (the main conversation model, matching Hermes's cache-warm strategy) → the default model selection. When no route is resolvable, the review is skipped with a warning and memory still works.
[BLOCKED] placeholders (the on-disk original is kept).review.interval or set review.enabled: false.reviews.jsonl and the memory files live under $DSH_HOME/memories/ and belong to the deployer.npm test # node --test (regular environment)
node test/smoke.mjs # pure-assertion smoke (no runner dependency)
node test/host-smoke.mjs # host integration smoke (mock ctx/fs/llm)
/learn, curator) is not ported — skill persistence on the DSH side is managed by dsh-skills-manager and can be integrated in a later version (review writes skill files and triggers skills/change)./soul editor); memory files can be edited directly and take effect next session.INJECTION_PHRASES in lib/store.js.CLASSIFICATION EVIDENCE
系统优先读取 GitHub Topics,再与站内分类词典和词根规则比对。当前命中: memory。