Skip to content

charlenchen/memos2evolver-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

memos2evolver

MemOS Local ↔ EvoMap Evolver Bridge

A file-based bridge enabling bidirectional communication between MemOS Local (memory system) and EvoMap Evolver (AI evolution engine).

🏗️ 架构

┌─────────────────────────────────────────────────────────────────┐
│                         MemOS Local                              │
│                    (~/.openclaw/memos-local/)                  │
│                                                                   │
│   ┌─────────────┐  ┌─────────────┐  ┌─────────────────────┐   │
│   │ SQLite DB   │  │ FTS5 Index │  │ Vector Embeddings   │   │
│   │ (chunks)   │  │ (chunks_fts)│  │ (embeddings)       │   │
│   └─────────────┘  └─────────────┘  └─────────────────────┘   │
└────────────────────────────┬───────────────────────────────────┘
                              │
                              │ ① write-signal
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                    memos2evolver Bridge                          │
│                (~/.openclaw/extensions/memos2evolver/)           │
│                                                                   │
│   ① MemOS → Evolver:                                           │
│   ┌──────────────────────┐    ┌────────────────────────────┐   │
│   │ MemOSClient.search() │ → │ signal JSONL               │   │
│   │ FTS5 关键词搜索       │    │ signals/inbound/          │   │
│   └──────────────────────┘    └────────────────────────────┘   │
│                                      │                           │
│                                      │ copy_to_evolver_inbox()   │
│                                      ▼                           │
│   ② Evolver 运行:                                               │
│   ┌──────────────────────┐    ┌────────────────────────────┐   │
│   │ node evolver/index.js│ → │ memory_graph.jsonl       │   │
│   └──────────────────────┘    └────────────────────────────┘   │
│                                      │                           │
│                                      ▼                           │
│   ③ Evolver → MemOS:                                          │
│   ┌──────────────────────┐    ┌────────────────────────────┐   │
│   │ MemOSTask            │ ← │ read_evolver_capsules()  │   │
│   │ (SQLite insert)      │    └────────────────────────────┘   │
│   └──────────────────────┘                                      │
└─────────────────────────────────────────────────────────────────┘

🔄 完整工作流

方式一:手动触发(完整闭环)

# 1. MemOS 搜索 → 写入信号 → 复制到 Evolver inbox
memos2evolver write-signal --real --text "SyntaxError" --time-window 6

# 2. 触发 Evolver 运行
node ~/.openclaw/extensions/evolver/index.js

# 3. 同步 Capsule → 创建 MemOS Tasks
memos2evolver sync

方式二:使用 Skill(推荐)

局长: "触发一次 Evolver 进化,关键词是 memory_missing"
    ↓
Agent 执行 memos-v-evolve skill:
1. memos2evolver write-signal --real --text "memory_missing" --time-window 6
2. node evolver/index.js
3. memos2evolver sync
    ↓
结果:
- Signals written to signals/inbound/
- Evolver processed signals
- New Tasks created in MemOS

方式三:HEARTBEAT 自动(定时同步)

HEARTBEAT.md 中配置:

## 长周期任务检查
- [ ] memos2evolver 同步 (每 60 分钟)
  command: source ~/miniforge3/etc/profile.d/conda.sh && conda activate py312 && memos2evolver sync

🛡️ 防重复机制

核心概念

组件 作用 说明
B: 时间窗口 限定搜索范围 只搜索 [now - window, now]不是去重
A: Results Hash 去重检测 同一Query在新窗口中结果是否真的变了
C: 内容指纹 智能去重 深度检测内容相似度

正确理解

时间窗口 B 不是用来去重的,它只是限定 memos search API 的搜索范围。

同一 Query 在不同时间窗口出现,可能是:

  • 新问题(新对话)
  • 同一问题的不同处理阶段(修复→改进→验证)

去重发生在 A/C 阶段:检测这次搜索的结果是否真的包含新信息。

工作流程

HEARTBEAT 触发
    ↓
┌─────────────────────────────────────────────┐
│  1. 搜索范围限定 (B)                        │
│     只搜索 [now - 6h, now] 的 MemOS 数据   │
└─────────────────────────────────────────────┘
    ↓
┌─────────────────────────────────────────────┐
│  2. Results Hash 检查 (A)                   │
│     同一Query,结果是否真的变了?             │
│     - 结果 hash 相似 → 无进化 → 跳过       │
│     - 结果 hash 差异大 → 有进化 → 处理       │
└─────────────────────────────────────────────┘
    ↓ (A 通过)
