自动切换模型 - 当模型token用完或限流时,自动切换到备用模型,并通知用户。支持配置多个备用模型,智能切换策略。
当主模型token用完或遇到限流时,自动切换到备用模型,确保对话不中断。
bash
cd ~/.openclaw/workspace/skills/auto-model-switch
npm install
编辑 config.yaml:
yaml
models:
- id: primary
model: custom-maas-coding-api-cn-huabei-1-xf-yun-com/astron-code-latest
name: Astron Code
daily_limit: 10000000
priority: 1
- id: backup-1
model: zai/glm-5
name: GLM-4.5
daily_limit: null
priority: 2
在 HEARTBEAT.md 中添加:
markdown
| 命令 | 说明 |
|---|---|
| node automodelswitch.js status | 查看当前模型状态 |
| node automodelswitch.js switch |
yaml
models:
- id: primary # 模型标识
model: model-id # OpenClaw模型ID
name: 显示名称 # 友好名称
daily_limit: 10000000 # 每日token限制(null=无限制)
priority: 1 # 优先级(数字越小越优先)
auto_switch:
onlimitexceeded: true # token用完时切换
onratelimit: true # 限流时切换
retry_delay: 60 # 限流后重试延迟(秒)
warning_threshold: 0.8 # 警告阈值
critical_threshold: 0.95 # 切换阈值
notification:
enabled: true # 启用通知
设置环境变量以启用网关集成:
bash
export OPENCLAWGATEWAYURL=http://localhost:3000
export OPENCLAWGATEWAYTOKEN=your-token
📊 模型状态
当前:Astron Code
Token:8.5M / 10M (85%)
备用模型:
auto-model-switch/
├── SKILL.md # 本文件
├── config.yaml # 模型配置
├── automodelswitch.js # 主脚本
├── heartbeat.js # 心跳脚本
├── package.json # Node.js配置
├── QUICKSTART.md # 快速开始
└── state/ # 状态目录(自动创建)
├── model-switch.json # 当前状态
└── switch-history.json # 切换历史
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 auto-model-switch-1776025782 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 auto-model-switch-1776025782 技能
skillhub install auto-model-switch-1776025782
文件大小: 12.48 KB | 发布时间: 2026-4-13 09:25