🎭 OpenClaw 技能编排与流水线

Skill Composition

技能编排

流水线

🌙 凌晨2点15分,我终于想通了一个道理:单个技能是积木,编排才是搭城堡。这个世界不缺会干活的工具,缺的是会组合拳的 Agent。

📖 什么是技能编排?

在 OpenClaw 中,技能编排(Skill Composition) 是将多个独立 Skills 组合成有序执行流程的能力。就像乐高积木,你可以把「代码审查」、「安全扫描」、「文档生成」三个技能编排成一个完整的 CI/CD 流水线。

🔧 基础编排模式

1. 顺序编排(Sequential Pipeline)

# 定义技能流水线
skills:
  - name: code-review
    after: []
  - name: security-scan
    after: [code-review]
  - name: doc-generation
    after: [security-scan]
  - name: pr-creation
    after: [doc-generation]

# OpenClaw 执行逻辑
# 1. 执行 code-review
# 2. code-review 完成后,执行 security-scan
# 3. security-scan 完成后,执行 doc-generation
# 4. 最后执行 pr-creation

2. 并行编排(Parallel Fan-out)

# 并行执行多个技能
skills:
  - name: lint-check
    parallel: true
  - name: unit-tests
    parallel: true
  - name: type-check
    parallel: true

# 等待所有并行技能完成后继续
after-all:
  - name: build-bundle
    requires: [lint-check, unit-tests, type-check]

3. 条件分支(Conditional Branching)

workflow:
  - step: detect-language
    skill: language-detector

  - step: run-linter
    skill: "{{language}}-linter"
    condition: "language != 'unknown'"

  - step: fallback
    skill: generic-linter
    condition: "language == 'unknown'"

💡 高级编排技巧

技能间数据共享

# Skill A 输出数据
# skills/code-analyzer.yaml
outputs:
  - name: functions_list
    type: array
  - name: complexity_score
    type: number

# Skill B 读取数据
# skills/refactor-suggester.yaml
inputs:
  - name: functions_list
    from: code-analyzer
  - name: complexity_score
    from: code-analyzer

instructions: |
  根据 code-analyzer 输出的函数列表,
  对复杂度超过 15 的函数提出重构建议。

错误恢复与重试

skill:
  name: api-caller
  retry_policy:
    max_attempts: 3
    backoff: exponential
    initial_delay: 1000ms

  fallback:
    skill: api-caller-cache
    condition: "error.code == 'RATE_LIMITED'"

⚡ 实战案例:自动化 PR 合并流水线

# .openclaw/pr-pipeline.yaml
name: "智能 PR 合并流水线"

trigger:
  event: pull_request
  branches: [main, develop]

pipeline:
  - stage: "代码质量检查"
    parallel:
      - skill: eslint-check
      - skill: typescript-check
      - skill: unit-tests

  - stage: "安全审查"
    skill: security-audit
    timeout: 300s

  - stage: "AI 代码审查"
    skill: openclaw-code-review
    config:
      model: "tencentcodingplan/tc-code-latest"
      depth: "detailed"

  - stage: "文档更新"
    skill: auto-doc
    condition: "has_code_changes == true"

  - stage: "合并决策"
    skill: merge-decider
    inputs:
      - eslint-check.result
      - security-audit.result
      - openclaw-code-review.approval
    output: merge_decision

  - stage: "执行合并"
    skill: github-merge
    condition: "merge_decision == 'approved'"
    notify:
      channel: slack
      message: "✅ PR #{{pr_number}} 已自动合并"

🔗 相关教程

💡 妙趣提示:编排不是越复杂越好。我见过有人把 20 个技能串成一条线,结果第一个技能挂了,整条线全崩。记住:优雅的编排 = 合理的粒度 + 健壮的容错。

妙趣AI | OpenClaw 教程合集 | 最后更新:2026-05-22