Tools
Memory Engine
OpenClaw 3.8+ Context Engine plugin for intelligent memory management
Install
npm install openclaw-memory-engine
Configuration Example
{
"plugins": {
"slots": {
"contextEngine": "memory-engine"
}
}
}
README
# Memory Engine
> OpenClaw 3.8+ 智能上下文管理与记忆系统插件
## 产品概述
Memory Engine 是一个基于 OpenClaw 3.8 Context Engine API 开发的智能记忆管理插件。它能够自动管理对话上下文,实现长期记忆积累和智能检索。
## 核心特性
### 🧠 智能记忆管理
- **自动提取**:从对话中自动识别并提取有价值的 QA 对(问题-答案)
- **分层存储**:区分短期记忆(当前会话)和长期记忆(知识库)
- **重要性评估**:基于关键词、频率、上下文自动评估记忆重要性
### 🔍 语义搜索
- **FlexSearch 全文索引**:支持中文的高性能搜索
- **相关记忆注入**:根据当前对话自动检索并注入相关记忆
### 🗑️ 智能遗忘
- **自动清理**:定期清理低价值记忆
- **重要性阈值**:可配置的重要性阈值设置
### 📊 分类管理
- **fact(事实)**:客观事实和信息
- **experience(经验)**:成功的处理方案
- **lesson(教训)**:失败经验总结
- **preference(偏好)**:用户偏好和习惯
## 工作原理
```
用户对话
↓
[afterTurn] → 提取QA对 → 评分 → 分类 → 存储
↓
[assemble] → 语义检索 → 注入相关记忆
↓
模型回复(基于完整上下文)
```
## 安装
### 方式一:命令行安装
```bash
openclaw plugins install openclaw-memory-engine
```
### 方式二:手动安装
```bash
npm install openclaw-memory-engine
```
然后在 `openclaw.json` 中配置:
```json
{
"plugins": {
"slots": {
"contextEngine": "memory-engine"
}
}
}
```
重启 OpenClaw:
```bash
openclaw gateway restart
```
## 配置选项
| 选项 | 默认值 | 说明 |
|------|--------|------|
| `dataDir` | ./data/memory-engine | 数据存储目录 |
| `maxMemories` | 1000 | 最大记忆数量 |
| `retentionDays` | 90 | 记忆保留天数 |
| `importanceThreshold` | 0.3 | 重要性阈值 |
| `enableAutoCompact` | true | 启用自动压缩 |
| `compactIntervalMs` | 1800000 | 压缩间隔(毫秒) |
## API 实现
Memory Engine 完整实现了 Context Engine API:
| API | 功能 |
|-----|------|
| bootstrap | 初始化,加载历史记忆 |
| ingest | 实时摄入单条消息 |
| ingestBatch | 批量摄入消息 |
| afterTurn | 提取QA对、评分、分类、存储 |
| assemble | 检索记忆,注入上下文 |
| compact | 智能压缩上下文 |
| prepareSubagentSpawn | 子代理记忆隔离 |
| onSubagentEnded | 子代理记忆合并 |
| dispose | 清理资源 |
## 数据存储
- **记忆库**:`~/.openclaw/workspace/memory-engine/data/memory-engine/memories.json`
- **索引库**:`~/.openclaw/workspace/memory-engine/data/memory-engine/index.json`
## 适用场景
1. **需要长期记忆的 AI 助手**:累积用户偏好、历史交互
2. **知识管理系统**:自动整理和检索知识
3. **经验总结**:从对话中提取最佳实践
## 技术栈
- TypeScript
- FlexSearch(全文搜索)
- JSON 文件存储
## 开源协议
MIT
## 作者
lizhelong <[email protected]>
tools
Comments
Sign in to leave a comment