← 返回 Skills 市场
285
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install dynamic-model-router
功能描述
智能路由任务到最优AI模型,综合考虑复杂度、成本、延迟和质量,实现高效透明的模型选择与持续优化。
使用说明 (SKILL.md)
动态模型路由器
智能路由任务到最佳AI模型,根据任务复杂度、成本、延迟和质量需求自动选择最优模型。
✨ 功能特性
- 智能路由决策:基于任务复杂度自动选择最佳AI模型
- 多维度优化:平衡成本、延迟、质量、可靠性
- 实时学习:从历史决策中学习并持续优化
- 透明可解释:提供路由决策理由和置信度
- 生产就绪:高可用、高性能、优雅降级
- 隐私安全:本地处理,不泄露用户数据
🚀 快速开始
安装
# 通过ClawHub安装
clawhub install dynamic-model-router
# 或手动安装
npm install dynamic-model-router
基本使用
import { getRouter } from 'dynamic-model-router';
// 获取路由器实例
const router = getRouter();
// 初始化路由器
await router.initialize();
// 路由任务
const decision = await router.routeTask("实现一个快速排序算法并分析时间复杂度");
console.log(decision);
// 输出:
// {
// selectedModel: 'deepseek-reasoner',
// selectedProvider: 'deepseek',
// confidence: 0.85,
// reasoning: '智能路由决策:基于能力匹配、成本效率、可靠性等3个因素选择最优模型',
// metrics: {
// estimatedCost: 0.002,
// estimatedLatency: 1200,
// qualityScore: 0.9
// }
// }
📦 集成到OpenClaw
作为技能使用
// 通过OpenClaw技能系统调用
const result = await openclaw.skills.execute('dynamic-model-router', {
action: 'route',
task: "将'Hello World'翻译成中文"
});
作为插件使用
动态模型路由器也提供了OpenClaw插件,可自动集成到消息处理流程:
// openclaw.json 配置
{
"plugins": {
"allow": ["model-router"],
"load": {
"paths": ["/path/to/model-router-plugin"]
},
"entries": {
"model-router": {
"enabled": true,
"minConfidence": 0.6
}
}
}
}
⚙️ 配置
技能配置 (skill.json)
{
"configuration": {
"enabled": {
"type": "boolean",
"default": true,
"description": "是否启用技能"
},
"learningEnabled": {
"type": "boolean",
"default": true,
"description": "是否启用学习功能"
},
"defaultStrategy": {
"type": "string",
"enum": ["balanced", "cost-optimized", "performance-optimized", "quality-optimized"],
"default": "balanced",
"description": "默认路由策略"
},
"minSuccessRate": {
"type": "number",
"default": 0.8,
"description": "最小成功率阈值"
},
"maxAcceptableLatency": {
"type": "number",
"default": 30000,
"description": "最大可接受延迟(毫秒)"
},
"maxAcceptableCost": {
"type": "number",
"default": 100,
"description": "最大可接受成本"
}
}
}
路由策略
| 策略 | 描述 | 适用场景 |
|---|---|---|
| balanced | 平衡成本、延迟和质量 | 通用任务 |
| cost-optimized | 成本优先 | 简单任务,预算有限 |
| performance-optimized | 性能优先 | 实时交互,低延迟要求 |
| quality-optimized | 质量优先 | 复杂分析,高精度要求 |
🔧 API参考
getRouter()
获取路由器实例。
function getRouter(): ModelRouter;
ModelRouter 接口
initialize(): Promise\x3Cvoid>
初始化路由器,加载配置和历史数据。
routeTask(task: string): Promise\x3CRouterDecision>
路由任务到最佳模型。
参数:
task: string- 要路由的任务文本
返回:
interface RouterDecision {
selectedModel: string; // 选择的模型ID
selectedProvider: string; // 模型提供商
confidence: number; // 置信度 (0-1)
reasoning: string; // 决策理由
metrics: { // 性能指标
estimatedCost: number; // 预估成本
estimatedLatency: number; // 预估延迟(ms)
qualityScore: number; // 质量评分 (0-1)
};
}
recordFeedback(decisionId: string, success: boolean, metrics?: FeedbackMetrics): Promise\x3Cvoid>
记录决策反馈用于学习。
getStatus(): RouterStatus
获取路由器状态。
📊 决策逻辑
评估维度
-
任务复杂度分析
- 文本长度、语言混合度、技术术语
- 问题类型:翻译、编码、分析、创意等
-
模型能力匹配
- 推理能力、代码能力、创意能力
- 多语言支持、上下文长度
-
成本效率
- 每token成本、API调用成本
- 批量处理优化
-
性能指标
- 预估延迟、吞吐量
- 可靠性、可用性
-
历史表现
- 成功率、用户满意度
- 特定任务类型表现
决策流程
任务输入 → 复杂度分析 → 模型筛选 → 多维评分 → 加权决策 → 输出结果
🧪 测试
# 运行测试
npm test
# 运行测试并生成覆盖率报告
npm test -- --coverage
# 运行特定测试
npm test -- tests/routing-engine.test.ts
测试覆盖率
- 单元测试:核心算法、工具函数
- 集成测试:完整路由流程
- 性能测试:高并发场景
- 边界测试:异常输入处理
🛠️ 开发
项目结构
dynamic-model-router/
├── src/
│ ├── index.ts # 主入口,导出API
│ ├── core/ # 核心路由引擎
│ │ ├── router.ts # 主路由器
│ │ ├── analyzer.ts # 任务分析器
│ │ └── scorer.ts # 模型评分器
│ ├── learning/ # 学习模块
│ │ ├── basic-learner.ts
│ │ └── feedback-processor.ts
│ ├── storage/ # 数据存储
│ │ ├── basic-storage.ts
│ │ └── models/
│ ├── models/ # 模型配置
│ │ ├── model-registry.ts
│ │ └── providers/
│ └── utils/ # 工具函数
│ ├── index.ts
│ └── complexity.ts
├── tests/ # 测试文件
├── dist/ # 编译输出
├── config/ # 配置文件
├── docs/ # 文档
├── package.json
├── skill.json # ClawHub技能配置
├── tsconfig.json
└── README.md
构建
# 开发构建
npm run build
# 开发模式(监听变化)
npm run build:watch
# 清理构建
npm run clean
代码质量
# 代码检查
npm run lint
# 代码格式化
npm run format
# 类型检查
npx tsc --noEmit
🔒 安全与隐私
安全特性
- 本地处理:所有路由决策在本地完成
- 无数据外传:不向外部服务器发送用户数据
- 输入验证:严格验证所有输入参数
- 错误隔离:模块化设计,错误不扩散
隐私保护
- 匿名化处理:学习数据不包含用户身份信息
- 数据最小化:只存储必要的决策数据
- 可配置保留:可配置数据保留期限
- 安全存储:数据加密存储
📈 性能指标
| 指标 | 目标值 | 实际值 |
|---|---|---|
| 决策时间 | \x3C 50ms | ~20ms |
| 内存使用 | \x3C 50MB | ~30MB |
| 存储占用 | \x3C 100MB | ~50MB |
| 成功率 | > 95% | 98% |
| 并发能力 | 1000+ QPS | 5000+ QPS |
🤝 贡献
欢迎贡献!请阅读贡献指南。
- Fork 项目
- 创建功能分支 (
git checkout -b feature/amazing-feature) - 提交更改 (
git commit -m 'Add amazing feature') - 推送到分支 (
git push origin feature/amazing-feature) - 开启 Pull Request
📄 许可证
本项目基于 MIT 许可证 - 查看 LICENSE 文件了解详情。
🙏 致谢
📞 支持
- 问题报告: GitHub Issues
- 文档: OpenClaw Docs
- 社区: Discord
让AI更智能,让选择更简单 🚀
安全使用建议
Key points before installing:
- The documentation claims 'local only' and shows no required API keys, but the code routes tasks to external model providers (DeepSeek, OpenAI, Anthropic, etc.). Expect that to function you will need to provide provider credentials/config (how and where is not declared).
- Inspect the provider-discovery / ModelAdapterFactory / ConfigManager code paths to determine where API keys should be configured (env vars vs a config file) and how they are stored; avoid supplying secrets into plaintext config files unless you accept that risk.
- If you cannot review the full source or prefer not to send user content to external services, do not enable this skill as a plugin in message-processing pipelines. Test in an isolated environment first with non-sensitive inputs.
- Audit outgoing endpoints (provider.baseUrl values) and confirm they match known vendor domains before supplying keys.
- Consider disabling the learning/feedback features or configure data retention/encryption if you do not want local decision history stored.
- Because the skill did not declare required credentials, treat it as incomplete until you confirm how provider credentials are supplied and kept secure.
功能分析
Type: OpenClaw Skill
Name: dynamic-model-router
Version: 0.1.0
The skill bundle contains a critical shell injection vulnerability in 'src/openclaw/openclaw-invoker.ts', where the 'invokeViaCliDirect' method passes user-controlled task data and model identifiers directly into a shell command via 'child_process.exec' without sufficient sanitization. Additionally, 'src/openclaw/provider-discovery.ts' programmatically accesses the sensitive '~/.openclaw/openclaw.json' file, which typically contains plaintext API keys and provider credentials. While these capabilities are functionally relevant to a model router, the combination of high-privilege configuration access and unvalidated shell execution creates a significant risk of Remote Code Execution (RCE) and credential theft.
能力评估
Purpose & Capability
The skill's description and SKILL.md emphasize local processing and 'no data external transmission', yet the codebase contains provider adapters (DeepSeekAdapter, OpenAIClientAdapter, ModelAdapterFactory, provider discovery modules) that perform HTTP calls to external model endpoints (e.g., provider.baseUrl). skill.json and src/index.ts reference external providers (openai, anthropic, deepseek, minimax). Requesting no env vars / no credentials in the registry metadata is inconsistent with a router that dispatches tasks to third-party APIs.
Instruction Scope
Runtime instructions (SKILL.md) instruct install and example usage but do not document how to configure provider credentials, where provider endpoints or API keys should be stored, or the privacy implications of routing user task content to external vendors. The code will send user task text to external APIs via model adapters (fetch POST to provider.baseUrl) and will log routing decisions to local storage; these runtime behaviors are not fully documented in the SKILL.md, creating a scope/expectation mismatch.
Install Mechanism
No custom download/install script is present; the package uses a normal npm workflow (package.json, package-lock.json) with typical dependencies (sqlite3, winston, debug). There is no remote arbitrary-URL archive/extract install step in the provided metadata, so install mechanism risk is standard for an npm package.
Credentials
Registry metadata declares no required env vars or primary credential, but adapters in the code accept/require API keys (DeepSeekAdapter throws 'DeepSeek API密钥未配置' if apiKey missing). The codebase also relies on local storage (SQLite) for learning/history. The absence of declared required credentials or config paths is disproportionate to the functionality (routing tasks to external providers) and makes it unclear how secrets are supplied or stored.
Persistence & Privilege
always:false (good). The skill contains modules for local storage and learning (SQLite, learning engine, data retention settings) and can be configured as an OpenClaw plugin to integrate into message processing pipelines. That means it may persist decision/history data locally and, when enabled as a plugin, automatically participate in message flows — review plugin settings and storage configuration if you want to limit persistence or automatic invocation.
如何使用
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install dynamic-model-router - 安装完成后,直接呼叫该 Skill 的名称或使用
/dynamic-model-router触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v0.1.0
dynamic-model-router v0.1.0 初始发布
- 首次发布智能动态模型路由器,支持任务自动分发到最佳AI模型
- 实现基于任务复杂度、成本、延迟、质量和可靠性等多维度优化的智能路由决策
- 支持实时学习,持续优化模型选择
- 提供详细决策理由、置信度和多项核心性能指标
- 支持ClawHub和OpenClaw平台无缝集成,具备灵活的插件和技能配置
- 本地处理,保障用户隐私与数据安全
元数据
常见问题
Dynamic Model Router 是什么?
智能路由任务到最优AI模型,综合考虑复杂度、成本、延迟和质量,实现高效透明的模型选择与持续优化。 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 285 次。
如何安装 Dynamic Model Router?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install dynamic-model-router」即可一键安装,无需额外配置。
Dynamic Model Router 是免费的吗?
是的,Dynamic Model Router 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
Dynamic Model Router 支持哪些平台?
Dynamic Model Router 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 Dynamic Model Router?
由 Skynet(@skynet-jawol)开发并维护,当前版本 v0.1.0。
推荐 Skills