360 Secure SkillHub
360 安全技能中心

Smart Router V3

一个 OpenAI 兼容的 HTTP 路由服务:读取 OpenClaw 提供商配置,对用户消息做意图分类(代码、分析、创意、实时、通用),按优先级链选择提供商并在失败时自动回退,提供健康检查接口显示已发现的提供商。

earlvanze
earlvanze
热度 25.00
最近更新 2026-04-12 00:16:47
分类:自动化依赖:代码执行 / 读写文件 / 第三方 API / 内部调用大模型应用场景:API 集成 / 工作流 / 自动化脚本

安装技能

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

执行命令安装此 skill: npx secure-skills-cli add smart-router-v2
Metadata
name
smart-router-v2
description
Dynamic AI model router with intent classification and automatic provider discovery
version
3.0.0

Smart Router V2

HTTP server that routes AI requests to optimal models based on intent classification with dynamic provider discovery.

Features

  • Dynamic Discovery: Automatically reads available providers from ~/.openclaw/openclaw.json
  • Intent Classification: Routes based on task type (CODE, ANALYSIS, CREATIVE, REALTIME, GENERAL)
  • Automatic Fallback: Tries providers in priority order until success
  • Zero-config: Works out of the box with OpenClaw provider config

Installation

# Clone and run
python3 router.py --port 8788

# Or use systemd
systemctl --user enable smart-router.service
systemctl --user start smart-router.service

API

Health Check

GET /health

Returns discovered providers:

{"status": "ok", "providers": ["ollama", "ollama-cyber", "openrouter", "claude-cli"]}

Chat Completions

POST /v1/chat/completions

OpenAI-compatible endpoint with automatic routing.

Routing Logic

Intent Priority Chain
CODE claude-cli → ollama → ollama-cyber
ANALYSIS claude-cli → ollama → ollama-cyber
CREATIVE ollama → claude-cli
REALTIME ollama → openrouter
GENERAL ollama → claude-cli → ollama-cyber

Intent Detection

Automatically classifies user messages:

  • CODE: write, debug, fix, function, code blocks (```)
  • ANALYSIS: analyze, explain, compare, research, why
  • CREATIVE: create, brainstorm, imagine, design, story
  • REALTIME: now, today, current, latest, price, weather
  • GENERAL: Default for unmatched patterns

Configuration

Reads providers from OpenClaw config:

  • ~/.openclaw/openclaw.json → models.providers
  • Supports: ollama, openai-completions, anthropic-messages APIs
  • Automatically skips smart-router (self-reference)

Files

  • router.py — Main HTTP routing server (V3 with dynamic discovery)
  • SKILL.md — This documentation
  • _meta.json — Metadata

Changelog

v2.0.0 (2026-04-11)

  • Added dynamic provider discovery from OpenClaw config
  • Removed hardcoded endpoints
  • Added /health endpoint showing discovered providers
  • Improved error handling and fallback logic

v1.0.0

  • Initial release with hardcoded routing

License

MIT