跳到主要内容
Claw101
第11章 · 免费预计阅读 2 分钟

Skills 技能系统

Skill 是 OpenClaw 的能力扩展模块,让 Agent 拥有专业技能。

Skill 定义格式

Skill 使用 YAML 格式定义:

# skills/translator.yaml
name: "translator"
version: "1.0.0"
description: "多语言翻译技能"

parameters:
  - name: "text"
    type: "string"
    required: true
    description: "待翻译的文本"

  - name: "target_lang"
    type: "string"
    required: true
    enum: ["en", "zh", "ja", "ko"]
    description: "目标语言"

prompt_template: |
  请将以下文本翻译成 {{target_lang}}:

  {{text}}

  要求:
  - 保持原文语气和风格
  - 专业术语准确翻译
  - 符合目标语言习惯

model:
  prefer: "gpt-4-turbo"
  fallback: "claude-3-sonnet"

内置 Skills

OpenClaw 提供了一系列内置技能:

# config.yaml
skills:
  builtin:
    - name: "code_review"
      enabled: true

    - name: "data_analysis"
      enabled: true

    - name: "text_summarization"
      enabled: true

    - name: "image_generation"
      enabled: true
      config:
        provider: "dalle-3"

    - name: "web_search"
      enabled: true
      config:
        engine: "google"
        api_key: "${GOOGLE_API_KEY}"

自定义 Skill 开发

创建你自己的技能:

# skills/code_optimizer.yaml
name: "code_optimizer"
version: "1.0.0"
description: "代码性能优化建议"

input_schema:
  type: "object"
  properties:
    code:
      type: "string"
    language:
      type: "string"
      enum: ["javascript", "python", "go"]

steps:
  - name: "analyze"
    action: "llm"
    prompt: "分析以下 {{language}} 代码的性能瓶颈"

  - name: "optimize"
    action: "llm"
    prompt: "提供优化建议和重构代码"

  - name: "benchmark"
    action: "code_execution"
    script: "run_benchmark.py"

output_format:
  - 性能分析报告
  - 优化后的代码
  - 性能提升百分比

Skill 组合

将多个技能组合成工作流:

workflows:
  - name: "博客文章生成"
    description: "从想法到发布的完整流程"

    steps:
      - skill: "outline_generator"
        input:
          topic: "{{user_topic}}"

      - skill: "content_writer"
        input:
          outline: "{{step.1.output}}"

      - skill: "seo_optimizer"
        input:
          content: "{{step.2.output}}"

      - skill: "image_generator"
        input:
          prompt: "{{step.1.output.title}}"

      - skill: "publisher"
        input:
          content: "{{step.3.output}}"
          image: "{{step.4.output}}"

Skills 让 Agent 像人类专家一样具备专业能力。

学完这章想实战?加入社群获得 $50 算力额度 + 实时答疑

加入社群 ¥99