Smart Router Skill
Skill by astralwaveorg
Install via CLI (Recommended)
clawhub install openclaw/skills/skills/astralwaveorg/smart-router-skill智能路由器技能
概述
智能路由器是一个先进的模型调度系统,它超越了简单的关键词匹配,使用多维度分析来为每个消息选择最合适的模型。系统包含成本优化、自动模型扫描和性能监控功能。
功能特性
🎯 智能路由
- 多维度分析:消息长度、内容复杂度、模式识别
- 动态模型选择:基于任务类型自动选择最佳模型
- 成本感知:优先使用免费模型,复杂任务才用付费模型
- 上下文感知:考虑对话历史和用户偏好
💰 成本优化
- 预算控制:设置每日/每月预算限制
- 自动降级:简单任务自动使用免费模型
- 使用统计:实时监控各模型成本
- 智能提醒:成本接近阈值时预警
🔄 自动化管理
- 定期扫描:自动发现OpenRouter免费模型
- 性能监控:实时监控路由性能和系统健康
- 自动备份:定期备份配置和日志
- 规则优化:基于使用数据自动优化路由规则
安装和配置
前提条件
- OpenClaw 2026.2.13 或更高版本
- Node.js 18+
- OpenRouter API密钥(用于模型扫描)
快速安装
# 1. 复制技能文件到OpenClaw技能目录
cp -r smart-router-skill /opt/homebrew/lib/node_modules/openclaw/skills/
# 2. 更新OpenClaw配置以启用技能
openclaw config patch --json '{"skills":{"entries":{"smart-router":{"enabled":true}}}}'
# 3. 重启OpenClaw
openclaw gateway restart
详细安装步骤
- 环境变量设置:
export OPENROUTER_API_KEY="your-openrouter-api-key"
export DEEPSEEK_API_KEY="your-deepseek-api-key"
- 初始化系统:
cd /Users/nora/.openclaw/users/main/workspace
node enhanced-intent-router.js init
- 运行集成测试:
./test-integration.sh
- 部署系统:
node update-openclaw-config.js update
openclaw gateway restart
使用方法
基本路由
// 使用智能路由器路由消息
const { SmartIntentRouter } = require('./enhanced-intent-router.js');
const router = new SmartIntentRouter();
await router.initialize();
const decision = router.analyzeMessage("帮我写一个Python函数");
console.log(decision);
// 输出: { agentId: 'code-agent', model: '4sapi-anthropic/claude-sonnet-4-5-20250929', ... }
命令行工具
# 初始化路由器
node enhanced-intent-router.js init
# 分析消息路由
node enhanced-intent-router.js analyze "你的消息"
# 运行测试用例
node enhanced-intent-router.js test
# 查看性能指标
node enhanced-intent-router.js stats
# 生成详细报告
node enhanced-intent-router.js report
OpenClaw集成
系统自动集成到OpenClaw,无需手动调用。所有消息都会经过智能路由器处理。
配置说明
路由规则配置 (smart-router-config.json)
{
"routingRules": {
"priority": [
{
"name": "代码相关任务",
"conditions": {
"keywords": ["代码", "编程", "Python", "Java"],
"minLength": 10,
"maxLength": 5000
},
"agent": "code-agent",
"model": "4sapi-anthropic/claude-sonnet-4-5-20250929",
"priority": 100
}
],
"fallback": {
"agent": "free-agent",
"model": "openrouter/google/gemma-3-27b-it:free"
}
},
"costOptimization": {
"budgetLimit": 10.0,
"dailyLimit": 1.0,
"preferFreeModels": true
}
}
自定义路由规则
要添加新的路由规则:
- 编辑
smart-router-config.json - 在
routingRules.priority数组中添加新规则 - 设置匹配条件和目标模型
- 无需重启,系统支持热重载
定时任务
系统包含以下自动化定时任务:
| 任务名称 | 时间 | 描述 |
|---|---|---|
| OpenRouter扫描 | 每天 6:00 | 扫描免费模型并更新配置 |
| 每日性能报告 | 每天 0:00 | 生成路由性能报告 |
| 每周成本分析 | 每周一 9:00 | 分析成本优化效果 |
| 配置备份 | 每天 23:30 | 备份配置和日志 |
| 规则优化检查 | 每天 12:00 | 检查并优化路由规则 |
API参考
SmartIntentRouter 类
Metadata
Not sure this is the right skill?
Describe what you want to build — we'll match you to the best skill from 16,000+ options.
Find the right skillPaste this into your clawhub.json to enable this plugin.
{
"plugins": {
"official-astralwaveorg-smart-router-skill": {
"enabled": true,
"auto_update": true
}
}
}Related Skills
openclaw-ref
OpenClaw 配置、CLI、排错、模型管理完整参考手册。修改 openclaw.json、执行 CLI 命令、排查问题时必须查阅此 Skill。
openclaw-ops
Safe OpenClaw gateway configuration operations. Use when reading, analyzing, or modifying openclaw.json. Enforces schema validation + official documentation verification before every change.
blog-writer
为张向阳(Astral Wave)的个人博客 astralwaveorg 生成高质量技术博客文章。当用户说"写博客xxx"、"帮我写一篇xxx"、"引用消息写成博客"、"总结今天聊天",或者 cron 触发每日聊天总结时,使用此技能。文章风格必须模拟作者本人:用工程师第一人称视角,诚实直接,有踩坑说踩坑,读起来像同事之间的经验分享,而不是翻译官方文档。绝不出现"非常优秀""极其强大"等废话词汇。目标是让读者感觉这是技术大牛写的,不是"AI 生成的"。