SuperAPI AI 工具集

openclaw-admin

部署与运维

查看项目

更新于 10-16 08:26

技能介绍

用途

openclaw-admin 用于管理 OpenClaw 网关,覆盖 core-openclaw 集群的日常运维任务,包括网关的启动、停止、重启、更新,配置补丁的应用,compaction 设置的调优,以及集群内代理(agent)的管理。

主要能力

  • 网关生命周期管理:通过 CLI 命令启动、停止、重启或更新网关,例如 openclaw gateway start --cluster core-openclaw --force。
  • 配置补丁:应用 JSON Patch 文档,例如 {"op": "replace", "path": "/settings/compaction", "value": {"interval": 60}}。
  • Compaction 调优:通过参数调整设置,例如 openclaw compaction tune --threshold 80 --interval 300,用于设定内存阈值和间隔。
  • 代理管理:使用命令添加、移除或列出代理,例如 openclaw agent add --name agent1 --cluster core-openclaw。
  • 身份验证:所有操作均需要 $OPENCLAW_API_KEY 环境变量。

使用方式

运行命令前需先设置 $OPENCLAW_API_KEY,例如 export OPENCLAW_API_KEY=your_api_key。CLI 使用时以 openclaw 为前缀,并指定 --cluster core-openclaw 标志。API 调用使用 HTTP 请求,并携带 Authorization: Bearer $OPENCLAW_API_KEY 请求头。在脚本中,建议将调用包裹在错误检查中,例如在修补配置前先确认集群存在。自动化场景下,可通过 bash 脚本调用 CLI,集成到 cron 任务或 CI/CD 流水线中。

常用命令与 API 示例:

  • 启动网关:CLI openclaw gateway start --cluster core-openclaw --env prod;API POST /api/gateway/start,请求体 {"cluster": "core-openclaw", "env": "prod"}。
  • 停止网关:CLI openclaw gateway stop --cluster core-openclaw --force;API POST /api/gateway/stop,请求体 {"cluster": "core-openclaw"}。
  • 重启网关:CLI openclaw gateway restart --cluster core-openclaw;API POST /api/gateway/restart,请求体 {"cluster": "core-openclaw"}。
  • 更新网关:CLI openclaw gateway update --cluster core-openclaw --version 2.1.0;API POST /api/gateway/update,请求体 {"cluster": "core-openclaw", "version": "2.1.0"}。
  • 应用配置补丁:CLI openclaw config patch --file config.patch.json --cluster core-openclaw;API PATCH /api/config,请求体来自 JSON 文件,例如 {"op": "add", "path": "/agents", "value": ["agent1"]}。
  • 调优 compaction:CLI openclaw compaction tune --cluster core-openclaw --threshold 75 --interval 600;API PUT /api/compaction,请求体 {"threshold": 75, "interval": 600}。
  • 管理代理:CLI openclaw agent add --name agent2 --cluster core-openclaw;API POST /api/agents,请求体 {"name": "agent2", "cluster": "core-openclaw"}。

API 调用代码片段(重启网关):

export OPENCLAW_API_KEY=your_key
curl -X POST https://api.openclaw.com/api/gateway/restart \
-H "Authorization: Bearer $OPENCLAW_API_KEY" \
-d '{"cluster": "core-openclaw"}'

配置补丁代码片段:

{"op": "replace", "path": "/settings/logLevel", "value": "debug"}

适用场景

  • 网关维护:部署期间应用更新、出错后重启、为提升性能调整 compaction 等。
  • 生产环境:在 core-openclaw 集群处于活动状态时使用。
  • 分布式环境:进行代理生命周期管理。
  • 自动化集成:通过 cron 任务或 CI/CD 流水线调用 CLI。

限制与注意事项

  • 所有操作均依赖 $OPENCLAW_API_KEY,需确保其已设置且有效。
  • 命令需指定 --cluster core-openclaw,外部系统需兼容 core-openclaw 集群端点(如通过 HTTPS)。
  • 错误处理:认证错误(HTTP 401)需检查密钥;网关未找到(HTTP 404)可用 openclaw gateway status --cluster core-openclaw 确认集群状态;CLI 错误可从 stderr 解析,如 "Error: Cluster core-openclaw not reachable" 表示网络问题,可用指数退避重试;配置补丁的无效 JSON 需在脚本中用 try-catch 处理。常见 API 错误包括 400(请求体格式错误)和 500(服务器问题,需记录并告警)。
  • 与其他技能组合时,可将输出作为输入传递,例如将本技能产生的代理 ID 用于监控工具。

具体使用示例

配置变更后重启网关:先导出密钥 export OPENCLAW_API_KEY=your_api_key,再应用补丁 openclaw config patch --file patch.json --cluster core-openclaw(patch.json 内容为 {"op": "replace", "path": "/settings/restartTrigger", "value": true}),最后重启 openclaw gateway restart --cluster core-openclaw。

调优 compaction 并添加代理以优化性能:先调优 openclaw compaction tune --cluster core-openclaw --threshold 85 --interval 900,再添加代理 openclaw agent add --name monitoring-agent --cluster core-openclaw,最后用 openclaw agent list --cluster core-openclaw 验证代理是否处于活动状态。

集成说明

可通过 "openclaw-admin" ID 将该技能导入 AI 工作流。向量搜索可使用嵌入提示 "openclaw gateway restart update config compaction agent"。在环境文件中设置 $OPENCLAW_API_KEY 以实现安全访问,所有命令追加 --cluster core-openclaw 以处理集群特定配置。