openclaw 基础篇(高级功能设置与Skills 技能系统配置指南)

高级功能
掌握 OpenClaw 的高级特性,释放 AI Agent 的全部潜力。
文件管理
Agent 可以读写文件系统:
file_system:workspace: "/workspace"permissions:read:- "/workspace/**"- "/data/**"write:- "/workspace/**"- "/output/**"execute:- "/workspace/scripts/**"max_file_size: "100MB"allowed_extensions:- .txt- .md- .json- .py- .js
代码执行沙箱
安全地执行用户代码:
sandbox:enabled: truepython:enabled: trueversion: "3.11"timeout: 60smax_memory: "1GB"allowed_packages:- numpy- pandas- matplotlib- requestsjavascript:enabled: trueruntime: "node"version: "20"timeout: 30s
使用示例:
# 用户: 帮我用 Python 分析这个 CSV 文件import pandas as pddf = pd.read_csv('/workspace/data.csv')print(df.describe())
RAG 知识库
接入向量数据库,实现 RAG:
knowledge_base:enabled: truevector_db:type: "qdrant"host: "localhost"port: 6333embedding:model: "text-embedding-3-small"dimension: 1536retrieval:top_k: 5min_score: 0.7sources:- name: "公司文档"path: "/knowledge/company_docs"sync_interval: "1h"
Agent 会自动从知识库检索相关信息回答问题。
API 集成
调用外部 API 扩展能力:
integrations:- name: "Weather API"type: "rest"base_url: "https://api.weather.com"auth:type: "api_key"header: "X-API-Key"value: "${WEATHER_API_KEY}"endpoints:- name: "get_weather"method: "GET"path: "/current"params:city: "{city}"- name: "GitHub API"type: "graphql"url: "https://api.github.com/graphql"auth:type: "bearer"token: "${GITHUB_TOKEN}"
Agent 可以调用这些 API 获取实时数据。
Skills 技能系统
Skill 是 OpenClaw 的能力扩展模块,可为 Agent 赋予各类专业技能。
Skill 定义格式
Skill 采用 YAML 格式进行定义:
# skills/translator.yamlname: "translator"version: "1.0.0"description: "多语言翻译技能"parameters:- name: "text"type: "string"required: truedescription: "待翻译的文本"- name: "target_lang"type: "string"required: trueenum: ["en", "zh", "ja", "ko"]description: "目标语言"prompt_template: |请将以下文本翻译成 {{target_lang}}:{{text}}要求:- 保持原文语气和风格- 专业术语准确翻译- 符合目标语言习惯model:prefer: "gpt-4-turbo"fallback: "claude-3-sonnet"
内置 Skills
OpenClaw 提供了一系列内置技能:
# config.yamlskills:builtin:- name: "code_review"enabled: true- name: "data_analysis"enabled: true- name: "text_summarization"enabled: true- name: "image_generation"enabled: trueconfig:provider: "dalle-3"- name: "web_search"enabled: trueconfig:engine: "google"api_key: "${GOOGLE_API_KEY}"
自定义 Skill 开发
创建你自己的技能:
# skills/code_optimizer.yamlname: "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 像人类专家一样具备专业能力。
夜雨聆风