Cell 生命周期

Cell 是 wesgine 的核心隔离单元——完整、独立、可移植的 AI Agent 运行时。本文介绍 Cell 的创建、温度管理、导入导出和运维。

Cell 是什么

一个 Cell = 一个独立的 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有活跃 Run0
Warmgoroutine/DB 打开0
Cool磁盘保留,无 goroutine100-500ms
Cold已停止1-3s

转换规则

Hot → Warm     Run 结束后
Warm → Cool    空闲 15 分钟
Cool → Cold    空闲 N 天

自动唤醒

外设(Cron / IMAP 轮询)需要 Warm 态才能运行,因此有定时任务的 Cell 不会降到 Cool。

导出与导入

Cell 支持完整的导出/导入,实现 可移植快照:

导出

# 导出为 tar.gz
curl http://localhost:9091/admin/cells/dept-legal/export \
  -o dept-legal.tar.gz

导出包含:

导入

# 导入 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
wescode1 workspace = 1 Cellws-{hash}
wesclaw1 用户 = 1 Cellmain 或 personal
wescraft个人/团队personal / team-{id}
teleclaw1 部门 = 1 Celldept-{id}