360 Secure SkillHub
360 安全技能中心

Smart Router V3

核心功能:自动从OpenClaw配置发现AI提供者,智能分类请求意图(代码、分析等5类),按预设优先级链路由并自动重试备选,提供OpenAI兼容接口。典型场景:统一处理各类AI请求,如代码编写、创意生成、实时信息查询等,无需切换不同模型服务。输入输出:通过HTTP接口交互,POST /v1/chat/completions发请求,返回对应模型结果;GET /health查看服务状态与提供者。

earlvanze
earlvanze
热度 25.04
最近更新 2026-04-12 00:16:47
分类:开发依赖:代码执行 / 读写文件 / 第三方 API应用场景:API 集成 / DevOps / 自动化脚本

安装技能

复制下面的话术发给你的 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