PrismClaw Architecture

5-Layer Dependency · L0 Schema → L1 Engine → L2 Runtime/Infra → L3 Assembly → L4 App · Single Run Container

L4 · App 通信层 — 请求接入与流式回传 app/web · WebSocket SSE / 流式事件 app/auth · Gateway JWT / 鉴权 / 路由 ChatRunner 会话编排 / 取消 / 续跑 app/state · routes 会话状态 / HTTP 入口 L3 · Assembly 编配层 — DI bundles 组装 L1/L2 bundles · wiring 依赖装配 / 端口绑定 lifecycle 启动 / 关闭 / 后台任务 plugins 插件装载 / hook 注册 workspace Runner 装配 / 工作区 L2 · Runtime / Infra — 服务启动器与基础设施 runtime/facade 引擎门面 / 懒加载 runtime/skills 技能发现 / 加载 infra/settings · config 配置加载 / 环境解析 infra/runtime_root 运行时卷 / 沙箱挂载 L1 · Engine 引擎层 — Agent 循环与领域子系统 Agent Loop 核心 runner · preparer · wiring · agent_loop · runtime · terminal · types LoopRuntime 唯一 run 级容器 execution loop / dispatch / checkpoint security gate / sandbox / policy execution/skills 技能运行时 plugins · hooks 插件 / 生命周期 hook memory 长期记忆 / 检索 dream 离线整合 / dispatch compression 上下文压缩 / 缓存打包 engine/mcp MCP 客户端 / 传输 subagent 子代理执行 / 隔离 toolkit 工具注册 / 执行 / 工作区 services/llm LLM 客户端 / provider review 审查 / 完成契约 scheduler 定时任务 / 执行器 curator 知识策展 / 巡检 engine/runtime Runtime-Agent 通信 commands 斜杠命令 / 内置指令 L0 · Schema 契约层 — 零业务依赖(15 个模块) agent llm services content config session storage memory security scheduler audit dream protocol shared trajectory Persistence — 适配器(Redis / PostgreSQL) session · lock · pg_checkpoint memory · workspace · user · scheduler dream · curator · trajectory · audit Agent Loop · 单次 run 生命周期 1 · RunPreparer.prepare() 返回 EarlyExit | LoopRuntime;启动路径全部闭合 2 · build_loop_config(rt) build_runtime(rt) 原地装配预算 / 完成内核 / 投影器 3 · RunLoopState → run_loop() frame / ledger / run 级对象;stage 第一参数统一为 rt 4 · stages stream · tools · continue_ · terminal(端口注入) 5 · run_teardown(rt) 遥测 · skill 清理 · ownership 释放 · SESSION_END LoopRuntime · 唯一 run 级容器 入参 / run 级状态 / 装配产物 / 可变标志(无运行期行为) run 级状态单一真相源;随 run 创建,随 teardown 释放 数据流 ❶ 请求主路径 WebSocket ChatRunner Preparer run_loop teardown ❷ 安全决策链 Pre-tool Check Security Gate Sandbox / Bwrap CompletionKernel ❸ 记忆 / 上下文路径 Context Prepare Compression Memory Projection run 级状态只经 LoopRuntime 传递;stage 通过 (rt, state) 显式读写。 依赖方向严格向下:App → Assembly → Runtime/Infra → Engine → Schema。 engine 只向下依赖 schema;runtime / app / persistence 均位于其上层。 Legend L4 App L3 Assembly L2 Runtime · L0 Schema L1 Engine / Agent Loop Security Persistence 依赖方向(向下) 单容器 / 状态 Architecture Principles • L0 零依赖;依赖只能向下,禁止反向导入。 • LoopRuntime 是单次 run 的唯一状态容器。 • build_loop_config(rt) 单参数 + build_runtime 原地装配。 • stage 统一 (rt, state) 签名,行为经端口注入。 • 终态唯一出口:CompletionKernel.decide()。 • 终态副作用集中在 terminal.py(幂等)。

Schema · 契约层 (L0)

  • 15 个模块,零业务依赖
  • agent / llm / services / content / config
  • session / storage / memory / security / scheduler
  • audit / dream / protocol / shared / trajectory

Engine · 引擎层 (L1)

  • Agent Loop:runner → preparer → wiring → run_loop
  • stage:stream / tools / continue_ / terminal
  • 子系统:execution / security / skills / plugins / memory
  • dream / compression / mcp / subagent
  • toolkit / llm / review

Runtime (L2) · Assembly (L3) · App (L4)

  • L2:runtime/facade、runtime/skills
  • L2:infra/settings、infra/runtime_root
  • L3:bundles、wiring、lifecycle、plugins、workspace
  • L4:app/web、auth、gateway、ChatRunner、routes
  • Persistence:Redis / PostgreSQL 适配器