Cell 生命周期
Cell 是 wesgine 的核心隔离单元——完整、独立、可移植的 AI Agent 运行时。本文介绍 Cell 的创建、温度管理、导入导出和运维。
Cell 是什么
一个 Cell = 一个独立的 Agent 运行时实例,包含:
- 独立的记忆、会话、知识库
- 独立的工具集和 Agent 配置
- 独立的治理策略和配额
- 可导出/导入的便携快照
Cell 之间无数据面通信(AX-1),不同 Cell 之间不能访问彼此的数据。
创建 Cell
HTTP API
curl -X POST http://localhost:9091/admin/cells \
-H "Content-Type: application/json" \
-d '{
"id": "dept-legal",
"timezone": "Asia/Shanghai",
"locale": "zh-CN",
"compliance": "financial"
}'
Go SDK
cell, err := hyp.Cells().GetOrCreate(ctx, wesgine.CellSpec{
ID: "dept-legal",
Timezone: "Asia/Shanghai",
Locale: "zh-CN",
})
GetOrCreate 是幂等操作——Cell 存在则返回、不存在则创建。
温度管理
Cell 有四种温度状态,自动转换以优化资源使用:
| 温度 | 含义 | 激活成本 |
|---|---|---|
| Hot | 有活跃 Run | 0 |
| Warm | goroutine/DB 打开 | 0 |
| Cool | 磁盘保留,无 goroutine | 100-500ms |
| Cold | 已停止 | 1-3s |
转换规则
Hot → Warm Run 结束后
Warm → Cool 空闲 15 分钟
Cool → Cold 空闲 N 天
自动唤醒
- Cool 态:首请求自动 WarmUp,对调用方透明
- Cold 态:Gateway 返回
503 Retry-After: 5,后台异步唤醒
外设(Cron / IMAP 轮询)需要 Warm 态才能运行,因此有定时任务的 Cell 不会降到 Cool。
导出与导入
Cell 支持完整的导出/导入,实现 可移植快照:
导出
# 导出为 tar.gz
curl http://localhost:9091/admin/cells/dept-legal/export \
-o dept-legal.tar.gz
导出包含:
- 三层数据库(meta.db / state.db / sessions.db)
- 知识库文件
- 技能包
- workspace 产出文件(可选排除)
导入
# 导入 Cell
curl -X POST http://localhost:9091/admin/cells/import \
-H "Content-Type: application/octet-stream" \
--data-binary @dept-legal.tar.gz
Cell 运维
列出所有 Cell
curl http://localhost:9091/admin/cells
停止 Cell
curl -X POST http://localhost:9091/admin/cells/dept-legal/stop
重启 Cell
curl -X POST http://localhost:9091/admin/cells/dept-legal/restart
删除 Cell
curl -X DELETE http://localhost:9091/admin/cells/dept-legal
删除会同时移除注册表记录和磁盘文件,不可恢复。建议删除前先导出备份。
更新配置
curl -X PATCH http://localhost:9091/admin/cells/dept-legal \
-H "Content-Type: application/json" \
-d '{"quotas": {"max_concurrent_runs": 5}}'
数据目录结构
每个 Cell 的数据独立存储:
{DataDir}/cells/{cellID}/
├── meta.db # Cell 元数据
├── state.db # 运行时状态、traces
├── sessions.db # 会话、记忆
├── knowledge/ # 知识库文件
├── skills/ # 已安装技能
├── workspace/ # 产出文件(按 Actor 分目录)
└── .scratch/ # 临时计算域(Run 结束后 GC)
多产品 Cell 映射
不同产品使用不同的 Cell 映射策略:
| 产品 | Cell 映射 | Cell ID |
|---|---|---|
| wescode | 1 workspace = 1 Cell | ws-{hash} |
| wesclaw | 1 用户 = 1 Cell | main 或 personal |
| wescraft | 个人/团队 | personal / team-{id} |
| teleclaw | 1 部门 = 1 Cell | dept-{id} |