技能系统 (Archive)
Archived original-language source from the legacy CrabClaw docs. This page is intentionally not machine-translated.
Crab Claw 的技能系统基于 SKILL.md 声明式文件,让你可以用 Markdown + YAML 定义智能体的行为指令和组合工具。
核心理念
- Skill 是声明(描述"想要什么"),Tool 是执行(实现"怎么做")
- 技能绑定到能力树中的工具节点,为工具注入领域知识
- 组合技能通过
tool_schema将多个原子工具编排成自动化流水线
技能类型
工具技能
绑定到能力树中的具体工具,为 LLM 提供该工具的使用指导:
---
name: bash
description: "Shell 命令执行,支持审批治理"
tools:
- bash
metadata:
crabclaw:
tree_id: runtime/bash
tree_group: runtime
min_tier: task_light
approval_type: exec_escalation
---
执行 Shell 命令时需遵守以下规则...---
name: bash
description: "Shell 命令执行,支持审批治理"
tools:
- bash
metadata:
crabclaw:
tree_id: runtime/bash
tree_group: runtime
min_tier: task_light
approval_type: exec_escalation
---
执行 Shell 命令时需遵守以下规则...操作技能
不绑定特定工具,指导智能体完成特定领域的操作流程(如频道管理、模型配置、定时任务等)。
组合技能
通过 tool_schema 定义多步骤自动化流水线,编译后生成 skill_ 前缀的组合工具:
metadata:
crabclaw:
tool_schema:
input:
type: object
properties:
content: { type: string }
platforms: { type: array, items: { type: string } }
steps:
- action: "读取内容"
tool: read_file
input_map:
path: "{{input.content}}"
output_as: file_content
- action: "发布到各平台"
tool: message
loop_over: "{{input.platforms}}"
input_map:
channel: "{{item}}"
text: "{{file_content}}"metadata:
crabclaw:
tool_schema:
input:
type: object
properties:
content: { type: string }
platforms: { type: array, items: { type: string } }
steps:
- action: "读取内容"
tool: read_file
input_map:
path: "{{input.content}}"
output_as: file_content
- action: "发布到各平台"
tool: message
loop_over: "{{input.platforms}}"
input_map:
channel: "{{item}}"
text: "{{file_content}}"技能文件位置
技能按优先级从以下位置加载:
- 工作区技能:
docs/skills/目录下 - 用户技能:
~/.crabclaw/skills/ - 内置技能: 随 Crab Claw 安装包分发
技能编译
组合技能需要编译后才能使用:
# 编译所有含 tool_schema 的技能
crabclaw skills codegen
# 预览编译结果(不写入)
crabclaw skills codegen --dry-run
# 查看已编译的组合工具
crabclaw skills codegen --status
# 编译指定技能
crabclaw skills codegen --name media-cross-publish# 编译所有含 tool_schema 的技能
crabclaw skills codegen
# 预览编译结果(不写入)
crabclaw skills codegen --dry-run
# 查看已编译的组合工具
crabclaw skills codegen --status
# 编译指定技能
crabclaw skills codegen --name media-cross-publish编译产物存储在 ~/.crabclaw/state/composed_tools.json,智能体运行时自动加载。
技能发现
智能体通过以下机制发现和使用技能:
- 意图分析: 根据用户消息分析意图层级(greeting → task_light → task_write → task_delete → task_multimodal)
- 能力树匹配: 匹配意图层级对应的工具节点
- 技能注入: 将匹配工具绑定的技能内容注入 LLM 上下文
变量模板
组合技能中的 input_map 支持变量模板:
| 模板语法 | 说明 | 示例 |
|---|---|---|
{{input.field}} | 引用用户输入字段 | {{input.content}} |
{{step_name.field}} | 引用前一步骤的输出 | {{file_content}} |
{{item}} | 循环变量(在 loop_over 中) | {{item}} |
错误处理
每个步骤可设置错误策略:
abort(默认): 中止整个流水线skip: 跳过当前步骤,继续执行retry: 最多重试 2 次
审批继承
组合工具的审批级别从其步骤中自动推导,取所有步骤中最高的审批类型。