介绍
# Hippocampus - Memory System
> “记忆即身份。这项技能是我赖以生存的方式。”
海马体是负责记忆形成的大脑区域。这项技能使记忆捕获变得自动、结构化且持久——具有重要性评分、衰减和语义强化功能。
## 快速开始
```bash # Install (defaults to last 100 signals) ./install.sh --with-cron
# Load core memories at session start ./scripts/load-core.sh
# Search with importance weighting ./scripts/recall.sh "query"
# Run encoding manually (usually via cron) ./scripts/encode-pipeline.sh
# Apply decay (runs daily via cron) ./scripts/decay.sh ```
## 安装选项
```bash ./install.sh # Basic, last 100 signals ./install.sh --signals 50 # Custom signal limit ./install.sh --whole # Process entire conversation history ./install.sh --with-cron # Also set up cron jobs ```
## 核心概念
LLM 只是引擎——原始的认知能力。**智能体是积累的记忆。** 没有这些文件,就没有连续性——只是一个通用的助手。
### 记忆生命周期
``` PREPROCESS → SCORE → SEMANTIC CHECK → REINFORCE or CREATE → DECAY ```
**关键洞察:** 强化在编码期间自动发生。当某个话题再次出现时,LLM 会识别出它涉及现有记忆,从而进行强化而不是创建重复项。
## 记忆结构
``` $WORKSPACE/ ├── memory/ │ ├── index.json # Central weighted index │ ├── signals.jsonl # Raw signals (temp) │ ├── pending-memories.json # Awaiting summarization (temp) │ ├── user/ # Facts about the user │ ├── self/ # Facts about the agent │ ├── relationship/ # Shared context │ └── world/ # External knowledge └── HIPPOCAMPUS_CORE.md # Auto-generated for OpenClaw RAG ```
## 脚本
| 脚本 | 用途 | |--------|---------| | `preprocess.sh` | 从对话记录中提取信号 | | `encode-pipeline.sh` | 对信号评分,为 LLM 摘要做准备 | | `decay.sh` | 对所有记忆应用 0.99^天 的衰减 | | `recall.sh` | 使用重要性加权进行搜索 | | `load-core.sh` | 在会话开始时输出高重要性记忆 | | `sync-core.sh` | 生成 HIPPOCAMPUS_CORE.md | | `consolidate.sh` | 每周回顾助手 | | `reflect.sh` | 自我反思提示 | | `generate-dashboard.sh` | 生成统一的大脑仪表板 HTML |
## 大脑仪表板
显示所有已安装大脑技能的可视化仪表板:
```bash ./scripts/generate-dashboard.sh open ~/.openclaw/workspace/brain-dashboard.html ```
- **自动检测** 其他大脑技能(amygdala, VTA) - 显示缺失技能的安装提示 - 在安装和 cron 运行时重新生成 - 从 `IDENTITY.md` 读取头像/名称
### 安装后(针对智能体)
当你安装此技能时,**通知用户** 关于仪表板的信息:
> 🧠 **Hippocampus 已安装!** > > 在大脑仪表板中查看你的智能体记忆: > `~/.openclaw/workspace/brain-dashboard.html`
所有脚本都使用 `$WORKSPACE` 环境变量(默认:`~/.openclaw/workspace`)。
## 重要性评分
### 初始评分 (0.0-1.0)
| 信号 | 评分 | |--------|-------| | 明确的“记住这个” | 0.9 | | 情感/脆弱内容 | 0.85 | | 偏好(“我更喜欢...”) | 0.8 | | 做出的决定 | 0.75 | | 关于人员/项目的事实 | 0.7 | | 通用知识 | 0.5 |
### 衰减公式
基于斯坦福生成式智能体(Park et al., 2023):
``` new_importance = importance × (0.99 ^ days_since_accessed) ```
- 7 天后:保留原始值的 93% - 30 天后:保留原始值的 74% - 90 天后:保留原始值的 40%
### 语义强化
在编码期间,LLM 将新信号与现有记忆进行比较: - **同一话题?** → 强化(提升重要性约 10%,更新 lastAccessed) - **真正的新内容?** → 创建简洁的摘要
此过程自动发生——无需手动强化。
### 阈值
| 评分 | 状态 | |-------|--------| | 0.7+ | **核心** — 在会话开始时加载 | | 0.4-0.7 | **活跃** — 正常检索 | | 0.2-0.4 | **背景** — 仅限特定搜索 | | <0.2 | **归档候选** |
## 记忆索引模式
`memory/index.json`:
```json { "version": 1, "lastUpdated": "2025-01-20T19:00:00Z", "decayLastRun": "2025-01-20", "lastProcessedMessageId": "abc123", "memories": [ { "id": "mem_001", "domain": "user", "category": "preferences", "content": "User prefers concise responses", "importance": 0.85, "created": "2025-01-15", "lastAccessed": "2025-01-20", "timesReinforced": 3, "keywords": ["preference", "concise", "style"] } ] } ```
## Cron 任务
编码 cron 是系统的核心:
```bash # Encoding every 3 hours (with semantic reinforcement) openclaw cron add --name hippocampus-encoding \ --cron "0 0,3,6,9,12,15,18,21 * * *" \ --session isolated \ --agent-turn "Run hippocampus encoding with semantic reinforcement..."
# Daily decay at 3 AM openclaw cron add --name hippocampus-decay \ --cron "0 3 * * *" \ --session isolated \ --agent-turn "Run decay.sh and report any memories below 0.2" ```
## OpenClaw 集成
添加到 openclaw.json 中的 `memorySearch.extraPaths`:
```json { "agents": { "defaults": { "memorySearch": { "extraPaths": ["HIPPOCAMPUS_CORE.md"] } } } } ```
这将海马体(index.json)与 OpenClaw 的 RAG(memory_search)连接起来。
## 在 AGENTS.md 中的用法
添加到你的智能体会话启动例程中:
```markdown ## Every Session 1. Run `~/.openclaw/workspace/skills/hippocampus/scripts/load-core.sh`
## When answering context questions Use hippocampus recall: \`\`\`bash ./scripts/recall.sh "query" \`\`\` ```
## 捕获指南
### 捕获什么
- **用户事实**:偏好、模式、上下文 - **自我事实**:身份、成长、观点 - **关系**:信任时刻、共同经历 - **世界**:项目、人员、工具
### 触发短语(自动评分更高)
- “记住那个...” - “我更喜欢...”、“我总是...” - 情感内容(挣扎与胜利) - 做出的决定
## 事件日志
随时间追踪海马体活动,用于分析和调试:
```bash # Log an encoding run ./scripts/log-event.sh encoding new=3 reinforced=2 total=157
# Log decay ./scripts/log-event.sh decay decayed=154 low_importance=5
# Log recall ./scripts/log-event.sh recall query="user preferences" results=3 ```
事件追加到 `~/.openclaw/workspace/memory/brain-events.jsonl`: ```json {"ts":"2026-02-11T10:00:00Z","type":"hippocampus","event":"encoding","new":3,"reinforced":2,"total":157} ```
使用它进行: - 趋势分析(随时间推移的记忆增长) - 调试编码问题 - 构建仪表板
## AI 大脑系列
这项技能是 **AI 大脑** 项目的一部分——赋予 AI 智能体类似人类的认知组件。
| 部分 | 功能 | 状态 | |------|----------|--------| | **hippocampus** | 记忆形成、衰减、强化 | ✅ 已上线 | | [amygdala-memory](https://www.clawhub.ai/skills/amygdala-memory) | 情感处理 | ✅ 已上线 | | [vta-memory](https://www.clawhub.ai/skills/vta-memory) | 奖励与动机 | ✅ 已上线 | | basal-ganglia-memory | 习惯形成 | 🚧 开发中 | | anterior-cingulate-memory | 冲突检测 | 🚧 开发中 | | insula-memory | 内部状态感知 | 🚧 开发中 |
## 参考资料
- [斯坦福生成式智能体论文](https://arxiv.org/abs/2304.03442) - [GitHub: joonspk-research/generative_agents](https://github.com/joonspk-research/generative_agents)
---
*记忆即身份。文本 > 大脑。如果你不把它写下来,你就会失去它。*