┌─────────────────────────────────────────────┐
│  3. 内容指纹检查 (C)                        │
│     Jaccard 相似度 > 80% → 跳过            │
│     (夜间低峰期可启用)                      │
└─────────────────────────────────────────────┘
    ↓ (C 通过)
→ 写入信号文件

📟 CLI 命令详解

write-signal

写入信号到 Evolver。

memos2evolver write-signal [OPTIONS]
参数 说明
--text, -t 搜索查询文本
--real 使用真实 MemOS 搜索(默认使用模拟搜索)
--simulate 强制使用模拟搜索
--time-window, -w 时间窗口(小时),限定搜索范围(B机制,默认 6)
--no-dedup 禁用 A: Results Hash 去重检查
--enable-fingerprint, -f 启用 C: 内容指纹检查(Jaccard 相似度)
--no-copy 跳过复制到 Evolver inbox

示例

# 使用真实 MemOS 搜索,6小时时间窗口
memos2evolver write-signal --real --text "SyntaxError" --time-window 6

# 禁用 A 去重,启用 C 指纹检查(夜间模式)
memos2evolver write-signal --real --text "TypeError" --no-dedup --enable-fingerprint

# 模拟搜索(测试用)
memos2evolver write-signal --simulate --text "MemoryError"

read-capsules

读取 Evolver 新产生的 Capsule 事件。

memos2evolver read-capsules [OPTIONS]
参数 说明
--since 只读取此时间戳之后的事件(ISO 8601 格式)

示例

# 读取所有新事件
memos2evolver read-capsules

# 读取特定时间之后的事件
memos2evolver read-capsules --since "2026-04-22T00:00:00Z"

sync

完整同步:读取 Capsule 并创建 MemOS Tasks。

memos2evolver sync

示例

# 执行完整同步
memos2evolver sync

# 输出示例:
# [CLI] Starting one-time sync...
# [CLI] Events read: 4
# [CLI] Tasks created: 4
# [CLI] Last sync: 2026-04-22T10:42:26.562Z

status

查看桥接状态。

memos2evolver status

输出示例

Bridge: memos-v-evolver v1.0.0
Last sync: 2026-04-22T10:42:26.562Z
Signals inbound: 2 files
Signals outbound: 4 files
Evolver memory: ~/.openclaw/extensions/evolver/memory

config

显示当前配置。

memos2evolver config

🛠️ 安装

Python 包

# 克隆仓库
git clone https://github.com/charlenchen/memos2evolver-py.git
cd memos2evolver-py

# 安装
pip install -e .

# 验证安装
memos2evolver --help

OpenClaw Extension

# 克隆到 extensions 目录
git clone https://github.com/charlenchen/memos2evolver-py.git ~/.openclaw/extensions/memos-v-evolver

# 安装 Python 依赖
pip install -e ~/.openclaw/extensions/memos-v-evolver/extension/py/

# 配置 openclaw.json
# 添加 plugins.slots.bridge = "memos-v-evolver"

📁 目录结构

memos2evolver/
├── src/memos2evolver/     # Python 桥接代码
│   ├── __init__.py
│   ├── bridge.py          # 核心桥接类
│   ├── memos_client.py    # MemOS 客户端
│   ├── schema.py          # 数据模型
│   ├── capsule.py         # EvolutionEvent 解析
│   └── cli.py             # CLI 入口
├── extension/              # OpenClaw Extension 打包
│   ├── openclaw.plugin.json
│   ├── package.json
│   ├── skill/memos-v-evolve/SKILL.md
│   └── config/default.yaml
├── README.md
└── pyproject.toml

🔑 核心概念

MemOSSignal

从 MemOS 搜索结果生成的信号:

{
  "type": "MemOSSignal",
  "version": "1.0",
  "timestamp": "2026-04-22T00:00:00+00:00",
  "source": "memos_local",
  "query": { "text": "SyntaxError" },
  "computed_signals": ["log_error"],
  "results": {
    "count": 6,
    "hits": [
      {
        "id": "uuid",
        "original_excerpt": "收到的对话内容...",
        "relevance_score": 0.5,
        "created_at": "2026-04-06T09:51:16+00:00",
        "tags": ["assistant", "task-id"]
      }
    ]
  }
}

EvolutionEvent

Evolver 产生的进化事件:

{
  "type": "MemoryGraphEvent",
  "kind": "outcome",
  "id": "mge_1776853951827_e63a3a41",
  "ts": "2026-04-22T10:32:31.826Z",
  "signal": {
    "key": "memory_missing|user_missing",
    "signals": ["memory_missing", "user_missing"]
  },
  "outcome": {
    "status": "success",
    "score": 0.58
  }
}

📜 License

MIT

About

MemOS Local OpenClaw Plugin dua adapt to Evolver

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors