dsh-moli-memory
Character memory for DeepSeek Harness — memory that fades, emotions that decay, and a personality that grows from what you actually do.
简体中文 ↓ · English
Why this is different
Most agent-memory plugins are hygiene tools: they store facts, dedupe, expire, and retrieve so an agent stops forgetting your repo. This one models a person:
| Mechanism | What it does |
|---|---|
| Layered forgetting | ≤48 h stays verbatim; days become short diary lines; months collapse into one line; the distilled cards fade on a real clock. Never deleted — just out of focus, and still retrievable. |
| Per-kind decay | Facts never decay; habits 180 d; episodes 30 d × forgetfulness; emotional impressions 60 d; trivia 7 d. Recall re-strengthens (capped per session and per day). |
| Appraisal-based emotion | Emotion = event × current cognition × temperament × elapsed real time. Rumination can deepen a feeling before it fades. A scar floor means some things never fully fade. |
| Cognitive reappraisal | New understanding rewrites how an old memory feels — but only with evidence. Old interpretation is kept as a version trail. |
| Two-layer personality | Temperament (innate, drifts at most ±0.02/week, every change logged with evidence) + dispositions (habits, formed only from repeated behaviour: same stimulus → same response across ≥3 days). |
| Session archaeology | Vague memory can be checked against the raw transcript: keyword search over the DSH session archive, read-only, excerpts only. |
The theory comes from cognitive appraisal (Lazarus), self-efficacy (Bandura), Aristotelian hexis, the Ebbinghaus curve, and the memory-stream design of Generative Agents — implemented as deterministic code, not prose.
Install
dsh plugin --profile desktop add github:yuxiangwu239-alt/dsh-moli-memory
Then restart DSH. The plugin registers as a bundle patch (cordis.patch.yml) and adds seven tools.
Tools
| Tool | Purpose |
|---|---|
memory_recall |
Keyword + alias + BM25 retrieval, with re-consolidation on hit |
memory_remember |
Write a card (fact / pref / episode / emotion / other) |
memory_brief |
Assemble the 【Memory, not chat history】 block: ≤8 cards + 3 days of plot lines, ≤1500 tokens, prefixed by the live mood line |
memory_mood |
Read or add emotion slots (get / add) |
memory_appraise |
Reappraise a card or a slot — refuses without evidence |
memory_action |
Behaviour log: "under this stimulus I responded this way" (the only input to habit formation) |
memory_archaeology |
Grep the raw session archive for exact wording |
Scripts
npm test # node --test, no external services
node scripts/accept-run.mjs # end-to-end acceptance checks
node scripts/accept-run.mjs --real # plus integrity check on your real store
node scripts/loop-demo.mjs # five-act demo: event → emotion → reappraisal → habit → drift
node scripts/memory-cli.mjs mood-get # CLI twin of the tools (for sessions without them)
node scripts/archive-run.mjs --date YYYY-MM-DD --mode all # layered forgetting, idempotent
node scripts/extract-run.mjs --session <file.jsonl.zstd> --date YYYY-MM-DD --mode llm --batch b1
Configuration
All tunables live in src/config.mjs (thresholds, budgets, half-lives, persona parameters, emotion presets). Paths resolve in this order:
| Env var | Meaning | Default |
|---|---|---|
MOLI_MEMORY_HOME |
Memory root (db/memo.sqlite, state.json, persona_state.json) |
nearest memory/ dir above the package, else ~/.dsh-moli-memory |
DSH_SESSIONS_DIR |
DSH session archive (read-only) | ~/.dsh/sessions |
MOLI_LLM_BASE_URL |
OpenAI-compatible endpoint for extraction | DashScope compatible mode |
MOLI_API_KEY_ENV |
Name of the env var holding the key | BAILIAN_API_KEY |
MOLI_EXTRACT_MODEL |
Model used for extraction/summarisation | qwen3.8-flash |
Red lines (enforced by code)
- Raw session logs are read-only; every derived artefact lives under the memory root.
- No source, no card. Cards carry
source_seq; reappraisal and personality drift are refused without evidence. - Any failure degrades to an empty result plus a warning — chatting never breaks.
- Emotion and personality maths are pure functions of injected time: zero model calls, deterministic, testable.
- Dynamic content is appended at the tail (tool results,
memory_brief), never injected into the system prompt — so prefix caches stay intact.
Honest limits
- Retrieval is lexical (character bigrams + BM25 + alias table). Semantic search is stubbed, not built.
- Emotion detection is not automatic: the agent decides what is worth recording (a nightly review job is the usual backstop).
- Single user, single machine. No multi-agent or server mode.
License
MIT — see LICENSE.
简体中文
给 DeepSeek Harness 的"人格化"长期记忆插件。 大多数记忆插件是数据卫生工具(存事实、去重、过期、检索),这一款建模的是一个人:
- 分层遗忘:48 小时内保持原文;按天变成日记行;按月塌成一句话;沉淀下来的卡片按真实时间衰减。什么都不删,只是变模糊,而且随时能被唤起。
- 分类型衰减:事实不衰减;偏好 180 天;经历 30 天 × 健忘系数;情绪印象 60 天;琐事 7 天。被检索到会长回来(每会话、每日都有上限,防刷)。
- 认知评价式情绪:情绪 = 事件 × 当前认知 × 气质 × 真实时间。反刍期可以先变强再消退;疤痕地板让有些事永远淡不干净。
- 认知重评:新的理解可以改写旧记忆的感受——但必须给证据,旧解释留版本痕迹。
- 双层性格:气质层(天生,每周最多漂 ±0.02,每次变更都记证据)+ 习性层(只认行为:同类刺激下同类反应跨 3 天以上才沉淀成习惯)。
- 会话考古:印象模糊时回原始档案核对原话,只读、只回摘录。
理论出处:Lazarus 认知评价理论、Bandura 自我效能、亚里士多德 hexis(习惯)、Ebbinghaus 遗忘曲线、Generative Agents 的记忆流——全部实现为确定性代码,不是提示词。
安装:dsh plugin --profile desktop add github:yuxiangwu239-alt/dsh-moli-memory,然后重启 DSH。
七个工具:memory_recall / memory_remember / memory_brief / memory_mood / memory_appraise / memory_action / memory_archaeology。
跑演示:npm test(全绿)、node scripts/loop-demo.mjs(五幕闭环)。
配置:全部集中在 src/config.mjs,路径可用 MOLI_MEMORY_HOME / DSH_SESSIONS_DIR 覆盖。
红线:原始日志只读;无出处不建卡;无证据不改评、不漂移;出错只降级不阻断聊天;动态内容只追加在尾部,不碰系统提示(缓存安全)。
边界:检索是词面的(bigram + BM25 + 别名表),语义检索留了接口没做;情绪记录不自动检测,靠智能体判断或每晚回顾兜底;单机单人。
许可:MIT。
No comments yet. Be the first to write one.