认知循环五件套

wesgine 引擎内核的五个子系统(Cognitive / Context / Execution / Memory / Govern)。


架构位置

五件套构成 Layer 2 Kernel——引擎的核心能力层:

┌──────────────────────────────────────────────────┐
│              Cell(数据面,厚)                    │
│                                                  │
│  ┌─────────┐ ┌─────────┐ ┌───────────┐          │
│  │Cognitive│ │ Context │ │ Execution │          │
│  └────┬────┘ └────┬────┘ └─────┬─────┘          │
│       │           │            │                 │
│  ┌────┴────┐ ┌────┴────┐                        │
│  │ Memory  │ │ Govern  │                        │
│  └─────────┘ └─────────┘                        │
│                                                  │
│  + Coordination(Loop 协调器)                    │
│  + TaskMemory                                    │
└──────────────────────────────────────────────────┘

1. Cognitive(认知子系统)

负责与 LLM 通信。

职责

核心接口

type Resolver interface {
    Stream(ctx context.Context, cellID string, req Request) (Stream, error)
}

装配

cellchain.BuildCellCognitive 装配内层五层。


2. Context(上下文子系统)

负责构建送给模型的完整上下文。

职责

三个注入面

注入面时机内容
Eager系统提示词索引到的记忆
Lazy当轮 overlay语义召回的记忆
Cold-start跨会话重放历史摘要

3. Execution(执行子系统)

负责工具调用的注册、分发与执行。

职责

工具六源

来源归属层
Tier E 内置工具Layer 2 Kernel
Tier C SDK 闭包Layer 3 Cell
MCP proxyLayer 3 Cell
Adapter 派生Layer 3 Cell
Sub-agent as ToolLayer 3 Cell
Per-run 临时 ToolLayer 4 Actor

4. Memory(记忆子系统)

负责记忆的存储、召回与生命周期管理。

职责

存储后端

双后端架构:


5. Govern(治理子系统)

负责安全策略与合规。

三步管道

Hardline → Sandbox → Zone
步骤职责
Hardline灾难命令拦截(18 条正则,恒 Deny)
Sandbox数据边界(DenyPaths / WorkDir / NetworkPolicy)
Zone效果分类(Green/Yellow/Red)+ GovernMode 决策

Evidence

治理决策产出证据链(hash chain),不可事后篡改。


Coordination(协调器)

不是第六个子系统,而是 Loop 本身——runLoop 的 for{} 循环:

while !done:
    context = Context.Assemble(messages, overlays)
    response = Cognitive.Stream(context)
    if response.tool_calls:
        Govern.Check(tool_calls)
        results = Execution.Execute(tool_calls)
        Memory.Observe(results)
    else:
        done = true
    Settlement()

Run 编排

internal/orchestration/ 管理 Run 的多 Agent 委派。


依赖方向

严格单向向内:

Shared Kernel ← 零依赖
Subsystem BC ← 只依赖 Shared Kernel
Coordination ← 依赖 Subsystem 接口
Infrastructure ← 实现 Subsystem 接口
Cell ← 组装以上一切
Hypervisor ← 管理 Cell 生命周期