世界上有一种痛苦叫做「AI Agent不记得三秒前说过的话」。你刚告诉它你的名字,转头它就问「你叫什么来着」——像极了那些你记不住人名的同事。
OpenViking 是字节跳动(火山引擎)开源的、专为AI Agent设计的上下文数据库。它通过文件系统范式统一管理Agent的:
传统的RAG方案存在一个核心问题——它只是「检索」,而不是「管理」。OpenViking做了三件事:
| 能力 | 传统RAG | OpenViking |
|---|---|---|
| 上下文管理 | ❌ 无状态检索 | ✅ 层次化上下文递送 |
| 记忆持久化 | ✅ 基础 | ✅ 智能分层 |
| 自我进化 | ❌ 静态 | ✅ 动态演化 |
| 文件系统接口 | ❌ 专用API | ✅ POSIX-like接口 |
| Skills索引 | ❌ 不支持 | ✅ 内置支持 |
OpenViking的核心架构分为三层:
┌─────────────────────────────────────┐
│ Agent Layer (用户端) │
│ OpenClaw / Claude Code / Codex │
└─────────────────┬───────────────────┘
│ FS Protocol
┌─────────────────▼───────────────────┐
│ OpenViking 上下文数据库 │
├────────────────┬────────┬───────────┤
│ Memory Store │ Resource│ Skills DB│
│ (长期/短期记忆) │ (配置) │ (技能索引) │
├────────────────┴────────┴───────────┤
│ Backend Layer │
│ SQLite / Redis / Filesystem / S3 │
└─────────────────────────────────────┘
这是OpenViking最核心的特性——根据任务复杂度自动选择递送合适的上下文:
# 通过pip安装 pip install openviking # 或者使用Docker docker run -d \ --name openviking \ -p 8374:8374 \ -v /data/openviking:/data \ volcengine/openviking:latest
// ~/.openclaw/config.json
{
"context": {
"provider": "openviking",
"config": {
"host": "localhost",
"port": 8374,
"backend": "sqlite",
"database": "/data/openviking/agent.db"
},
"memory": {
"shortTerm": {
"limit": 100,
"ttl": 3600
},
"longTerm": {
"limit": 10000,
"ttl": 2592000
},
"autoSummary": true
},
"hierarchy": {
"enabled": true,
"maxTokens": {
"L1": 4000,
"L2": 8000,
"L3": 16000,
"L4": 32000
}
}
}
}
// skills/openviking-memory/index.js
export default {
name: "openviking-memory",
description: "使用OpenViking增强Agent记忆管理",
hooks: {
async beforeAction(context) {
// 在每次操作前检索相关记忆
const memories = await context.openviking.retrieve({
query: context.input,
layers: ["L2", "L3"],
limit: 5
});
context.memories = memories;
},
async afterAction(context) {
// 操作后保存新记忆
await context.openviking.store({
type: "episodic",
content: context.output,
importance: context.importance || 0.5,
ttl: context.importance > 0.8 ? "long" : "short"
});
}
}
}
OpenViking用「文件系统」的思维管理上下文——一切皆文件:
# OpenViking 上下文目录结构
/context/
├── /memory/
│ ├── /working/ # 工作集(当前会话)
│ │ ├── session_001.json
│ │ └── current_task.md
│ ├── /recent/ # 短期记忆
│ │ └── 2026-05-24.jsonl
│ └── /longterm/ # 长期记忆
│ ├── user_preferences.json
│ └── knowledge_graph.db
├── /resources/
│ ├── /config/
│ │ ├── openai_key.json
│ │ └── databases.yaml
│ └── /docs/
│ └── api_handbook.md
├── /skills/
│ ├── /installed/
│ │ └── web-search/
│ └── /cache/ # Skills执行缓存
└── /state/
├── task_progress.json
└── agent_status.json
让Agent记住用户偏好,即使重启也不丢失:
# 对话1 用户: 我喜欢用Python写数据分析 Agent: 记住了!✓(写入OpenViking长期记忆) ## 24小时后,对话2(新会话) 用户: 帮我写个爬虫 Agent: 好的,用Python吧?我记得你偏好Python做数据相关的工作。 用户: 你还记得?! 👈 这就是OpenViking的魔法
# 配置自动总结
{
"autoSummary": {
"interval": 1800, // 每30分钟自动总结
"strategy": "hierarchical",
"output": {
"type": "markdown",
"path": "/memory/recent/summary_2026-05-24.md"
}
}
}
多个Agent实例共享上下文数据库,实现「群体智慧」:
{
"openviking": {
"frontend": "agent-alpha",
"shared": {
"enabled": true,
"read": ["team-memory"],
"write": ["agent-alpha-memory"]
}
}
}
答: 向量数据库只管「存和查向量」,OpenViking管理的是完整上下文——包括记忆层次、文件系统接口、Skills集成等。更准确地说,OpenViking是「面向Agent的操作系统存储层」。
答: 用SQLite后端最低256MB内存即可运行。如果用Redis做L1缓存,建议512MB+。
答: L1工作集延迟在1ms以内,L2-L3约10-50ms,L4知识库检索约100-500ms(取决于索引量)。