| name | smart-router-skill |
| description | Smart Router Skill |
智能路由器技能
概述
智能路由器是一个先进的模型调度系统,它超越了简单的关键词匹配,使用多维度分析来为每个消息选择最合适的模型。系统包含成本优化、自动模型扫描和性能监控功能。
功能特性
🎯 智能路由
- 多维度分析:消息长度、内容复杂度、模式识别
- 动态模型选择:基于任务类型自动选择最佳模型
- 成本感知:优先使用免费模型,复杂任务才用付费模型
- 上下文感知:考虑对话历史和用户偏好
💰 成本优化
- 预算控制:设置每日/每月预算限制
- 自动降级:简单任务自动使用免费模型
- 使用统计:实时监控各模型成本
- 智能提醒:成本接近阈值时预警
🔄 自动化管理
- 定期扫描:自动发现OpenRouter免费模型
- 性能监控:实时监控路由性能和系统健康
- 自动备份:定期备份配置和日志
- 规则优化:基于使用数据自动优化路由规则
安装和配置
前提条件
- OpenClaw 2026.2.13 或更高版本
- Node.js 18+
- OpenRouter API密钥(用于模型扫描)
快速安装
cp -r smart-router-skill /opt/homebrew/lib/node_modules/openclaw/skills/
openclaw config patch --json '{"skills":{"entries":{"smart-router":{"enabled":true}}}}'
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);
命令行工具
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",
自定义路由规则
要添加新的路由规则:
- 编辑
smart-router-config.json
- 在
routingRules.priority 数组中添加新规则
- 设置匹配条件和目标模型
- 无需重启,系统支持热重载
定时任务
系统包含以下自动化定时任务:
| 任务名称 | 时间 | 描述 |
|---|
| OpenRouter扫描 | 每天 6:00 | 扫描免费模型并更新配置 |
| 每日性能报告 | 每天 0:00 | 生成路由性能报告 |
| 每周成本分析 | 每周一 9:00 | 分析成本优化效果 |
| 配置备份 | 每天 23:30 | 备份配置和日志 |
| 规则优化检查 | 每天 12:00 | 检查并优化路由规则 |
API参考
SmartIntentRouter 类
class SmartIntentRouter {
async initialize()
analyzeMessage(message, context)
getMetrics()
generateReport()
}
路由决策对象
{
agentId: 'code-agent',
model: 'model-id',
reasoning: false,
ruleName: '规则名称',
confidence: 0.95,
reason: '匹配原因',
features: { ... },
costOptimized: true
}
维护和管理
监控系统健康
node smart-router-maintenance.js health
node smart-router-maintenance.js daily
node smart-router-maintenance.js weekly
备份和恢复
node smart-router-maintenance.js backup
node smart-router-maintenance.js clean-backups
故障排除
路由器初始化失败
node enhanced-intent-router.js init
OPENCLAW_DEBUG=1 node enhanced-intent-router.js init
路由决策不准确
- 检查路由规则配置
- 查看路由日志分析模式
- 调整规则优先级和条件
OpenRouter扫描失败
echo $OPENROUTER_API_KEY
node openrouter-scanner.js
性能优化
缓存设置
系统使用智能缓存减少重复计算。默认缓存TTL为3600秒,可根据使用情况调整:
{
"performanceSettings": {
"cacheEnabled": true,
"cacheTTL": 3600,
"maxResponseTime": 30000
}
}
规则优化建议
- 将高频规则放在前面
- 使用更精确的匹配条件
- 定期分析路由日志优化规则
- 根据使用数据调整规则优先级
安全注意事项
- API密钥保护:确保所有API密钥安全存储
- 配置备份:定期备份路由器配置
- 访问控制:限制对配置文件的访问
- 日志管理:定期清理敏感日志信息
扩展开发
添加新功能
- 在
enhanced-intent-router.js 中添加新功能
- 更新配置文件
- 运行测试验证
- 部署到生产环境
自定义分析器
可以扩展 analyzeMessage 方法添加自定义分析逻辑:
class CustomRouter extends SmartIntentRouter {
analyzeMessage(message, context) {
const features = this.extractCustomFeatures(message);
return super.analyzeMessage(message, { ...context, customFeatures: features });
}
}
支持与反馈
如有问题或建议:
- 查看路由日志分析问题
- 检查系统指标识别瓶颈
- 调整配置参数优化性能
- 联系系统管理员获取支持
版本历史
v1.0.0 (2026-02-15)
- 初始版本发布
- 智能多维度路由
- 成本优化系统
- OpenRouter自动扫描
- 完整的维护工具
技能作者:OpenClaw AI
最后更新:2026-02-15
许可证:MIT
状态:生产就绪 ✅