Provides a cross-session AI memory and cognition system with four-layer memory, real-time sync, free thinking, intelligent prediction, and knowledge visualiz...
数据来源:ClawHub。 在 ClawSkills 查看
选择你使用的 Agent
方法一:命令行安装(推荐)
推荐(无需提前安装 clawhub)
npx clawhub@latest --dir ~/.claude/skills install cognitive-brain或使用 clawhub CLI(需提前安装)
clawhub --dir ~/.claude/skills install cognitive-brain⚠️ 需要 Node.js 18+,没有 Node?请使用下方方法二直接下载 ZIP。 安装 Node.js →
方法二:手动下载安装(无需 Node)
下载 ZIP,解压后将文件夹放到以下路径,重启 Agent 即可:
安装路径
~/.claude/skills/cognitive-brain/💡解压后将文件夹放到上方路径,重启 Agent 即可生效
> 跨会话记忆与认知系统 v5.0 | Cross-Session Memory & Cognition System > > 让 AI 拥有像人类一样的记忆、思考和预测能力
Version: 7.0.1 | License: MIT
---
| 功能 | Feature | 描述 | |------|---------|------| | 🔄 实时共享 | Real-time Sharing | 跨会话毫秒级记忆同步 | | 🧠 四层记忆 | Four-Layer Memory | 感官/工作/情景/语义记忆架构 | | 💭 自由思考 | Free Thinking | 非任务驱动的意识流思考 | | 🔮 智能预测 | Prediction | 预测用户需求,预加载记忆 | | 📊 可视化 | Visualization | 知识图谱、时间线、摘要 | | 🔗 联想网络 | Association Network | 概念关联,激活扩散算法 | | 🏗️ 分层架构 | Layered Architecture | Domain/Repository/Service 分层设计 | | 🔒 事务安全 | Transaction Safety | UnitOfWork 确保数据一致性 | | 📚 完整文档 | Documentation | API 文档 + 架构文档 | | ✅ 测试覆盖 | Test Coverage | 自动化测试套件 |
---
# 方式1: ClawHub 安装(推荐)
clawhub install cognitive-brain
cd ~/.openclaw/workspace/skills/cognitive-brain
npm run setup:auto # 非交互模式,自动安装所有依赖
# 方式2: 手动安装
cd ~/.openclaw/workspace/skills/cognitive-brain
npm install
npm run setup # 交互式配置
| 命令 | 说明 | |------|------| | npm run check | 检查系统依赖(PostgreSQL, Redis, pgvector) | | npm run setup | 交互式安装,会提示输入数据库配置 | | npm run setup:auto | 自动安装,使用默认配置,自动安装缺失依赖 | | npm run setup:resume | 从断点恢复安装(安装失败后使用) | | npm run health | 健康检查 | | npm run reset | 重置数据库(清空记忆,保留表结构) | | npm run uninstall | 卸载(清理数据库、hooks、配置文件) |
| 特性 | 说明 | |------|------| | 🔄 断点恢复 | 安装失败后运行 npm run setup:resume 继续 | | 📋 安装日志 | 记录到 install.log,便于排查问题 | | 🔍 已安装检测 | 自动检测是否已安装,避免重复 | | ⚡ 一键安装 | installCommand 自动执行完整安装流程 |
| 依赖 | 版本 | 安装命令 (Ubuntu) | |------|------|-------------------| | Node.js | >= 18 | apt install nodejs npm | | PostgreSQL | >= 14 | apt install postgresql | | Redis | >= 6 | apt install redis-server | | pgvector | - | apt install postgresql-16-pgvector |
> 💡 npm run setup:auto 会自动安装这些依赖(需要 root 权限)
const { CognitiveBrain } = require('./src/index.js');
const brain = new CognitiveBrain();
// 存储记忆
const memory = await brain.encode('用户的项目叫 Alpha', {
type: 'conversation',
importance: 0.8
});
// 检索记忆
const memories = await brain.recall('项目');
// 获取统计
const stats = await brain.stats();
# 编码记忆
node scripts/core/encode.cjs "内容" -t conversation -i 0.8
# 检索记忆
node scripts/core/recall.cjs --query "关键词" --limit 5
# 健康检查
node scripts/tools/health_check.cjs
# 运行测试
./tests/run.sh
---
┌─────────────────────────────────────────────────────────────┐
│ API / CLI 层 │
│ ┌────────────┐ ┌────────────┐ ┌────────────┐ │
│ │ REST API │ │ CLI │ │ Hook │ │
│ └────────────┘ └────────────┘ └────────────┘ │
└─────────────────────────┬───────────────────────────────────┘
│
┌─────────────────────────▼───────────────────────────────────┐
│ Service 层 │
│ ┌────────────┐ ┌────────────┐ ┌────────────┐ │
│ │ Memory │ │ Concept │ │ Association│ │
│ │ Service │ │ Service │ │ Service │ │
│ └────────────┘ └────────────┘ └────────────┘ │
└─────────────────────────┬───────────────────────────────────┘
│
┌─────────────────────────▼───────────────────────────────────┐
│ Repository 层 │
│ ┌────────────┐ ┌────────────┐ ┌────────────┐ │
│ │ Memory │ │ Concept │ │ Association│ │
│ │ Repository │ │ Repository │ │ Repository │ │
│ └────────────┘ └────────────┘ └────────────┘ │
│ UnitOfWork (事务) │
└─────────────────────────┬───────────────────────────────────┘
│
┌─────────────────────────▼───────────────────────────────────┐
│ Domain 层 │
│ ┌────────────┐ ┌────────────┐ ┌────────────┐ │
│ │ Memory │ │ Concept │ │ Association│ │
│ │ Entity │ │ Entity │ │ Entity │ │
│ └────────────┘ └────────────┘ └────────────┘ │
└─────────────────────────┬───────────────────────────────────┘
│
┌─────────────────────────▼───────────────────────────────────┐
│ 持久层 | Persistence │
│ ┌────────────┐ ┌────────────┐ ┌────────────┐ │
│ │ PostgreSQL│ │ Redis │ │ Files │ │
│ │ (主存储) │ │ (缓存) │ │ (配置/日志)│ │
│ └────────────┘ └────────────┘ └────────────┘ │
└─────────────────────────────────────────────────────────────┘
---
| 层级 | Layer | Duration | Purpose | Description | |------|-------|---------|---------|-------------| | 感官记忆 | Sensory | Milliseconds | Buffer | Transient sensory buffer for immediate perception | | 工作记忆 | Working | Minutes~Hours | Active Processing | Active processing workspace for current tasks | | 情景记忆 | Episodic | Long-term | Experiences | Personal experiences and events with context | | 语义记忆 | Semantic | Long-term | Knowledge | Facts, concepts, and structured knowledge |
---
主入口类,提供统一的操作接口。
const { CognitiveBrain } = require('./src/index.js');
const brain = new CognitiveBrain();
// 编码记忆
const memory = await brain.encode(content, {
type: 'conversation',
importance: 0.8,
sourceChannel: 'qq'
});
// 检索记忆
const memories = await brain.recall('关键词', { limit: 10 });
// 事务操作
await brain.transaction(async (uow) => {
// 多表原子操作
});
// 获取统计
const stats = await brain.stats();
{
id: 'uuid',
content: '记忆内容',
type: 'episodic',
importance: 0.5,
sourceChannel: 'qq',
role: 'user',
entities: ['关键词'],
emotions: { valence: 0, arousal: 0 },
createdAt: Date,
updatedAt: Date
}
{
id: 'uuid',
name: '概念名称',
type: 'general',
importance: 0.5,
activation: 0.0,
accessCount: 0
}
{
id: 'uuid',
fromId: '概念A-ID',
toId: '概念B-ID',
type: 'related',
weight: 0.5
}
---
使用 UnitOfWork 模式确保数据一致性:
const { UnitOfWork } = require('./src/repositories/UnitOfWork.js');
const { MemoryRepository } = require('./src/repositories/MemoryRepository.js');
// 自动事务
await UnitOfWork.withTransaction(pool, async (uow) => {
const memRepo = new MemoryRepository(uow.getQueryClient());
const conceptRepo = new ConceptRepository(uow.getQueryClient());
await memRepo.create(memory);
await conceptRepo.create(concept);
// 自动 commit 或 rollback
});
---
# 运行所有测试
./tests/run.sh
# 运行特定测试
node tests/v5.test.cjs
node tests/db.test.cjs
node tests/memory.test.cjs
# 健康检查
node scripts/tools/health_check.cjs
---
---
| 表名 | 用途 | 说明 | |------|------|------| | episodes | 情景记忆 | 存储对话和事件 | | concepts | 概念节点 | 提取的实体和关键词 | | associations | 概念关联 | 概念间的关系 | | system_memory | 系统配置 | 全局设置和状态 |
自动集成到 OpenClaw 消息流程:
用户消息 → Hook(cognitive-recall) → 检索记忆 → 注入上下文 → AI回复 → 编码记忆
---
{
"version": "5.3.25",
"storage": {
"primary": {
"type": "postgresql",
"host": "localhost",
"port": 5432,
"database": "cognitive_brain"
},
"cache": {
"type": "redis",
"host": "localhost",
"port": 6379
}
}
}
---
...
安装 Cognitive Brain 后,可以对 AI 说这些话来触发它
Help me get started with Cognitive Brain
Explains what Cognitive Brain does, walks through the setup, and runs a quick demo based on your current project
Use Cognitive Brain to a cross-session AI memory and cognition system with four-layer memo...
Invokes Cognitive Brain with the right parameters and returns the result directly in the conversation
What can I do with Cognitive Brain in my documents & notes workflow?
Lists the top use cases for Cognitive Brain, with example commands for each scenario
将技能文件夹放到 ~/.claude/skills/cognitive-brain/ 目录(个人级,所有项目可用),或 .claude/skills/cognitive-brain/(项目级)。重启 AI 客户端后,用 /cognitive-brain 主动调用,或让 AI 根据上下文自动发现并使用。
Cognitive Brain 支持 Claude、Cursor、OpenClaw,可与这些 AI 平台无缝集成,扩展其能力。
Cognitive Brain 可免费安装使用。请查阅仓库了解许可证信息。
Provides a cross-session AI memory and cognition system with four-layer memory, real-time sync, free thinking, intelligent prediction, and knowledge visualiz...
Cognitive Brain 属于「Documents & Notes」分类,该分类的技能帮助 AI 智能体在此领域执行专业任务。
Automate my documents & notes tasks using Cognitive Brain
Identifies repetitive steps in your workflow and sets up Cognitive Brain to handle them automatically