CLI 命令参考
OpenClaw CLI是平台的核心命令行工具,提供了从项目初始化到Agent管理、工具配置、模型操作、插件安装和系统监控的全套功能。本手册详细列出所有可用命令及其参数选项。
openclaw init
初始化一个新的OpenClaw项目,创建项目结构和默认配置文件:
# 基本初始化
openclaw init my-project
# 指定模板初始化
openclaw init my-project --template research-assistant
# 使用交互式向导
openclaw init my-project --interactive
# 初始化选项:
# --template, -t 项目模板名称(可选值:basic, research-assistant,
# coding-helper, multi-agent, custom)
# --interactive, -i 启用交互式配置向导
# --no-git 不初始化Git仓库
# --python-version 指定Python版本(默认:3.11)
# --config 指定配置文件路径
提示:项目模板
使用 --template 参数可以快速创建特定场景的项目结构。每个模板包含预配置的Agent定义、工具集成和示例工作流,帮助您快速启动开发。
openclaw agent
管理Agent的创建、运行、调试和生命周期:
# 创建新Agent
openclaw agent create research-bot \
--type conversational \
--model gpt-4o \
--tools web_search,document_reader
# 运行Agent
openclaw agent run research-bot \
--input "分析最新的AI Agent论文" \
--output-format json \
--verbose
# 列出所有Agent
openclaw agent list --status running
# 停止Agent
openclaw agent stop research-bot --graceful
# 查看Agent状态
openclaw agent status research-bot --detail
# 子命令说明:
# create 创建新Agent实例
# run 运行Agent并处理输入
# list 列出Agent(支持过滤)
# stop 停止运行中的Agent
# status 查看Agent详细状态
# logs 查看Agent运行日志
# delete 删除Agent定义
openclaw tool
管理和测试Agent可以使用的工具:
# 注册自定义工具
openclaw tool register my-tool \
--handler ./tools/my_tool.py \
--schema ./tools/my_tool_schema.json
# 测试工具调用
openclaw tool test web_search \
--params '{"query": "AI agent framework", "max_results": 5}' \
--output json
# 列出已注册工具
openclaw tool list --category builtin
# 查看工具详情
openclaw tool info web_search
# 子命令说明:
# register 注册新工具
# test 测试工具调用
# list 列出所有工具
# info 查看工具详情
# unregister 注销工具
# validate 验证工具Schema
openclaw model
管理AI模型的注册、测试和性能评估:
# 注册模型提供商
openclaw model provider add my-openai \
--type openai \
--api-key-env OPENAI_API_KEY \
--base-url https://api.openai.com/v1
# 列出可用模型
openclaw model list --provider openai --format table
# 测试模型连通性
openclaw model test gpt-4o \
--prompt "Hello, world!" \
--max-tokens 100
# 模型基准测试
openclaw model benchmark gpt-4o \
--suite general \
--output report.html
# 子命令说明:
# provider 管理模型提供商
# list 列出可用模型
# test 测试模型响应
# benchmark 运行基准测试
# compare 对比多个模型性能
核心概念:模型基准测试
基准测试套件包括:general(通用问答)、coding(代码生成)、reasoning(逻辑推理)、math(数学计算)。测试结果会生成详细的HTML报告,包含延迟、吞吐量、准确率等指标。
openclaw config
管理OpenClaw配置文件的查看、编辑和验证:
# 验证配置文件
openclaw config validate --file config.yaml
# 显示当前生效配置
openclaw config show --format yaml
# 生成配置模板
openclaw config generate --mode production > config.yaml
# 对比配置差异
openclaw config diff base.yaml production.yaml
# 子命令说明:
# validate 验证配置文件语法和语义
# show 显示合并后的配置
# generate 生成配置模板
# diff 对比两个配置文件
# get 获取特定配置值
# set 设置配置值(运行时覆盖)
openclaw plugin
管理OpenClaw插件的安装、卸载和更新:
# 安装插件
openclaw plugin install openclaw-slack-integration
# 从本地路径安装
openclaw plugin install --path ./my-plugin/
# 列出已安装插件
openclaw plugin list --status active
# 更新插件
openclaw plugin update openclaw-slack-integration
# 卸载插件
openclaw plugin uninstall openclaw-slack-integration
# 搜索可用插件
openclaw plugin search notification
# 子命令说明:
# install 安装插件
# uninstall 卸载插件
# list 列出已安装插件
# update 更新插件
# search 搜索插件仓库
# info 查看插件详情
openclaw monitor
监控系统运行状态、Agent性能和资源使用情况:
# 实时仪表板
openclaw monitor dashboard
# 查看系统状态
openclaw monitor status --format json
# 查看资源使用
openclaw monitor resources --interval 5s
# 查看Agent性能指标
openclaw monitor metrics --agent research-bot \
--metric latency,throughput,error_rate \
--period 1h
# 导出监控数据
openclaw monitor export \
--from 2024-01-01 \
--to 2024-01-31 \
--format csv \
--output metrics.csv
# 子命令说明:
# dashboard 启动实时Web仪表板
# status 查看系统整体状态
# resources 查看CPU/内存/GPU使用率
# metrics 查看Agent性能指标
# export 导出监控数据
# alerts 查看活跃告警
提示:输出格式
大多数命令支持 --output 或 --format 参数,可选值包括:table(默认,人类可读的表格格式)、json(结构化JSON输出)、yaml(YAML格式)、csv(逗号分隔值)。在脚本中建议使用 json 格式,方便程序化处理。
全局选项
以下选项适用于所有CLI命令:
--config, -c:指定配置文件路径(默认:./config.yaml)--verbose, -v:启用详细输出模式--quiet, -q:静默模式,仅输出关键信息--no-color:禁用彩色输出--log-level:设置日志级别(DEBUG/INFO/WARNING/ERROR)--timeout:设置命令超时时间(秒)--help, -h:显示帮助信息--version:显示版本号
# 使用全局选项的示例
openclaw --config /etc/openclaw/prod.yaml \
--verbose \
agent run research-bot \
--input "分析市场趋势" \
--output json
警告:生产环境使用
在生产环境中运行CLI命令时,建议使用 --quiet 标志减少日志输出,并通过 --config 明确指定配置文件路径,避免使用默认路径导致配置错误。