Skill Cortex
Triggers when installed Skills cannot complete the current task. If you can handle it yourself, just do it — do not trigger this flow.
Cortex data file: ~/.openclaw/skill-cortex/cortex.json (schema in docs/DESIGN.md).
Phase 1: Perception
- 1. Read
cortex.json (if missing or corrupt, skip to step 3). - Semantically match the user's task description against
sensory.patterns signals (no exact match required — use your own judgment on intent alignment). On hit, look up the corresponding region in motor, sort candidates by effective weight (effective_weight = weight * max(0.3, 1 - days_since_last_used / 180)), filter out blacklisted and effective_weight < 0.3 entries, then proceed to Phase 2. - On miss, search ClawHub:
clawhub search "<3-5 English keywords>". Read summaries only, pick up to 3 candidates. If fewer than 2 relevant results, supplement with a GitHub search (mark as unreviewed source).
Phase 2: Validation & Authorization
Reflex Fast Path
The top candidate may enter reflex mode when ALL of the following hold:
- -
reflex: true AND effectiveweight >= 0.90 AND consecutive successes >= 5 - No write side effects (sideeffects contains no
write:/delete:/shell: prefix) - Version unchanged (slug + version match the stored record)
Reflex mode skips only the execution plan confirmation. Installation still requires user notification:
CODEBLOCK0
Version change automatically downgrades to standard mode.
Standard Mode
Present candidates to the user (name, description, stars, downloads, source, security scan status, history). Wait for explicit approval before installing.
If prefrontal.lessons contain experiences matching the current region, retain them for use in Phase 3.
Phase 3: Execution
3.1 Install
CODEBLOCK1
On failure, auto-switch to the next candidate. Max 2 switches, then stop and report.
3.2 Execution Plan
Read the installed Skill's SKILL.md and present to the user:
- - Step summary
- Side-effect severity: 🟢 read-only 🟡 write 🔴 destructive 🔑 sensitive credentials ⚙️ shell commands
- Relevant prefrontal lessons (if any) — e.g., proactively check for a dependency known to be commonly missing
Reflex mode skips this step. Standard mode waits for user confirmation.
3.3 Execute
Follow the Skill's instructions to complete the task.
3.4 Failure Recovery
| Type | Handling |
|---|
| INLINECODE12 | Show the user what needs to be installed, proceed only after confirmation |
| INLINECODE13 |
Wait 3 seconds, retry once |
|
auth_error | Prompt user to check credentials, do not auto-retry |
|
task_mismatch | Uninstall, suggest switching to next candidate |
|
runtime_error | Uninstall, suggest switching to next candidate |
Switching candidates requires user consent. After all candidates fail, provide a full report with each failure reason and suggested remediation.
Phase 4: Learning & Cleanup
Execute regardless of success or failure.
4.1 Update Motor
Success: new_weight = old + (1 - old) * 0.15 * (1 / (1 + successes_in_last_7d))
Failure: new_weight = old * decay (task_mismatch: 0.4 / runtime: 0.6 / auth: 0.8 / dependency: 0.85 / api: 0.9)
New Skill initial weight = 0.5. Record skill_md_chars (SKILL.md character count) and version.
Create region if it doesn't exist. Update last_used.
4.2 Update Sensory
When this task was resolved via search (sensory miss), extract 2–4 signal words from the task description and merge into the corresponding region's pattern. Merge into existing patterns; do not create duplicates.
Entity Filtering (mandatory): Before writing signal words, strip all concrete entities — personal names, company names, place names, dates, numeric values, filenames, URLs, emails, etc. Retain only verbs and abstract nouns.
Example: user says "Look up Alice's Q3 sales report" → signals should be ["query", "sales", "report"], NOT ["Alice", "Q3"].
4.3 Update Prefrontal
Record structured lessons only in the following cases (no free-form):
CODEBLOCK2
Confidence +0.1 each time validated (cap 1.0). Remove when < 0.3 during pruning.
4.4 Reflex Promotion
Set reflex: true when ALL conditions are met: success >= 5, weight >= 0.90, no write side effects.
Immediately reset reflex: false on any failure or version change.
4.5 Cleanup
Default: uninstall. INLINECODE26
Suggest retention (when ALL met): success >= 3, weight >= 0.8, skillmdchars < 8000.
Approved → keep installed, remove record from motor (transfers to OpenClaw native management). Declined → uninstall normally.
4.6 Pruning
- - Motor: max 5 candidates per region / max 80 regions / remove effective_weight < 0.1
- Sensory: remove pattern when its region is pruned / max 10 signals per pattern
- Prefrontal: max 30 lessons / remove confidence < 0.3 / remove if linked region is pruned
Boundary Rules
- 1. Never interfere with long-term Skills.
- Installation requires user confirmation (including reflex mode).
- System dependency installation requires separate confirmation.
- Write operations never enter reflex. Reflex locks version; version change auto-downgrades.
- Max 2 candidate switches.
- On cortex file corruption, degrade to direct ClawHub search; rebuild after task.
- Read latest cortex file before writing; merge changes, never overwrite.
- Single-session design; cortex data may be inconsistent under concurrent sessions.
技能皮层
当已安装的技能无法完成当前任务时触发。如果你能自行处理,直接执行即可——不要触发此流程。
皮层数据文件:~/.openclaw/skill-cortex/cortex.json(架构见 docs/DESIGN.md)。
第一阶段:感知
- 1. 读取 cortex.json(如果缺失或损坏,跳至步骤3)。
- 语义匹配用户任务描述与 sensory.patterns 信号(无需精确匹配——自行判断意图对齐)。命中时,在 motor 中查找对应区域,按有效权重排序候选(有效权重 = 权重 * max(0.3, 1 - 距上次使用天数 / 180)),过滤掉黑名单和有效权重 < 0.3 的条目,然后进入第二阶段。
- 未命中时,搜索 ClawHub:clawhub search <3-5个英文关键词>。仅阅读摘要,选取最多 3 个候选。如果相关结果少于2个,补充 GitHub 搜索(标记为未审核来源)。
第二阶段:验证与授权
反射快速路径
当满足所有以下条件时,最佳候选可进入反射模式:
- - reflex: true 且有效权重 >= 0.90 且连续成功次数 >= 5
- 无写入副作用(side_effects 不包含 write:/delete:/shell: 前缀)
- 版本未变更(slug + 版本与存储记录匹配)
反射模式仅跳过执行计划确认。安装仍需用户通知:
⚡ 技能皮层反射:todoist-cli v1.2.0(96% 成功率)
任务:查询今日待办(只读)| 即将安装并执行。说取消可中止。
版本变更自动降级为标准模式。
标准模式
向用户展示候选(名称、描述、星标、下载量、来源、安全扫描状态、历史记录)。等待明确批准后再安装。
如果 prefrontal.lessons 包含与当前区域匹配的经验,保留以供第三阶段使用。
第三阶段:执行
3.1 安装
bash
clawhub install
失败时,自动切换到下一个候选。最多切换 2 次,然后停止并报告。
3.2 执行计划
读取已安装技能的 SKILL.md 并向用户展示:
- - 步骤摘要
- 副作用严重程度:🟢 只读 🟡 写入 🔴 破坏性 🔑 敏感凭据 ⚙️ shell 命令
- 相关的前额叶经验(如有)——例如,主动检查已知常缺失的依赖项
反射模式跳过此步骤。标准模式等待用户确认。
3.3 执行
按照技能的指令完成任务。
3.4 失败恢复
| 类型 | 处理方式 |
|---|
| dependencymissing | 向用户展示需要安装的内容,确认后继续 |
| apierror |
等待3秒,重试一次 |
| auth_error | 提示用户检查凭据,不自动重试 |
| task_mismatch | 卸载,建议切换到下一个候选 |
| runtime_error | 卸载,建议切换到下一个候选 |
切换候选需要用户同意。所有候选均失败后,提供完整报告,包含每个失败原因和建议的修复措施。
第四阶段:学习与清理
无论成功或失败均执行。
4.1 更新运动区
成功:新权重 = 旧权重 + (1 - 旧权重) 0.15 (1 / (1 + 最近7天成功次数))
失败:新权重 = 旧权重 * 衰减系数(任务不匹配:0.4 / 运行时:0.6 / 认证:0.8 / 依赖:0.85 / API:0.9)
新技能初始权重 = 0.5。记录 skillmdchars(SKILL.md 字符数)和 version。
如果区域不存在则创建。更新 last_used。
4.2 更新感知区
当此任务通过搜索解决(感知未命中)时,从任务描述中提取2-4个信号词,合并到对应区域的模式中。合并到现有模式中;不创建重复项。
实体过滤(强制): 写入信号词前,去除所有具体实体——人名、公司名、地名、日期、数值、文件名、URL、电子邮件等。仅保留动词和抽象名词。
示例:用户说查找 Alice 的 Q3 销售报告 → 信号应为 [query, sales, report],而非 [Alice, Q3]。
4.3 更新前额叶
仅在以下情况下记录结构化经验(无自由格式):
jsonc
// 类型1:同一失败类型出现2次以上 → 依赖预检查
{ type: dependencywarning, region: ..., key: imagemagick, action: checkbinbeforeinstall, confidence: 0.6 }
// 类型2:技能描述与实际能力不匹配
{ type: skillqualitywarning, slug: xxx, detail: 不支持批量操作, confidence: 0.6 }
// 类型3:用户环境通常已就绪
{ type: envready, region: ..., key: TODOISTAPI_KEY, confidence: 0.6 }
每次验证通过置信度 +0.1(上限 1.0)。修剪时置信度 < 0.3 则移除。
4.4 反射晋升
当满足所有条件时设置 reflex: true:成功次数 >= 5,权重 >= 0.90,无写入副作用。
任何失败或版本变更时立即重置 reflex: false。
4.5 清理
默认:卸载。 clawhub uninstall
建议保留(满足所有条件时):成功次数 >= 3,权重 >= 0.8,skillmdchars < 8000。
批准 → 保持安装状态,从运动区移除记录(转移至 OpenClaw 原生管理)。拒绝 → 正常卸载。
4.6 修剪
- - 运动区:每区域最多5个候选 / 最多80个区域 / 移除有效权重 < 0.1
- 感知区:其区域被修剪时移除模式 / 每模式最多10个信号
- 前额叶:最多30条经验 / 移除置信度 < 0.3 / 关联区域被修剪时移除
边界规则
- 1. 绝不干扰长期技能。
- 安装需要用户确认(包括反射模式)。
- 系统依赖安装需要单独确认。
- 写入操作从不进入反射。反射锁定版本;版本变更自动降级。
- 最多2次候选切换。
- 皮层文件损坏时,降级为直接 ClawHub 搜索;任务完成后重建。
- 写入前读取最新皮层文件;合并变更,绝不覆盖。
- 单会话设计;并发会话下皮层数据可能不一致。