360 Secure SkillHub
360 安全技能中心

OpenClaw Model Switcher

读取本机 OpenClaw 配置文件,将用户请求的模型名与已配置的模型列表按精确、别名或部分匹配校验;校验通过后备份配置、只修改 agents.defaults.model.primary、重启 Gateway 并做健康检查,失败时自动回滚;无匹配模型时列出可选模型并停止操作。

lv-yezhen
lv-yezhen
热度 36.33
最近更新 2026-05-11 17:43:55
分类:自动化依赖:代码执行 / 读写文件应用场景:自动化脚本 / 工作流 / DevOps

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add openclaw-model-switcher
Metadata
name
model-switcher
description
Switch the OpenClaw default model safely. Triggers: switch model, change model, 切换模型, 换模型, switch to XX model. Use when the user wants to change the default AI model. Reads openclaw.json, validates the target model exists in the configured provider list, backs up config, modifies only agents.defaults.model.primary, restarts gateway, and auto-rolls back on failure.

Model Switcher

Switch the OpenClaw default model with backup, validation, and automatic rollback.

Workflow

Step 1: Validate Model Name

Read ~/.openclaw/openclaw.json. Extract:

  • Current model from agents.defaults.model.primary
  • Available models from models.providers list

Match user request against available models (exact, alias, or partial match):

  • Exact: zai/glm-5 → direct hit
  • Alias: "GLM 5" → zai/glm-5; "doubao" → volcengine-plan/doubao-seed-2.0-pro
  • Partial: "deepseek" → volcengine-plan/deepseek-v3.2

Step 2: Abort if Not Found

If no match, stop and report:

  • List all available models
  • Ask user to pick one

Never guess or execute blindly.

Step 3: Execute Switch

python3 scripts/model_switch.py <full-model-name> --retry 3

The script handles: backup → modify config → restart gateway → health check → auto-rollback on failure.

Step 4: Expect Session Interruption

Gateway restart kills the current session. This is normal. The session resumes automatically after Gateway recovers.

Constraints

  1. Only modify agents.defaults.model.primary — never touch the provider list
  2. Always validate model exists before switching
  3. Backups stored in ~/.openclaw/config_backups/
  4. Script has full backup + rollback — config will never be lost