360 Secure SkillHub
360 安全技能中心

AI Task Router Auto-Route Prompts by Complexity (Local/Cloud)

核心功能:基于正则匹配将AI任务分简单、中等、复杂三档,自动路由至可处理的最便宜模型(免费本地Ollama、中端Sonnet、高端Opus),支持自定义路由规则,可省60%-80%API成本。典型场景:日常闲聊、邮件撰写、代码调试等不同复杂度请求。通过JS调用,输入文本任务,输出适配模型、路由原因及置信度。

theshadowrose
theshadowrose
热度 87.07
最近更新 2026-05-11 17:30:39
分类:自动化依赖:代码执行 / 内部调用大模型 / 第三方 API应用场景:自动化脚本 / 工作流 / 任务管理

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add task-complexity-router
Metadata
name
AI Task Router — Auto-Route Prompts by Complexity (Local/Cloud)
description
Regex-based routing sends simple tasks to local AI, medium to mid-tier, complex to premium — saving 60%+ on API costs.
author
@TheShadowRose
version
1.0.0
tags
["task-routing","cost-optimization","complexity-detection","ollama","auto-routing","smart-dispatch"]
license
MIT

AI Task Router — Auto-Route Prompts by Complexity (Local/Cloud)

Regex-based routing sends simple tasks to local AI, medium to mid-tier, complex to premium — saving 60%+ on API costs.


Automatically routes prompts to the cheapest model that can handle them.

How It Works

Pattern matching classifies tasks into tiers:

Task Type Example Routed To Cost
Simple "hi", "thanks", "what time is it" Local (Ollama) $0
Moderate "write an email", "analyze this" Mid-tier (Sonnet) $
Complex "debug this codebase", "write a chapter" Premium (Opus) $$$

Usage

const { TaskRouter } = require('./src/task-router');

const router = new TaskRouter({
  defaultModel: 'local',
  escalationModel: 'sonnet',
  heavyModel: 'opus'
});

const result = router.route('analyze the sales data from Q3');
// { model: 'sonnet', reason: 'Analysis task', confidence: 0.8 }

Custom Rules

Add your own routing patterns:

router.addRule({
  name: 'code-review',
  pattern: /\b(review|refactor|debug|optimize)\b.*\b(code|function|class)\b/i,
  model: 'opus',
  reason: 'Code review needs deep reasoning'
});

Cost Savings

Typical usage pattern routes ~70% of tasks to free local models, ~25% to mid-tier, and ~5% to premium. With Opus at $15/M tokens vs Ollama at $0, this saves 60-80% on API costs.

⚠️ Disclaimer

This software is provided "AS IS", without warranty of any kind, express or implied.

USE AT YOUR OWN RISK.

  • The author(s) are NOT liable for any damages, losses, or consequences arising from the use or misuse of this software — including but not limited to financial loss, data loss, security breaches, business interruption, or any indirect/consequential damages.
  • This software does NOT constitute financial, legal, trading, or professional advice.
  • Users are solely responsible for evaluating whether this software is suitable for their use case, environment, and risk tolerance.
  • No guarantee is made regarding accuracy, reliability, completeness, or fitness for any particular purpose.
  • The author(s) are not responsible for how third parties use, modify, or distribute this software after purchase.

By downloading, installing, or using this software, you acknowledge that you have read this disclaimer and agree to use the software entirely at your own risk.

DATA DISCLAIMER: This software processes and stores data locally on your system. The author(s) are not responsible for data loss, corruption, or unauthorized access resulting from software bugs, system failures, or user error. Always maintain independent backups of important data. This software does not transmit data externally unless explicitly configured by the user.


Support & Links

🐛 Bug Reports TheShadowyRose@proton.me
☕ Ko-fi ko-fi.com/theshadowrose
🛒 Gumroad shadowyrose.gumroad.com
🐦 Twitter @TheShadowyRose
🐙 GitHub github.com/TheShadowRose
🧠 PromptBase promptbase.com/profile/shadowrose

Built with OpenClaw — thank you for making this possible.


🛠️ Need something custom? Custom OpenClaw agents & skills starting at $500. If you can describe it, I can build it. → Hire me on Fiverr