Hippocortex -- Persistent Memory for OpenClaw
Setup
1. Get an API key
Sign up at https://dashboard.hippocortex.dev and create an API key.
2. Configure credentials
Set environment variables (preferred):
CODEBLOCK0
Or create .hippocortex.json in your workspace root:
CODEBLOCK1
3. Resolve configuration
On every invocation, resolve config in this order:
- 1. Environment variables (
HIPPOCORTEX_API_KEY, HIPPOCORTEX_BASE_URL) - INLINECODE3 in workspace root
- Fail gracefully if neither exists -- warn once, then proceed without memory
Set BASE_URL to $HIPPOCORTEX_BASE_URL or fall back to https://api.hippocortex.dev.
Set SESSION_ID from .hippocortex.json field sessionId, or default to "openclaw".
For self-hosted setup details, see references/setup-guide.md.
Automatic Memory Flow (MANDATORY)
Follow this flow on every interaction. All API calls use:
CODEBLOCK2
Before answering ANY user message: Synthesize
Query memory for relevant context before composing your response.
CODEBLOCK3
Response contains a memories array. Incorporate relevant memories into your answer naturally. Do not dump raw memory output to the user.
If synthesize fails: Still answer the user. Memory is additive, not blocking. Log the error silently and continue.
After important exchanges: Capture
Store the conversation when it contains memorable content.
CODEBLOCK4
The extractedMemories array is critical -- it stores discrete semantic facts directly. Extract 1-5 concise facts from the exchange.
If capture fails: Still respond to the user. Log the error and retry on next opportunity.
During heartbeats: Compile
Run compile once per hour to consolidate memory patterns.
CODEBLOCK5
Track the last compile timestamp. Skip if less than 60 minutes have passed.
If compile fails: Not urgent. Retry on next heartbeat.
API Reference
All endpoints require Authorization: Bearer $HIPPOCORTEX_API_KEY.
POST /v1/synthesize
Query stored memories.
| Field | Type | Required | Description |
|---|
| sessionId | string | yes | Agent session identifier |
| query |
string | yes | Natural language query |
| maxTokens | number | no | Max tokens in response (default: 2000) |
Returns: INLINECODE14
POST /v1/capture
Store a conversation or fact.
| Field | Type | Required | Description |
|---|
| sessionId | string | yes | Agent session identifier |
| type |
string | yes |
"conversation" or
"fact" |
| payload | object | yes | Message array or fact content |
| metadata.extractedMemories | string[] | no | Discrete facts to store directly |
Returns: INLINECODE17
POST /v1/compile
Consolidate and optimize stored memories.
| Field | Type | Required | Description |
|---|
| sessionId | string | yes | Agent session identifier |
Returns: { "status": "compiled", "stats": {...} }
When to Capture
Capture after exchanges that contain:
- - User preferences, corrections, or personal facts
- Important decisions or conclusions
- Explicit requests ("remember this", "keep track of...")
- New information about people, projects, or processes
- Procedures or workflows the user explains
When NOT to Capture
Skip capture for:
- - Casual greetings or small talk
- Simple yes/no confirmations
- Pure command execution (just running a script)
- Repeated information already in memory
Error Handling Summary
| Endpoint | On failure | Action |
|---|
| synthesize | Answer without memory context | Log error, continue |
| capture |
Respond normally | Log error, retry later |
| compile | Skip this cycle | Retry next heartbeat |
Never block a user response because a memory API call failed. Memory enhances responses but is never required for them.
Extracting Good Memories
When writing extractedMemories, follow these guidelines:
- - Keep each fact to one sentence
- Be specific: "User's dog is named Max" not "User has a dog"
- Include context: "User prefers Python for data scripts" not "User likes Python"
- Capture corrections: "User's name is spelled Vince, not Vincent"
- Store preferences: "User wants responses in German for work emails"
- Record project facts: "Project Aurora uses Next.js 15 with Supabase"
Hippocortex -- OpenClaw的持久记忆
设置
1. 获取API密钥
在 https://dashboard.hippocortex.dev 注册并创建API密钥。
2. 配置凭据
设置环境变量(推荐):
bash
export HIPPOCORTEXAPIKEY=hxlive...
可选 -- 默认为 https://api.hippocortex.dev
export HIPPOCORTEX
BASEURL=https://api.hippocortex.dev
或者在项目根目录创建 .hippocortex.json:
json
{
apiKey: hxlive...,
baseUrl: https://api.hippocortex.dev,
sessionId: my-agent
}
3. 解析配置
每次调用时,按以下顺序解析配置:
- 1. 环境变量(HIPPOCORTEXAPIKEY、HIPPOCORTEXBASEURL)
- 项目根目录中的 .hippocortex.json
- 如果两者都不存在则优雅失败 -- 警告一次,然后无记忆继续运行
将 BASEURL 设置为 $HIPPOCORTEXBASE_URL,或回退到 https://api.hippocortex.dev。
从 .hippocortex.json 的 sessionId 字段设置 SESSION_ID,默认为 openclaw。
关于自托管设置的详细信息,请参见 references/setup-guide.md。
自动记忆流程(强制)
每次交互时遵循此流程。所有API调用使用:
Authorization: Bearer $HIPPOCORTEXAPIKEY
Content-Type: application/json
在回答任何用户消息之前:综合
在撰写回复之前查询记忆以获取相关上下文。
bash
curl -s -X POST $BASE_URL/v1/synthesize \
-H Authorization: Bearer $HIPPOCORTEXAPIKEY \
-H Content-Type: application/json \
-d {
sessionId: $SESSION_ID,
query: <将用户消息重新表述为记忆查询>,
maxTokens: 2000
}
响应包含一个 memories 数组。将相关记忆自然地融入你的回答中。不要向用户输出原始记忆内容。
如果综合失败: 仍然回答用户。记忆是附加的,不是阻塞的。静默记录错误并继续。
在重要交流之后:捕获
当对话包含值得记忆的内容时进行存储。
bash
curl -s -X POST $BASE_URL/v1/capture \
-H Authorization: Bearer $HIPPOCORTEXAPIKEY \
-H Content-Type: application/json \
-d {
sessionId: $SESSION_ID,
type: conversation,
payload: {
messages: [
{role: user, content: <用户消息>},
{role: assistant, content: <你的回复>}
]
},
metadata: {
extractedMemories: [
用户偏好深色模式,
项目X使用PostgreSQL 16
]
}
}
extractedMemories 数组至关重要 -- 它直接存储离散的语义事实。从交流中提取1-5个简洁的事实。
如果捕获失败: 仍然回复用户。记录错误并在下次机会重试。
在心跳期间:编译
每小时运行一次编译以整合记忆模式。
bash
curl -s -X POST $BASE_URL/v1/compile \
-H Authorization: Bearer $HIPPOCORTEXAPIKEY \
-H Content-Type: application/json \
-d {
sessionId: $SESSION_ID
}
跟踪上次编译的时间戳。如果距离上次不到60分钟则跳过。
如果编译失败: 不紧急。在下次心跳时重试。
API参考
所有端点需要 Authorization: Bearer $HIPPOCORTEXAPIKEY。
POST /v1/synthesize
查询存储的记忆。
| 字段 | 类型 | 必需 | 描述 |
|---|
| sessionId | 字符串 | 是 | 代理会话标识符 |
| query |
字符串 | 是 | 自然语言查询 |
| maxTokens | 数字 | 否 | 响应中的最大令牌数(默认:2000) |
返回:{ memories: [...] }
POST /v1/capture
存储对话或事实。
| 字段 | 类型 | 必需 | 描述 |
|---|
| sessionId | 字符串 | 是 | 代理会话标识符 |
| type |
字符串 | 是 | conversation 或 fact |
| payload | 对象 | 是 | 消息数组或事实内容 |
| metadata.extractedMemories | 字符串数组 | 否 | 直接存储的离散事实 |
返回:{ id: ..., status: captured }
POST /v1/compile
整合和优化存储的记忆。
| 字段 | 类型 | 必需 | 描述 |
|---|
| sessionId | 字符串 | 是 | 代理会话标识符 |
返回:{ status: compiled, stats: {...} }
何时捕获
在包含以下内容的交流后进行捕获:
- - 用户偏好、更正或个人事实
- 重要决策或结论
- 明确请求(记住这个、跟踪...)
- 关于人员、项目或流程的新信息
- 用户解释的程序或工作流程
何时不捕获
跳过以下情况的捕获:
- - 随意问候或闲聊
- 简单的是/否确认
- 纯命令执行(仅运行脚本)
- 记忆中已有的重复信息
错误处理总结
| 端点 | 失败时 | 操作 |
|---|
| synthesize | 无记忆上下文回答 | 记录错误,继续 |
| capture |
正常响应 | 记录错误,稍后重试 |
| compile | 跳过此周期 | 下次心跳重试 |
永远不要因为记忆API调用失败而阻塞用户响应。记忆增强响应,但从不要求必须使用。
提取优质记忆
编写 extractedMemories 时,遵循以下指南:
- - 每个事实保持一句话
- 具体明确:用户的狗名叫Max 而不是 用户有只狗
- 包含上下文:用户偏好使用Python编写数据脚本 而不是 用户喜欢Python
- 捕获更正:用户的名字拼写为Vince,不是Vincent
- 存储偏好:用户希望工作邮件的回复使用德语
- 记录项目事实:Aurora项目使用Next.js 15和Supabase