
Model Fallback
- 47 installs
- 82 repo stars
- Updated August 2, 2026
- aaaaqwq/claude-code-skills
model-fallback is a Claude Code skill that automatically fails over to a backup model when the primary model request fails, times out, or hits rate or quota limits.
About
model-fallback is a Claude Code skill that provides automatic model downgrade and failover. When a primary model request fails, times out, or hits a rate limit or quota, it switches to a backup model to keep service running. It supports multi-provider, priority-based model selection with health monitoring, auto-retry, and error recovery, and switches back once the primary recovers. A developer uses it to keep an AI agent reliable across model outages. The SKILL.md is written in Chinese.
- Automatically switches to a backup model when the primary fails, times out, or hits rate/quota limits
- Supports multi-provider, priority-based failover with health monitoring and auto-retry
- Switches back to the primary model once it recovers
Model Fallback by the numbers
- 47 all-time installs (skills.sh)
- Ranked #7,461 of 16,556 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Aug 3, 2026 (Skillselion catalog sync)
model-fallback capabilities & compatibility
- Capabilities
- model failover · auto retry · rate limit handling · model routing
- Use cases
- orchestration
- Pricing
- Free
What model-fallback says it does
当主模型请求失败、超时、达到速率限制或配额耗尽时,自动切换到备用模型,确保服务连续性。
**切换**: 自动降级到备用模型
npx skills add https://github.com/aaaaqwq/claude-code-skills --skill model-fallbackAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 47 |
|---|---|
| repo stars | ★ 82 |
| Last updated | August 2, 2026 |
| Repository | aaaaqwq/claude-code-skills ↗ |
What it does
Automatically fail over to a backup model when the primary model errors, times out, or is rate-limited.
Who is it for?
Keeping an AI agent running when a model fails, times out, or is rate-limited
Skip if: Choosing a model by task complexity or cost (that is model routing, not failover)
When should I use this skill?
A model request fails, times out, hits a rate limit, or exhausts quota
What you get
Continuous service through automatic failover to a backup model, with retry and automatic switch-back once the primary recovers.
- Automatic failover to a backup model
- Auto-retry of failed requests
- Automatic switch-back on primary recovery
By the numbers
- Handles 3 error classes: timeout, quota/rate-limit, error
Files
模型自动降级与故障切换
- Author: Daniel Li
- Copyright © Daniel Li. All rights reserved.
当使用此技能
- 模型请求失败
- API 超时
- 达到速率限制
- 配额耗尽
- 需要确保服务连续性
工作原理
1. 监控: 检测模型请求状态 2. 判断: 识别失败类型(超时/限额/错误) 3. 切换: 自动降级到备用模型 4. 重试: 失败请求自动重试 5. 恢复: 主模型恢复后自动切回
多供应商支持
- 优先级配置
- 跨供应商故障转移
- 智能负载均衡
错误类型
- 超时: 切换到更快模型
- 限额: 切换到有配额模型
- 错误: 切换到不同供应商
触发词
- "模型降级"
- "自动切换"
- "模型故障"
- "API 失败"
模型自动降级 Skill 安装指南
📦 已安装的文件
核心文件
~/.openclaw/agents/main/agent/agent.json # 主配置文件
~/.openclaw/scripts/model-fallback.sh # 切换脚本
~/.openclaw/scripts/monitor-models.sh # 监控脚本Skill 文件
~/clawd/skills/model-fallback/SKILL.md # Skill 文档
~/clawd/skills/model-fallback/README.md # 使用指南
~/clawd/skills/model-fallback/scripts/auto-switch-handler.sh # 自动错误处理
~/clawd/skills/model-fallback/scripts/model-error-wrapper.sh # 请求包装器
~/clawd/skills/model-fallback/tests/test-error-handling.sh # 测试脚本支持文件
~/clawd/scripts/test-model-fallback.sh # 集成测试
~/clawd/docs/model-fallback-strategy.md # 技术文档✅ 安装验证
运行以下命令验证安装:
# 检查配置文件
ls -l ~/.openclaw/agents/main/agent/agent.json
# 检查脚本权限
ls -l ~/.openclaw/scripts/model-fallback.sh
ls -l ~/.openclaw/scripts/monitor-models.sh
ls -l ~/clawd/skills/model-fallback/scripts/*.sh
# 检查 skill 文件
ls -l ~/clawd/skills/model-fallback/SKILL.md🚀 快速启动
1. 验证配置
cat ~/.openclaw/agents/main/agent/agent.json | python3 -m json.tool2. 运行测试
~/clawd/scripts/test-model-fallback.sh3. 启动监控
~/.openclaw/scripts/monitor-models.sh start4. 验证状态
~/.openclaw/scripts/monitor-models.sh status📝 下一步
1. 阅读文档: ~/clawd/skills/model-fallback/README.md 2. 配置优化: 根据需求调整 agent.json 3. 测试验证: 运行测试脚本验证功能 4. 启动监控: 启动后台监控 5. 定期维护: 每周检查日志和状态
🔧 故障排除
如果遇到问题,请查看:
# 查看日志
tail -f ~/.openclaw/logs/model-fallback.log
# 检查配置
cat ~/.openclaw/agents/main/agent/agent.json
# 手动测试
~/.openclaw/scripts/model-fallback.sh📞 获取帮助
- 查看文档:
~/clawd/skills/model-fallback/README.md - 运行测试:
~/clawd/scripts/test-model-fallback.sh - 查看日志:
~/.openclaw/logs/
---
安装完成!祝使用愉快! 🎉
模型自动降级 Skill 使用指南
📋 概述
这个 skill 提供了完整的模型自动降级和故障切换解决方案,确保在模型请求失败、超时或达到限制时自动切换到备用模型。
🚀 快速开始
1. 验证安装
检查所有脚本是否已正确安装:
ls -l ~/.openclaw/scripts/model-fallback.sh
ls -l ~/.openclaw/scripts/monitor-models.sh
ls -l ~/clawd/skills/model-fallback/scripts/auto-switch-handler.sh2. 启动监控
# 启动后台监控
~/.openclaw/scripts/monitor-models.sh start
# 验证监控状态
~/.openclaw/scripts/monitor-models.sh status3. 测试切换
# 运行测试脚本
~/clawd/scripts/test-model-fallback.sh🔧 使用方式
方式 1: 自动监控(推荐)
启动监控后,系统会自动检测并切换:
~/.openclaw/scripts/monitor-models.sh start监控会:
- 每 5 分钟检查所有模型健康状态
- 检测到故障时自动切换
- 记录详细日志
- 生成状态报告
方式 2: 手动触发
当需要手动检查和切换时:
~/.openclaw/scripts/model-fallback.sh方式 3: 使用错误包装器
在执行重要命令时使用包装器,自动处理错误:
~/clawd/skills/model-fallback/scripts/model-error-wrapper.sh \
--command "your-openclaw-command-here" \
--max-retries 3 \
--timeout 60📊 监控与日志
查看实时日志
# 切换日志
tail -f ~/.openclaw/logs/model-fallback.log
# 监控日志
tail -f ~/.openclaw/logs/model-monitor.log
# 自动切换日志
tail -f ~/.openclaw/logs/auto-switch.log
# 所有日志
tail -f ~/.openclaw/logs/*.log查看状态
# 当前模型状态
~/.openclaw/scripts/monitor-models.sh status
# JSON 格式状态
cat ~/.openclaw/logs/model-status.json | python3 -m json.tool
# OpenClaw 状态
openclaw status统计信息
# 切换次数统计
grep "切换模型" ~/.openclaw/logs/model-fallback.log | wc -l
# 今日切换历史
grep "$(date '+%Y-%m-%d')" ~/.openclaw/logs/model-fallback.log | grep "切换模型"
# 错误类型统计
grep "ERROR" ~/.openclaw/logs/auto-switch.log | \
awk '{print $NF}' | sort | uniq -c⚙️ 配置文件
主配置文件
位置:~/.openclaw/agents/main/agent/agent.json
{
"model": "anapi/opus-4.5",
"modelFallback": [
"<provider>/glm-4.7",
"openrouter-vip/gpt-5.2-codex",
"github-copilot/claude-sonnet-4-5"
],
"retry": {
"maxAttempts": 3,
"initialDelayMs": 1000,
"maxDelayMs": 10000,
"backoffMultiplier": 2.0
}
}修改配置后
# 重启 Gateway 使配置生效
openclaw gateway restart
# 验证配置
openclaw status | grep Model🎯 模型优先级
当前配置的降级顺序:
1. anapi/opus-4.5 - 最强能力,最高优先级 2. <provider>/glm-4.7 - 中文优化,Provider-A高 3. openrouter-vip/gpt-5.2-codex - 编码专用 4. github-copilot/claude-sonnet-4-5 - 免费备用
🛠️ 故障排查
问题 1: 模型未自动切换
诊断步骤:
# 1. 检查配置
cat ~/.openclaw/agents/main/agent/agent.json | grep -A 5 modelFallback
# 2. 检查日志
tail -50 ~/.openclaw/logs/model-fallback.log
# 3. 手动测试切换
~/.openclaw/scripts/model-fallback.sh常见原因:
- 配置文件格式错误
- API 密钥未配置
- 网络问题
- 所有模型都不可用
问题 2: 监控未运行
诊断步骤:
# 1. 检查进程
ps aux | grep monitor-models
# 2. 检查 PID 文件
cat ~/.openclaw/logs/model-monitor.pid
# 3. 重启监控
~/.openclaw/scripts/monitor-models.sh restart问题 3: 频繁切换
解决方法:
1. 增加重试次数和延迟 2. 调整冷却期设置 3. 检查网络稳定性
编辑 agent.json:
{
"retry": {
"maxAttempts": 5, // 增加到 5 次
"initialDelayMs": 2000 // 增加到 2 秒
},
"errorHandling": {
"rateLimit": {
"cooldownMs": 120000 // 增加冷却期到 2 分钟
}
}
}📈 性能优化
1. 减少切换开销
只在真正需要时切换,而非每次错误都切换:
{
"retry": {
"maxAttempts": 5,
"useFallbackOnFailure": false // 手动控制切换
}
}2. 优化响应时间
为快速响应任务选择最快的模型:
{
"routing": {
"rules": [
{
"name": "quick-response",
"match": {"urgency": "high"},
"preferModels": ["github-copilot/claude-sonnet-4-5"]
}
]
}
}3. 成本优化
优先使用低成本模型:
{
"modelFallback": [
"<provider>/glm-4.7", // 中等成本
"github-copilot/claude-sonnet-4-5", // 免费
"anapi/opus-4.5" // 高成本,必要时使用
]
}🔔 告警配置
发送告警到 Telegram
创建告警脚本:
#!/bin/bash
# ~/.openclaw/scripts/alert-telegram.sh
MESSAGE="$1"
TOKEN="your-telegram-bot-token"
CHAT_ID="your-chat-id"
curl -s -X POST "https://api.telegram.org/bot$TOKEN/sendMessage" \
-d chat_id="$CHAT_ID" \
-d text="🤖 OpenClaw 模型切换通知: $MESSAGE"在 auto-switch-handler.sh 中集成:
# 发送告警
~/.openclaw/scripts/alert-telegram.sh "已从 $CURRENT_MODEL 切换到 $NEW_MODEL"📝 维护建议
每日
- 查看切换日志
- 检查模型健康状态
grep "切换模型" ~/.openclaw/logs/model-fallback.log | tail -5
~/.openclaw/scripts/monitor-models.sh status每周
- 运行完整测试
- 检查配额使用情况
- 备份配置文件
~/clawd/scripts/test-model-fallback.sh
cp ~/.openclaw/agents/main/agent/agent.json \
~/.openclaw/agents/main/agent/agent.json.backup.$(date +%Y%m%d)每月
- 评估各模型性能
- 更新模型优先级
- 清理旧日志
# 清理 30 天前的日志
find ~/.openclaw/logs -name "*.log" -mtime +30 -delete🔗 相关资源
- OpenClaw 文档
- 技术文档
- 配置示例
💡 提示
1. 测试配置: 在生产环境使用前,先测试切换逻辑 2. 监控日志: 定期查看日志,了解切换模式 3. 优化配置: 根据实际使用情况调整参数 4. 备份配置: 保留配置备份,方便恢复 5. 文档更新: 记录配置变更和使用经验
🆘 获取帮助
如果遇到问题:
1. 查看日志文件 2. 运行诊断脚本 3. 查阅技术文档 4. 提交 Issue
---
祝使用愉快!🎉
#!/bin/bash
# 自动处理模型请求失败并切换的脚本
# 由 OpenClaw 在检测到模型错误时调用
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LOG_DIR="$HOME/.openclaw/logs"
LOG_FILE="$LOG_DIR/auto-switch.log"
STATE_FILE="$LOG_DIR/switch-state.json"
FALLBACK_SCRIPT="$HOME/.openclaw/scripts/model-fallback.sh"
mkdir -p "$LOG_DIR"
# 日志函数
log() {
local level=$1
shift
echo "[$(date '+%Y-%m-%d %H:%M:%S')] [$level] $*" | tee -a "$LOG_FILE"
}
# 解析命令行参数
ERROR_TYPE=""
ERROR_CODE=""
ERROR_MESSAGE=""
CURRENT_MODEL=""
RETRY_COUNT=0
while [[ $# -gt 0 ]]; do
case $1 in
--error-type)
ERROR_TYPE="$2"
shift 2
;;
--error-code)
ERROR_CODE="$2"
shift 2
;;
--error-message)
ERROR_MESSAGE="$2"
shift 2
;;
--current-model)
CURRENT_MODEL="$2"
shift 2
;;
--retry-count)
RETRY_COUNT="$2"
shift 2
;;
*)
log ERROR "未知参数: $1"
exit 1
;;
esac
done
log INFO "=== 自动模型切换处理 ==="
log INFO "错误类型: $ERROR_TYPE"
log INFO "错误代码: $ERROR_CODE"
log INFO "错误消息: $ERROR_MESSAGE"
log INFO "当前模型: $CURRENT_MODEL"
log INFO "重试次数: $RETRY_COUNT"
# 读取当前状态
if [[ -f "$STATE_FILE" ]]; then
CONSECUTIVE_FAILURES=$(python3 -c "import json; d=json.load(open('$STATE_FILE')); print(d.get('consecutive_failures', 0))" 2>/dev/null || echo "0")
LAST_SWITCH=$(python3 -c "import json; d=json.load(open('$STATE_FILE')); print(d.get('last_switch', 0))" 2>/dev/null || echo "0")
else
CONSECUTIVE_FAILURES=0
LAST_SWITCH=0
fi
log INFO "连续失败次数: $CONSECUTIVE_FAILURES"
# 决策逻辑
SHOULD_SWITCH=false
SWITCH_REASON=""
case "$ERROR_TYPE" in
"timeout")
# 超时错误:重试2次后切换
if [[ $RETRY_COUNT -ge 2 ]]; then
SHOULD_SWITCH=true
SWITCH_REASON="超时重试次数超限"
fi
;;
"rate_limit"|"429")
# 速率限制:立即切换
SHOULD_SWITCH=true
SWITCH_REASON="API 速率限制"
;;
"quota_exceeded"|"insufficient_quota")
# 配额耗尽:立即切换并标记
SHOULD_SWITCH=true
SWITCH_REASON="配额耗尽"
;;
"authentication"|"401"|"403")
# 认证错误:立即切换并禁用
SHOULD_SWITCH=true
SWITCH_REASON="认证失败"
;;
"service_unavailable"|"503"|"502")
# 服务不可用:重试3次后切换
if [[ $RETRY_COUNT -ge 3 ]]; then
SHOULD_SWITCH=true
SWITCH_REASON="服务不可用"
fi
;;
"network_error"|"connection_error")
# 网络错误:检查连续失败次数
if [[ $CONSECUTIVE_FAILURES -ge 3 ]]; then
SHOULD_SWITCH=true
SWITCH_REASON="网络连续失败"
fi
;;
*)
# 其他错误:记录但不切换
log WARN "未知错误类型,不触发切换"
exit 0
;;
esac
# 冷却期检查(避免频繁切换)
NOW=$(date +%s)
TIME_SINCE_LAST_SWITCH=$((NOW - LAST_SWITCH))
COOLDOWN_PERIOD=300 # 5分钟
if [[ $TIME_SINCE_LAST_SWITCH -lt $COOLDOWN_PERIOD ]] && [[ $SHOULD_SWITCH == true ]]; then
log WARN "切换冷却期中,距上次切换仅 ${TIME_SINCE_LAST_SWITCH} 秒(需要 ${COOLDOWN_PERIOD} 秒)"
# 严重错误(认证、配额)不受冷却期限制
if [[ "$ERROR_TYPE" != "authentication" ]] && [[ "$ERROR_TYPE" != "quota_exceeded" ]]; then
SHOULD_SWITCH=false
SWITCH_REASON="冷却期保护"
fi
fi
# 执行切换
if [[ "$SHOULD_SWITCH" == true ]]; then
log WARN "触发模型切换: $SWITCH_REASON"
# 获取当前模型(如果未提供)
if [[ -z "$CURRENT_MODEL" ]]; then
CURRENT_MODEL=$(openclaw status 2>/dev/null | grep -oP 'Model\s+\K\S+' | head -1 || echo "unknown")
fi
log INFO "切换前模型: $CURRENT_MODEL"
# 执行切换脚本
if [[ -x "$FALLBACK_SCRIPT" ]]; then
log INFO "运行降级切换脚本..."
if $FALLBACK_SCRIPT >> "$LOG_FILE" 2>&1; then
log INFO "✓ 切换成功"
# 获取新模型
NEW_MODEL=$(openclaw status 2>/dev/null | grep -oP 'Model\s+\K\S+' | head -1 || echo "unknown")
log INFO "切换后模型: $NEW_MODEL"
# 更新状态
cat > "$STATE_FILE" << EOF
{
"last_switch": $(date +%s),
"last_switch_from": "$CURRENT_MODEL",
"last_switch_to": "$NEW_MODEL",
"switch_reason": "$SWITCH_REASON",
"consecutive_failures": 0
}
EOF
# 发送通知(如果配置了)
if command -v notify-send &> /dev/null; then
notify-send "OpenClaw 模型切换" "已从 $CURRENT_MODEL 切换到 $NEW_MODEL" 2>/dev/null || true
fi
exit 0
else
log ERROR "✗ 切换失败"
# 增加失败计数
cat > "$STATE_FILE" << EOF
{
"last_switch": $LAST_SWITCH,
"consecutive_failures": $((CONSECUTIVE_FAILURES + 1))
}
EOF
exit 1
fi
else
log ERROR "切换脚本不存在或不可执行: $FALLBACK_SCRIPT"
exit 1
fi
else
log INFO "无需切换: $SWITCH_REASON"
# 更新失败计数
cat > "$STATE_FILE" << EOF
{
"last_switch": $LAST_SWITCH,
"consecutive_failures": $((CONSECUTIVE_FAILURES + 1))
}
EOF
exit 0
fi
#!/bin/bash
# 模型请求包装器 - 捕获错误并自动处理
# 用法: model-error-wrapper.sh --command "your-openclaw-command" --max-retries 3
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
AUTO_SWITCH_HANDLER="$SCRIPT_DIR/auto-switch-handler.sh"
LOG_DIR="$HOME/.openclaw/logs"
mkdir -p "$LOG_DIR"
# 默认参数
COMMAND=""
MAX_RETRIES=3
RETRY_DELAY=2
TIMEOUT=60
LOG_FILE="$LOG_DIR/wrapper.log"
# 解析参数
while [[ $# -gt 0 ]]; do
case $1 in
--command)
COMMAND="$2"
shift 2
;;
--max-retries)
MAX_RETRIES="$2"
shift 2
;;
--retry-delay)
RETRY_DELAY="$2"
shift 2
;;
--timeout)
TIMEOUT="$2"
shift 2
;;
--log-file)
LOG_FILE="$2"
shift 2
;;
*)
echo "未知参数: $1"
exit 1
;;
esac
done
# 日志函数
log() {
local level=$1
shift
echo "[$(date '+%Y-%m-%d %H:%M:%S')] [$level] $*" | tee -a "$LOG_FILE"
}
# 执行命令并捕获错误
execute_with_retry() {
local attempt=1
local current_model=$(openclaw status 2>/dev/null | grep -oP 'Model\s+\K\S+' | head -1 || echo "unknown")
while [[ $attempt -le $MAX_RETRIES ]]; do
log INFO "执行命令 (尝试 $attempt/$MAX_RETRIES)..."
log DEBUG "当前模型: $current_model"
# 使用 timeout 命令执行
if timeout $TIMEOUT bash -c "$COMMAND" 2>&1 | tee -a "$LOG_FILE"; then
log INFO "✓ 命令执行成功"
return 0
else
local exit_code=$?
# 分析错误类型
local error_type=""
local error_code=""
case $exit_code in
124) # timeout 退出码
error_type="timeout"
error_code="408"
log WARN "请求超时 (超过 ${TIMEOUT}秒)"
;;
28) # curl 超时
error_type="timeout"
error_code="408"
log WARN "网络超时"
;;
7 | 35 | 52) # curl 网络错误
error_type="network_error"
error_code="503"
log WARN "网络连接失败"
;;
*)
# 检查错误输出
error_output=$(tail -20 "$LOG_FILE")
if echo "$error_output" | grep -qi "rate limit\|429\|too many requests"; then
error_type="rate_limit"
error_code="429"
log WARN "API 速率限制"
elif echo "$error_output" | grep -qi "quota\|insufficient\|credit"; then
error_type="quota_exceeded"
error_code="402"
log WARN "配额耗尽"
elif echo "$error_output" | grep -qi "auth\|401\|403\|unauthorized"; then
error_type="authentication"
error_code="401"
log WARN "认证失败"
elif echo "$error_output" | grep -qi "502\|503\|504\|service unavailable"; then
error_type="service_unavailable"
error_code="503"
log WARN "服务不可用"
else
error_type="unknown"
error_code="$exit_code"
log WARN "未知错误 (退出码: $exit_code)"
fi
;;
esac
# 调用自动切换处理脚本
if [[ -x "$AUTO_SWITCH_HANDLER" ]]; then
log INFO "调用自动切换处理..."
$AUTO_SWITCH_HANDLER \
--error-type "$error_type" \
--error-code "$error_code" \
--error-message "$(tail -1 "$LOG_FILE")" \
--current-model "$current_model" \
--retry-count "$attempt" || true
fi
# 如果是最后一次尝试,返回失败
if [[ $attempt -eq $MAX_RETRIES ]]; then
log ERROR "达到最大重试次数 ($MAX_RETRIES),放弃"
return 1
fi
# 等待后重试
local wait_time=$((RETRY_DELAY * attempt))
log INFO "等待 ${wait_time} 秒后重试..."
sleep $wait_time
# 更新当前模型(可能已经切换)
current_model=$(openclaw status 2>/dev/null | grep -oP 'Model\s+\K\S+' | head -1 || echo "unknown")
((attempt++))
fi
done
return 1
}
# 主函数
main() {
if [[ -z "$COMMAND" ]]; then
log ERROR "未指定命令,使用 --command 参数"
exit 1
fi
log INFO "=== 模型请求包装器 ==="
log INFO "命令: $COMMAND"
log INFO "最大重试: $MAX_RETRIES"
log INFO "超时设置: ${TIMEOUT}秒"
execute_with_retry
exit $?
}
# 如果直接运行
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi
#!/bin/bash
# 模拟各种模型错误并测试自动切换
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
AUTO_SWITCH_HANDLER="$HOME/clawd/skills/model-fallback/scripts/auto-switch-handler.sh"
LOG_DIR="$HOME/.openclaw/logs"
mkdir -p "$LOG_DIR"
echo "========================================="
echo " 模型错误处理测试"
echo "========================================="
echo ""
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m'
# 测试用例
test_cases=(
"timeout:超时错误"
"rate_limit:速率限制"
"quota_exceeded:配额耗尽"
"authentication:认证失败"
"service_unavailable:服务不可用"
"network_error:网络错误"
)
for test_case in "${test_cases[@]}"; do
IFS=':' read -r error_type description <<< "$test_case"
echo -e "${YELLOW}测试: $description ($error_type)${NC}"
# 模拟不同重试次数
for retry_count in 1 2 3; do
echo " 重试次数: $retry_count"
# 调用自动切换处理脚本
if $AUTO_SWITCH_HANDLER \
--error-type "$error_type" \
--error-code "500" \
--error-message "模拟错误: $description" \
--current-model "test-model" \
--retry-count "$retry_count" 2>&1 | tee -a "$LOG_DIR/test-error.log"; then
echo -e " ${GREEN}✓${NC} 处理成功"
else
echo -e " ${RED}✗${NC} 处理失败"
fi
sleep 1
done
echo ""
done
echo "========================================="
echo " 测试完成"
echo "========================================="
echo ""
echo "查看日志:"
echo " cat $LOG_DIR/test-error.log"
echo " cat $LOG_DIR/auto-switch.log"
echo ""
Related skills
FAQ
When does model-fallback switch models?
On request failure, API timeout, rate-limit hit, or quota exhaustion.
Does it switch back to the primary?
Yes, it automatically switches back once the primary model recovers.