引言
在与 Claude Code 协作开发的过程中,我观察到一个有趣的现象:Claude Code 并没有复杂的"认知架构",却能展现出智能的行为。它的核心是上下文管理 + Skill 调用。
这启发了 ECHO_CLAW 的设计:如果 Claude Code 这种简单的架构就能让 AI 在编程任务中表现出智能,那在游戏场景中是否也能复用这种思路?
核心设计理念
认知科学与工程实践的结合
ECHO_feeling 采用认知科学架构(七层认知、情感系统),这是对"智能"的理论探索。但理论落地面临挑战:
- 复杂度高:每层都需要精细设计
- 调试困难:行为涌现难以追溯
- 参数调优:PAD/OCC 等情感参数需要大量实测
ECHO_CLAW 采用完全相反的思路:不预设智能框架,让智能从上下文中涌现。
核心公式
智能行为 = 丰富的上下文 + 完善的 Skill 库 + LLM 推理能力
这里的"上下文"包括:
- 当前游戏状态(位置、物品、周围环境)
- 对话历史(玩家说过什么、AI 回应过什么)
- 任务上下文(正在做什么、做过什么)
- 可用能力(有哪些 Skill 可以调用)
与 Claude Code 的类比
| Claude Code | ECHO_CLAW |
|---|---|
| 文件系统上下文 | 游戏世界状态 |
| Terminal 执行 | Plugin 操作 |
| Skills/Slashes | Skills |
| MCP Server | MCP Server(Wiki、配方) |
| 记忆系统 | 记忆系统 |
三层调度架构
架构概览
┌─────────────────────────────────────────────────────────────┐
│ ECHO_CLAW 核心架构 │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ 快速反射层 │ │ LLM 编排层 │ │ 执行引擎 │ │
│ │ (规则匹配) │───▶│ (上下文驱动)│───▶│ (Plugin池) │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ 紧急响应 │ │ Skill编排 │ │ 游戏操作 │ │
│ │ 如:躲避攻击│ │ 并行/串行 │ │ 如:移动/挖掘│ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ 上下文管理器 │ │
│ │ • 当前窗口(智能压缩) • 记忆系统(持久化查询) │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ 工具注册中心 │ │
│ │ Skills(决策) │ Plugins(执行) │ MCP(外部资源) │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
Layer 1: 快速反射层
处理紧急情况,绕过 LLM 直接执行:
interface ReflectionRule {
trigger: {
health?: { below?: number; above?: number }
threat?: 'hostile' | 'neutral' | 'friendly'
event?: string
}
action: () => Promise<void>
priority: number
}
// 示例规则
const rules: ReflectionRule[] = [
{
trigger: { health: { below: 20 }, threat: 'hostile' },
action: async () => await bot.pathfinder.flee(hostileEntity),
priority: 100
},
{
trigger: { event: 'on_fire' },
action: async () => await bot.equip(waterBucket, 'hand'),
priority: 90
}
]Layer 2: LLM 编排层
基于上下文的动态决策:
interface OrchestrationContext {
// 游戏状态
gameState: {
position: Vec3
health: number
inventory: Item[]
nearbyEntities: Entity[]
}
// 对话历史(压缩后)
conversationHistory: Message[]
// 当前任务
currentTask: Task | null
// 可用 Skills
availableSkills: SkillDeclaration[]
}
async function orchestrate(context: OrchestrationContext): Promise<ExecutionPlan> {
// LLM 根据上下文选择并编排 Skills
const prompt = buildOrchestrationPrompt(context)
const response = await llm.invoke(prompt)
return parseExecutionPlan(response)
}Layer 3: 执行引擎
执行 Skill 返回的操作:
interface ExecutionEngine {
// 执行计划
execute(plan: ExecutionPlan): Promise<ExecutionResult>
// 管理 Plugin 池
plugins: Map<string, PluginInterface>
// 操作队列
actionQueue: Action[]
}
async function execute(plan: ExecutionPlan): Promise<ExecutionResult> {
const results: ActionResult[] = []
for (const step of plan.steps) {
if (step.type === 'parallel') {
// 并行执行
const parallelResults = await Promise.all(
step.actions.map(a => executeAction(a))
)
results.push(...parallelResults)
} else {
// 串行执行
for (const action of step.actions) {
results.push(await executeAction(action))
}
}
}
return { results, success: true }
}工具体系:三分设计
Skill vs Plugin vs MCP
| 类型 | 职责 | 示例 |
|---|---|---|
| Skill | AI 决策逻辑 | explore-nearby, craft-item |
| Plugin | 游戏交互实现 | minecraft-plugin, stardew-plugin |
| MCP | 外部资源接入 | wiki-mcp, recipe-mcp |
这种分离的好处:
- Skill 可复用:同一 Skill 可以在不同游戏中使用(如
explore-nearby) - Plugin 可替换:换游戏只需换 Plugin
- MCP 可扩展:接入外部知识源(Wiki、地图)
Skill 声明规范
完整的 Skill 声明包含丰富的元信息:
interface SkillDeclaration {
// 基础信息
name: string
description: string
version: string
// 接口定义
input: JSONSchema
output: JSONSchema
// 触发条件
triggers: {
keywords?: string[] // 触发关键词
events?: string[] // 触发事件类型
conditions?: Condition[] // 触发条件
}
// 能力声明
capabilities: {
applicableScenes: string[] // 适用场景
outputType: string // 输出类型
collaborationWith: string[] // 可协作的其他skill
}
// 执行元信息
execution: {
costEstimate: number // 执行成本预估 (ms)
reliability: number // 可靠性 0-1
timeout: number // 超时时间
}
// 依赖与冲突
dependencies: {
requires: string[] // 前置依赖
conflicts: string[] // 冲突的skill
mutex: string[] // 互斥资源
}
// 失败恢复
recovery: {
retryable: boolean
fallbackSkill?: string
rollbackStrategy?: 'none' | 'partial' | 'full'
}
// 优先级
priority: {
base: number // 基础优先级
modifiers: { // 动态调整因子
urgency?: number
relevance?: number
userPreference?: number
}
}
}一个完整的 Skill 示例
const craftItemSkill: SkillDeclaration = {
name: 'craft-item',
description: '根据配方合成物品',
version: '1.0.0',
input: {
type: 'object',
properties: {
itemName: { type: 'string' },
quantity: { type: 'number', default: 1 }
}
},
output: {
type: 'object',
properties: {
success: { type: 'boolean' },
crafted: { type: 'number' },
remaining: { type: 'object' }
}
},
triggers: {
keywords: ['合成', '做', 'craft', 'make'],
events: ['inventory_update']
},
capabilities: {
applicableScenes: ['safe_area', 'has_crafting_table'],
outputType: 'inventory_change',
collaborationWith: ['gather-resources', 'store-items']
},
execution: {
costEstimate: 500,
reliability: 0.95,
timeout: 5000
},
dependencies: {
requires: [], // 无前置依赖
conflicts: ['in-combat'],
mutex: ['inventory', 'crafting_table']
},
recovery: {
retryable: true,
fallbackSkill: 'craft-item-manual',
rollbackStrategy: 'none'
},
priority: {
base: 50,
modifiers: {
urgency: 0,
relevance: 10
}
}
}上下文管理
双轨制设计
| 组件 | 内容 | 处理方式 |
|---|---|---|
| 当前上下文窗口 | 近期对话、当前任务、活跃状态 | 智能压缩,保留关键信息 |
| 记忆系统 | 历史事件、玩家偏好、学习知识 | 持久化存储,查询式调用 |
智能压缩策略
interface CompressionStrategy {
// 触发时机
triggers: {
taskBoundary: boolean // 任务边界默认触发
thresholdRatio: number // 达到窗口 80% 强制触发
llmRequest: boolean // LLM 主动触发
}
// 压缩规则
rules: {
keep: string[] // 保留:关键决策、承诺、未完成任务
compress: string[] // 压缩:详细对话、中间过程
discard: string[] // 丢弃:临时状态
}
}
function compress(history: Message[], strategy: CompressionStrategy): CompressedHistory {
const kept: Message[] = []
const summary: string[] = []
for (const msg of history) {
if (shouldKeep(msg, strategy.rules.keep)) {
kept.push(msg)
} else if (shouldCompress(msg, strategy.rules.compress)) {
summary.push(summarize(msg))
}
// discard 的直接跳过
}
return {
messages: kept,
summary: summary.join('\n'),
compressionRatio: (history.length - kept.length) / history.length
}
}可回溯设计
压缩后如果发现遗漏关键信息:
async function recallFromMemory(query: string): Promise<string[]> {
// 从记忆系统重新加载
const memories = await memorySystem.query({
type: 'episodic',
keywords: extractKeywords(query),
limit: 5
})
return memories.map(m => m.content)
}MCP 集成:外部知识源
MCP 架构
┌─────────────────────────────────────────────────────────┐
│ MCP Integration │
├─────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ wiki-mcp │ │recipe-mcp │ │ map-mcp │ │
│ │ │ │ │ │ │ │
│ │ 游戏百科 │ │ 合成配方 │ │ 地图数据 │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌─────────────────────────────────────────────────┐ │
│ │ MCP Protocol Layer │ │
│ │ • Resource: 查询静态数据 │ │
│ │ • Tool: 执行查询操作 │ │
│ │ • Prompt: 预定义提示模板 │ │
│ └─────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────┘
Wiki MCP 示例
const wikiMCP: MCPServer = {
name: 'minecraft-wiki',
resources: [
{
uri: 'wiki://blocks',
name: '方块百科',
mimeType: 'application/json'
},
{
uri: 'wiki://mobs',
name: '生物百科',
mimeType: 'application/json'
}
],
tools: [
{
name: 'search_wiki',
description: '搜索 Wiki 内容',
parameters: {
query: { type: 'string' }
},
execute: async (params) => {
const results = await wikiSearch(params.query)
return { content: results }
}
}
]
}游戏扩展包
渐进式支持级别
| 级别 | 内容 | 体验 |
|---|---|---|
| 最小 | 仅 Plugin | 可运行,基础交互 |
| 标准 | Plugin + 游戏知识 | 理解游戏规则 |
| 完整 | Plugin + 知识 + 专用 Skills | 游戏特定决策 |
| 最佳 | 完整包 + 上下文模板 + 压缩配置 | 深度沉浸体验 |
扩展包结构
games/
└── minecraft/
├── plugin/
│ ├── actions.ts # 操作实现
│ ├── queries.ts # 状态查询
│ └── events.ts # 事件订阅
├── knowledge/
│ ├── wiki.json # 游戏知识
│ ├── recipes.json # 合成配方
│ └── biomes.json # 生物群系
├── skills/
│ ├── explore.ts # 探索技能
│ ├── survive.ts # 生存技能
│ └── build.ts # 建造技能
└── config/
├── context-template.ts # 上下文模板
└── compression.ts # 压缩策略
与其他路径的深度对比
| 维度 | ECHO_feeling | ECHO_loop | ECHO_CLAW |
|---|---|---|---|
| 设计哲学 | 理论驱动 | 工程驱动 | 实践驱动 |
| 智能来源 | 认知架构 | ReAct循环 | 上下文丰富度 |
| 决策方式 | 意愿强度 | Tool调用 | Skill编排 |
| 情感系统 | PAD/OCC双引擎 | 无 | 无(可扩展) |
| 记忆管理 | 七层认知管理 | 三层记忆 | 双轨制 |
| 扩展性 | 需修改架构 | 需修改Agent | 仅需Plugin |
| 可调试性 | 困难(涌现) | 中等 | 容易(声明式) |
| 适用场景 | 深度角色扮演 | 工程实践 | 通用游戏框架 |
当前状态
设计阶段完成,核心架构文档已产出。下一步:
- 创建项目骨架
- 实现核心三件套:上下文管理器、工具注册中心、执行引擎
- 开发 Minecraft Plugin 作为首例
- 编写基础 Skills
- 集成测试与迭代优化
相关链接
最后更新: 2026-05-13