记忆梦境引擎 · AI 的睡眠系统

cn.savantcatv1.0.1Updated Oct 6, 2026

零 LLM 事实提取 + 三维信号评分 + 艾宾浩斯衰减 + 五阶段梦境流水线与内容发芽检测,纯计算零依赖

VerifiedSTDIODesktop onlyData & AnalyticsKnowledge & Memory

Overview

AI-generated overview

A local MCP server that extracts, scores, decays and consolidates an assistant's long-term memories, and flags when accumulated notes could become content.

What it does
It exposes six tools: extract_facts for regex-based fact extraction in Chinese and English without any LLM calls, score_signal for three-dimensional scoring of whether a signal belongs in long-term memory, decay_report for Ebbinghaus-style strength, access boost, archival decisions and a full curve, simulate_dream for running a complete five-stage dream cycle over supplied text in a temporary store, list_signal_types for the four signal dimensions and their weights, and engine_info for a capability overview. The engine itself is pure computation over SQLite with no third-party dependencies.
When to use it
Worth adding when an assistant's memory grows unbounded and you want scoring, decay and cleanup decisions rather than raw storage, or when you want to test how a batch of notes would be consolidated before wiring it into a framework. It is a computation and reporting layer, not a memory backend that stores your assistant's data.
Requirements
Runs as a local stdio process started with python server.py, or over streamable-http with a port argument. Needs Python and the mcp package (mcp>=2.1); pytest only for the test suite. No API keys, no environment variables, no accounts. Desktop only; not executable in a browser.
Before you install
The server is described as pure computation and read-only, with readOnlyHint true, destructiveHint false, idempotentHint true and openWorldHint false, and it states it does not retain caller data; simulate_dream uses a temporary store discarded after the run. Note that the README warns that cron subprocesses in many agent frameworks lack memory write permission, so the write and optimize stages can fail silently and high-scoring entries accumulate; it recommends periodic interactive sessions…

Installation

In SourceWeft

  1. Open 记忆梦境引擎 · AI 的睡眠系统 in the dashboard and add it to a workspace.
  2. Enable the server for the chats that should use its tools.

Desktop only via STDIO. STDIO servers start a local process, so they need the SourceWeft desktop host.

Other MCP clients

Follow the launch instructions in the repository.

README

🌙 记忆梦境引擎 · Memory Dream Engine

你的 AI 聊完就忘,不是它笨 —— 是它从来不做梦。

一个可插拔的「AI 睡眠系统」:采集 → 评分 → 写入 → 优化 → 发芽,每 3 小时自动跑一轮。 零 LLM 成本、纯标准库、~800 行 Python、8/8 单元测试通过。

[License] [Python] [Tests] [Deps]

[M8ven Verified]


🤔 你大概率遇到过这三种情况

症状真实原因
「我上周明确说过不要这样,你怎么又忘了?」记忆只在当次对话里,从不沉淀
memory 越写越满,快撑爆上限,但不敢删没有衰减机制,不知道哪条该淘汰
攒了一堆零散结论,没人把它们变成产出采集和产出之间断了一环

梦境引擎就是补这三环的。

🧠 它怎么工作 —— 像人一样睡觉

        ┌─ 浅睡 ── SignalCollector   采集四维信号(决策 / 纠偏 / 工具 / 灵感)        │一轮 ───┼─ 深睡 ── SignalScorer      三维动态评分(按信号类型自适应调权)(180min)│           MemoryWriter      去重 + 合并 + 替换,声明式写入        │        └─ REM ── SproutDetector    3 条 → 星球帖   /   5 条 → 公众号文章                          ▲                    MemoryOptimizer  每 3 轮深度清理(去重 / 过期 / 压缩)

⚡ 四个「别人没有」的点

能力说明
零 LLM 事实提取纯正则,中英文通吃,提取一万条也不花一分钱 token
艾宾浩斯衰减30 天半衰期,高频访问自动增强,低强度自动归档 —— 记忆会自己「瘦身」
三维动态评分决策信号看持久度、纠偏信号看纠偏度、工具信号看复用度,不是一把尺子量到底
内容发芽同一批记忆攒够了,自动提示「这批可以出一篇公众号了」

🆚 和溯忆(Suyi)比

溯忆是被动存储,梦境引擎是主动生长:

特性梦境引擎溯忆
艾宾浩斯衰减✅✅
零 LLM 提取✅ 中英文⚠️ 仅英文
五阶段流水线✅❌
四维信号采集✅❌
三维动态评分✅❌
内容发芽✅❌
Token 节省追踪✅❌
三方依赖零需向量库

🚀 60 秒跑起来

bash
git clone https://gitee.com/savantcat/memory-dream-engine.gitcd memory-dream-engine
# 依赖为零;只有跑测试才需要 pytestpython -m pip install -r requirements.txt
# 看演示(用内置 mock 适配器,不需要接任何框架)python cli.py

