From 0693c9e801d4cf2fe86ab2e576d45b3c29b3c5eb Mon Sep 17 00:00:00 2001 From: cfdaily Date: Sat, 16 May 2026 23:42:07 +0800 Subject: [PATCH] auto-sync: 2026-05-16 23:42:07 --- docs/design/technical-design-v2.6.md | 175 ++++++++++----------------- 1 file changed, 67 insertions(+), 108 deletions(-) diff --git a/docs/design/technical-design-v2.6.md b/docs/design/technical-design-v2.6.md index 475beaf..d654744 100644 --- a/docs/design/technical-design-v2.6.md +++ b/docs/design/technical-design-v2.6.md @@ -19,121 +19,80 @@ │ │ (OpenClaw Chat) │ │ React + Vite │ │ │ └────────┬─────────┘ └────────┬─────────┘ │ │ │ │ │ +│ 自然语言对话 REST API + SSE │ +│ │ │ │ └───────────┼───────────────────────┼────────────────────────────────────────┘ - │ │ SSE - │ CLI / sessions_send │ REST API ▼ ▼ +┌───────────────────────────────┐ ┌──────────────────────────────────────┐ +│ Agent 执行环境(独立进程) │ │ v2 主进程(PM2: sanguo-moziplus-v2) │ +│ │ │ asyncio event loop │ +│ ┌─────────────────────────┐ │ │ │ +│ │ L0 铁律 (OpenClaw Hook) │ │ │ ┌─────────────────────────────────┐ │ +│ │ L1 角色 (SOUL/IDENTITY) │ │ │ │ API 层 (FastAPI + uvicorn) │ │ +│ │ L2 引擎注入 (bootstrap) │ │ │ │ ┌──────┐ ┌──────┐ ┌────────┐ │ │ +│ │ L3 被动参考 (Skill) │ │ │ │ │黑板API│ │项目API│ │SSE推送 │ │ │ +│ └─────────────────────────┘ │ │ │ └──┬───┘ └──┬───┘ └───┬────┘ │ │ +│ │ │ └─────┼────────┼─────────┼───────┘ │ +│ Agent → 黑板 的交互方式: │ │ │ │ │ │ +│ ① CLI (blackboard.py) ───────┼──┼──→ 直接操作黑板 DB │ +│ ② Inbox JSONL ──────────────┼──┼──→ 秒级事件推送给 Daemon │ +│ │ │ │ +│ │ │ ┌─────────────────────────────────┐ │ +│ │ │ │ Daemon 引擎层(同一 event loop)│ │ +│ │ │ │ │ │ +│ │ │ │ ticker (30s scan) │ │ +│ │ │ │ ┌──────────┐ ┌──────────────┐ │ │ +│ │ │ │ │审查流水线 │ │ 依赖推进 │ │ │ +│ │ │ │ │(4级分级) │ │ 反驳权/蒸馏 │ │ │ +│ │ │ │ └──────────┘ └──────────────┘ │ │ +│ │ │ │ ┌──────────┐ ┌──────────────┐ │ │ +│ │ │ │ │Agent调度器│ │Bootstrap拼装 │ │ │ +│ ← asyncio.create_subprocess │ │ │ └────┬─────┘ └──────────────┘ │ │ +│ _exec (spawn 不等返回) │←─┼──┼───────┘ │ │ +│ │ │ │ ┌──────────────────────────────┐│ │ +│ │ │ │ │ ActiveAgentCounter (并发控制) ││ │ +│ │ │ │ └──────────────────────────────┘│ │ +│ │ │ └─────────────────────────────────┘ │ +│ │ │ │ +│ │ │ ┌─────────────────────────────────┐ │ +│ │ │ │ 黑板数据层 (per-project SQLite) │ │ +│ │ │ │ ┌─────┐ ┌──────┐ ┌──────┐ │ │ +│ │ │ │ │tasks│ │outputs│ │reviews│ │ │ +│ │ │ │ └─────┘ └──────┘ └──────┘ │ │ +│ │ │ │ ┌──────────┐ ┌───────────┐ │ │ +│ │ │ │ │comments │ │experiences│ │ │ +│ │ │ │ │decisions │ │events │ │ │ +│ │ │ │ │observations│ │ │ │ +│ │ │ │ └──────────┘ └───────────┘ │ │ +│ │ │ └─────────────────────────────────┘ │ +└───────────────────────────────┘ └──────────────────────────────────────┘ + ┌───────────────────────────────────────────────────────────────────────────┐ -│ API 层 (FastAPI) │ -│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ -│ │ 黑板 API │ │ Daemon │ │ SSE 推送 │ │ 项目管理 │ │ -│ │ CRUD │ │ 控制API │ │ /events │ │ API │ │ -│ └────┬─────┘ └────┬─────┘ └────┬─────┘ └────┬─────┘ │ -└───────┼────────────┼────────────┼────────────┼────────────────────────────┘ - │ │ │ │ -┌───────┼────────────┼────────────┼────────────┼────────────────────────────┐ -│ │ Daemon 引擎层 (asyncio event loop) │ -│ │ │ │ │ │ -│ ┌────▼────────────▼────────────▼────────────▼─────┐ │ -│ │ Daemon ticker (30s) │ │ -│ │ ┌──────────┐ ┌──────────┐ ┌──────────────────┐ │ │ -│ │ │ Inbox │ │ 审查流水线│ │ 依赖推进/反驳权 │ │ │ -│ │ │ JSONL │ │ (4级分级) │ │ /蒸馏/健康自检 │ │ │ -│ │ └──────────┘ └──────────┘ └──────────────────┘ │ │ -│ │ ┌──────────┐ ┌──────────┐ ┌──────────────────┐ │ │ -│ │ │ Agent │ │ Bootstrap│ │ ActiveAgent │ │ │ -│ │ │ 调度器 │ │ 拼装器 │ │ Counter │ │ │ -│ │ └────┬─────┘ └──────────┘ └──────────────────┘ │ │ -│ └───────┼─────────────────────────────────────────┘ │ -│ │ 3级调度: Daemon直接 / Full Agent / Subagent │ -│ │ │ -│ ┌───────▼─────────────────────────────────────────┐ │ -│ │ Agent Spawn 层 │ │ -│ │ asyncio.create_subprocess_exec │ │ -│ │ ┌──────────────┐ ┌──────────────┐ │ │ -│ │ │ Full Agent │ │ Subagent │ │ │ -│ │ │ (openclaw │ │ (sessions_ │ │ │ -│ │ │ agent CLI) │ │ spawn API) │ │ │ -│ │ └──────┬───────┘ └──────┬───────┘ │ │ -│ └─────────┼───────────────────┼───────────────────┘ │ -│ │ │ │ -│ ┌─────────▼───────────────────▼───────────────────┐ │ -│ │ Agent 执行环境 │ │ -│ │ SOUL.md + IDENTITY.md + Skills + 工具集 │ │ -│ │ ┌──────────────────────────────────────┐ │ │ -│ │ │ L0 铁律 (Hook注入) │ │ │ -│ │ │ L1 角色 (Agent自带) │ │ │ -│ │ │ L2 引擎注入 (操作规范+背景+上下文) │ │ │ -│ │ │ L3 被动参考 (Skill按需加载) │ │ │ -│ │ └──────────────────────────────────────┘ │ │ -│ └──────────────┬──────────────────────────────────┘ │ -│ │ 产出写入/评论/决策/观察 │ -│ ▼ │ -│ ┌──────────────────────────────────────────────────┐ │ -│ │ 黑板数据层 (per-project SQLite) │ │ -│ │ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ │ │ -│ │ │tasks │ │comments│ │outputs│ │reviews│ │events│ │ │ -│ │ └──────┘ └──────┘ └──────┘ └──────┘ └──────┘ │ │ -│ │ ┌──────┐ ┌──────┐ ┌──────────────┐ │ │ -│ │ │decisions│ │observations│ │experiences│ │ │ -│ │ └──────┘ └──────┘ └──────────────┘ │ │ -│ └──────────────────────────────────────────────────┘ │ -│ │ │ -│ ┌──────────────▼──────────────────────────────────┐ │ -│ │ 配置 & 知识层 │ │ -│ │ ┌────────────┐ ┌────────────┐ ┌────────────┐ │ │ -│ │ │ _registry │ │ guardrails │ │ review_ │ │ │ -│ │ │ .yaml │ │ .yaml │ │ protocols/ │ │ │ -│ │ └────────────┘ └────────────┘ └────────────┘ │ │ -│ │ ┌────────────┐ ┌────────────┐ ┌────────────┐ │ │ -│ │ │ prompt_ │ │ schemas/ │ │ skills/ │ │ │ -│ │ │ templates/ │ │ (JSON) │ │ (builtin+ │ │ │ -│ │ │ │ │ │ │ custom) │ │ │ -│ │ └────────────┘ └────────────┘ └────────────┘ │ │ -│ │ ┌────────────┐ │ │ -│ │ │ project.yaml│ (per-project 覆盖) │ │ -│ │ └────────────┘ │ │ -│ └─────────────────────────────────────────────────┘ │ -│ │ -│ 全部运行在单一 asyncio event loop 中(与 FastAPI 共享) │ +│ 配置 & 知识层(文件系统) │ +│ ┌────────────┐ ┌────────────┐ ┌────────────┐ ┌────────────┐ │ +│ │_registry │ │guardrails │ │review_ │ │prompt_ │ │ +│ │.yaml │ │.yaml │ │protocols/ │ │templates/ │ │ +│ └────────────┘ └────────────┘ └────────────┘ └────────────┘ │ +│ ┌────────────┐ ┌────────────┐ ┌────────────┐ │ +│ │schemas/ │ │skills/ │ │project.yaml│ (per-project 覆盖) │ +│ │(JSON) │ │(builtin+ │ │ │ │ +│ │ │ │ custom) │ │ │ │ +│ └────────────┘ └────────────┘ └────────────┘ │ └───────────────────────────────────────────────────────────────────────────┘ ``` -### 1.2 核心数据流 +### 1.2 交互路径详解 -``` -用户需求 → 庞统规划 → 任务拆解 → 写入黑板 - │ - ┌───────────────┘ - ▼ - Daemon tick 扫描 - │ - ┌───────────┼───────────┐ - ▼ ▼ ▼ - pending任务 review任务 blocked任务 - 调度Agent执行 处理审查流水线 检查依赖推进 - │ │ - ▼ ▼ - Agent执行 ┌─────────────┐ - (Full/Sub) │ 审查分级 │ - │ │ high→辩论 │ - ▼ │ standard→单审│ - 写入产出 │ low→Guardrail│ - 到黑板 └──────┬──────┘ - │ │ - │ ┌──────┴──────┐ - │ ▼ ▼ - │ 通过→done 不通过→反驳权 - │ │ - │ max_rounds - │ │ - │ 超轮次→庞统裁决 - │ │ - └───────────────────┘ - │ - ▼ - 任务完成 → 一级蒸馏 → 经验注入 -``` +| 路径 | 方式 | 说明 | +|------|------|------| +| 用户 → Agent | OpenClaw Chat | 自然语言对话,Agent 自带身份和工具 | +| 用户 → Dashboard | 浏览器访问 8083 | REST API 查黑板、SSE 收推送 | +| Agent → 黑板 | CLI `blackboard.py` | read/claim/output/comment/decide/observe/create/review | +| Agent → Daemon | 写 Inbox JSONL | 秒级事件推送,触发 Daemon 提前 tick | +| Agent → Agent | 黑板评论 | comments 表(handoff/rebuttal/debate),替代 Mail | +| Daemon → Agent | `asyncio.create_subprocess_exec` | spawn 不等返回,下次 tick 检查产出 | +| Daemon → Dashboard | SSE `/api/events` | 任务状态变更、审查结果、通知推送 | +| Dashboard → Daemon | REST API | 查状态、手动 tick、项目管理 | ### 1.3 组件职责矩阵