Files
TrulyMEM-TrueHumanMEM/README.md

263 lines
6.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# TrulyMEM - OpenClaw Graph Memory Plugin
让 AI 拥有真正的长期记忆能力 - OpenClaw 框架插件版
[English Version](./README_EN.md)
---
## AI 自行安装指南
> 本节面向 AI Agent按步骤指导你自主安装此插件到 OpenClaw 框架。
### 步骤 1克隆仓库
```bash
git clone https://gitcode.com/JianFeeeee/TrulyMEM-TrueHumanMEM.git
cd TrulyMEM-TrueHumanMEM
git checkout openclaw
```
### 步骤 2编译 TypeScript 插件
```bash
cd ts/
npm install
npm run build
```
编译成功后,`dist/` 目录会输出编译后的 JavaScript 文件。
### 步骤 3安装 Skill让 AI 能调用记忆工具)
`skills/` 目录下的 3 个 Skill 复制到 OpenClaw 的 Skill 目录。优先级:`<workspace>/skills/` > `~/.openclaw/skills/` > `~/.agents/skills/`
```bash
# 方式 A工作空间级推荐仅当前项目可用
cp -r skills/graph-memory <你的项目目录>/skills/graph-memory
cp -r skills/graph-memory-persona <你的项目目录>/skills/graph-memory-persona
cp -r skills/graph-memory-task <你的项目目录>/skills/graph-memory-task
# 方式 B用户级所有项目可用
cp -r skills/graph-memory ~/.openclaw/skills/graph-memory
cp -r skills/graph-memory-persona ~/.openclaw/skills/graph-memory-persona
cp -r skills/graph-memory-task ~/.openclaw/skills/graph-memory-task
```
### 步骤 4安装 Plugin让 OpenClaw 运行时加载 Tool
`ts/` 目录作为 OpenClaw 插件加载。在 `openclaw.json` 中添加:
```json5
{
"plugins": {
"allow": ["@trulymem/openclaw-graph-memory"]
}
}
```
或者直接将编译后的 `ts/dist/` 目录链接到 OpenClaw 的插件目录:
```bash
# 将插件目录软链接到 OpenClaw 插件路径
ln -s <本项目的ts/dist目录> ~/.openclaw/plugins/graph-memory
```
### 步骤 5验证安装
启动 OpenClaw 后,发送以下消息测试:
```
请记住:我喜欢编程,正在学习 TypeScript
```
AI 应调用 `graph_memory` 工具的 `commit` action 并返回成功确认。
然后测试检索:
```
我之前说过喜欢什么?
```
AI 应调用 `recall` action 并返回之前写入的信息。
### 步骤 6确认 Skill 已加载
在 OpenClaw 中执行:
```
/skills
```
你应该能看到以下 3 个 Skill
- `graph-memory` - 记忆 CRUD
- `graph-memory-persona` - 人设管理
- `graph-memory-task` - 任务管理
---
## 简介
本项目是 OpenClaw 的图记忆插件,基于 SQLite 实现持久化图数据库。
**核心功能:**
- **recall**: 检索记忆(支持关键词、种子实体、多跳遍历、时间过滤)
- **commit**: 写入记忆(三元组批量写入)
- **purge**: 删除记忆(软删除/硬删除/纠错替代)
- **introspect**: 查看记忆状态
- **archive**: 归档旧记忆
- **cleanup**: 清理无效数据
- **persona_update/clear**: 人设管理
- **task_create/set_state/delete/link_info**: 任务管理
---
## 安装
### 方式一:作为 OpenClaw 插件安装
```bash
cd ts/
npm install
npm run build
```
将插件目录添加到 OpenClaw 配置中,或使用 `openclaw plugins install` 安装。
### 方式二:作为 Skill 安装(推荐)
`skills/` 目录复制到 OpenClaw 的 Skill 目录:
```bash
cp -r skills/graph-memory ~/.agents/skills/graph-memory
cp -r skills/graph-memory-persona ~/.agents/skills/graph-memory-persona
cp -r skills/graph-memory-task ~/.agents/skills/graph-memory-task
```
---
## 目录结构
```
ts/
├── src/
│ ├── plugin-entry.ts # OpenClaw Plugin 入口
│ └── runtime/core/
│ ├── graph_memory/
│ │ ├── types.ts # 类型定义
│ │ ├── graph_database.ts # SQLite 图数据库
│ │ ├── memory_service.ts # 记忆服务
│ │ └── index.ts # 模块导出
│ └── tools/
│ ├── builtin/
│ │ └── graph_memory_tool.ts # Tool 实现
│ └── tool_limiter.ts # 调用限制器
├── bundled-skills/
│ ├── graph-memory/ # 内置 Skill 定义
│ │ └── SKILL.md
│ ├── graph-memory-persona/
│ │ └── SKILL.md
│ └── graph-memory-task/
│ └── SKILL.md
├── package.json
├── tsconfig.json
└── openclaw.plugin.json # Plugin Manifest
skills/ # 独立 Skill 定义
├── graph-memory/
│ └── SKILL.md
├── graph-memory-persona/
│ └── SKILL.md
└── graph-memory-task/
└── SKILL.md
```
---
## 在 OpenClaw 中使用
### 作为 Plugin
```typescript
import registerGraphMemoryPlugin from './dist/plugin-entry.js';
registerGraphMemoryPlugin({
registerTool(tool) {
// OpenClaw 会自动注册工具
}
});
```
### 作为独立模块
```typescript
import { createGraphMemoryTool } from './dist/runtime/core/tools/builtin/graph_memory_tool.js';
const tool = createGraphMemoryTool('graph_memory.db', 'my-session-id');
// 写入记忆
const result = await tool.execute('call-1', {
action: 'commit',
params: {
triplets: [
{ subject: '用户', relation: '喜欢', object: '编程' },
{ subject: '用户', relation: '正在学习', object: 'TypeScript' }
]
}
});
// 检索记忆
const recallResult = await tool.execute('call-2', {
action: 'recall',
params: { queryIntent: '用户 编程' }
});
```
---
## API
### Actions
| Action | 说明 | 参数 |
|--------|------|------|
| `recall` | 检索记忆 | `queryIntent`, `seedEntities`, `depth`, `sessionFilter`, `timeRange` |
| `commit` | 写入记忆 | `triplets`, `sessionId`, `turnId` |
| `purge` | 删除记忆 | `criteria`, `mode` (soft/hard/supersede), `newRelation` |
| `introspect` | 查看状态 | - |
| `archive` | 归档旧记忆 | `days` (默认 30) |
| `cleanup` | 清理无效数据 | `dry_run` (默认 true) |
| `persona_update` | 更新人设 | `attributes`, `mode` (merge/replace) |
| `persona_clear` | 清除人设 | `confirm` |
| `task_create` | 创建任务 | `task_id`, `description`, `info_nodes` |
| `task_set_state` | 设置状态 | `task_id`, `state` |
| `task_delete` | 删除任务 | `task_id` |
| `task_link_info` | 关联信息 | `task_id`, `info_node` |
---
## Skill 列表
| Skill 名称 | 功能 | 使用场景 |
|------------|------|----------|
| `graph-memory` | 记忆 CRUD | 读取/写入/删除记忆 |
| `graph-memory-persona` | 人设管理 | 设置 AI 角色性格 |
| `graph-memory-task` | 任务管理 | 创建/更新长期任务 |
---
## 开发
```bash
cd ts/
npm install
npm run build # 编译
npm test # 运行测试
```
---
## 许可证
[GNU General Public License v3.0 (GPLv3)](LICENSE)