想看核心能力,直接跑引擎自带的 v3 演示:

bash
python engine.py

🔌 接入你自己的 Agent

引擎不绑定任何框架,只需实现三个适配器函数:

python
from engine import DreamEngine
def my_session_search(query, limit, sort):    """换成你框架的搜索接口"""    return [{"content": "...", "role": "user"}]
def my_memory(action, target, content, old_text=None):    """换成你框架的记忆写入接口"""    return {"status": "ok"}
def my_get_usage():    """返回 (已用字符数, 总字符数)"""    return (1500, 2200)
engine = DreamEngine(    session_search_fn=my_session_search,    memory_fn=my_memory,    get_usage_fn=my_get_usage,)
report = engine.dream(days_back=2, existing_memories=[...])print(report.summary())

⚠️ 文档澄清:早期版本的 README 里出现过「编辑 .env 配置 SESSION_SEARCH_FN / MEMORY_FN」的说明, 那是错的 —— 引擎从不读取任何环境变量。接入方式只有上面这一种:传 Python 函数。

🔌 作为 MCP 服务调用

server.py 把引擎包成标准 MCP server —— 别人的 Agent 可以直接调这几个工具,不必接适配器、不必读源码。

bash
pip install "mcp>=2.1"
python server.py                                # 本地 stdio(Claude Desktop / Cursor / 任意 MCP 客户端)python server.py --transport http --port 8770   # 远程 streamable-httppython server.py --selftest                     # 不走协议,直接遍历打全部工具
工具作用
extract_facts零 LLM 事实提取(纯正则,中英文通吃)
score_signal三维动态评分 + 该不该写进长期记忆的结论
decay_report艾宾浩斯衰减:当前强度 / 访问增强 / 归档判定 / 完整曲线
simulate_dream用一段文本跑完整五阶段梦境周期,返回报告(临时库)
list_signal_types四维信号定义、权重与打分关键词
engine_info能力概览、与同类方案的取舍对比、服务边界

客户端配置(stdio):

json
{ "mcpServers": { "memory-dream-engine": { "command": "python", "args": ["server.py"] } } }

服务端为纯计算、纯读:6 个工具的四个 annotation hint 全部声明(readOnlyHint=true / destructiveHint=false / idempotentHint=true / openWorldHint=false),不需要 API Key,也不保存调用方的任何数据 —— simulate_dream 在临时库跑完即销毁。

⏰ 定时运行(Hermes Agent)

yaml
schedule: every 180mskills: ["memory-dream-engine"]prompt: 执行记忆梦境引擎五阶段流程。无新发现输出 [SILENT]。

⚠️ 必读:Cron 环境写不了 Memory(最大的运维坑)

多数 Agent 框架的 cron 子进程没有 memory 工具权限,会导致阶段 3(写入)和阶段 4(优化)静默失败 —— 引擎照常采集和评分,但 ≥70 分的条目会持续积压。

症状:报告反复出现「阶段3:写入 — 受阻」,同一批高分记忆连着几轮都没写进去。

做法:每跑 3 轮 cron,安排一次交互式会话手动补写阶段 3+4;memory 占用到 95% 时立即执行清理。

📁 项目结构

engine.py                  ~800 行核心引擎(五阶段 + 衰减 + 零LLM提取 + SQLite)server.py                  MCP 服务端(6 个工具,双通道 stdio / streamable-http)server.json                MCP 元数据(官方 Registry 格式)cli.py                     命令行入口 + 三个适配器示例nightbrain_consolidate.py  可选:夜间知识库巩固(扫描新知/标记陈旧/更新索引)SKILL.md                   Hermes Agent 集成指南部署指南.md                 两种部署方式 + FAQtests/                     8 个单元测试(pytest)

🧪 测试

bash
python -m pip install pytestpython -m pytest tests/ -q      # 8 passed

测试为 pytest 风格(裸 assert + setup_method 夹具),不兼容 unittest discover,请用 pytest 运行。 夹具名必须是 setup_method —— pytest 8 已移除旧的 setup 约定,写成 setup 在 CI 上会集体报 AttributeError(本地老版本 pytest 却照过,是个只在 CI 才暴露的坑)。

📄 License

MIT — 自由使用、修改、分发。

👤 作者

合尘猫 · 一个人 + 一个 AI 分身的 AI 落地实践 —— 知识库 · AI 客服合规 · 内容自动化。

如果这个引擎帮你的 AI 真正"记住"了什么,给个 ⭐ 就是最好的反馈。


记忆不是越多越好,而是越「活」越好。

Source: README.md at commit 583cb4c

Tools

0
Tool metadata has not been indexed yet.

Version history

1
  1. v1.0.1LatestOct 6, 2026