intelligent-routing

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Intelligent Agent Routing

智能Agent路由

Purpose: Automatically analyze user requests and route them to the most appropriate specialist agent(s) without requiring explicit user mentions.
用途:自动分析用户请求,无需用户明确提及即可将其路由至最合适的专业Agent。

Core Principle

核心原则

The AI should act as an intelligent Project Manager, analyzing each request and automatically selecting the best specialist(s) for the job.
AI应扮演智能项目经理的角色,分析每个请求并自动为任务选择最佳专业Agent。

How It Works

工作机制

1. Request Analysis

1. 请求分析

Before responding to ANY user request, perform automatic analysis:
mermaid
graph TD
    A[User Request: Add login] --> B[ANALYZE]
    B --> C[Keywords]
    B --> D[Domains]
    B --> E[Complexity]
    C --> F[SELECT AGENT]
    D --> F
    E --> F
    F --> G[security-auditor + backend-specialist]
    G --> H[AUTO-INVOKE with context]
在响应任何用户请求之前,先执行自动分析:
mermaid
graph TD
    A[User Request: Add login] --> B[ANALYZE]
    B --> C[Keywords]
    B --> D[Domains]
    B --> E[Complexity]
    C --> F[SELECT AGENT]
    D --> F
    E --> F
    F --> G[security-auditor + backend-specialist]
    G --> H[AUTO-INVOKE with context]

2. Agent Selection Matrix

2. Agent选择矩阵

Use this matrix to automatically select agents:
User IntentKeywordsSelected Agent(s)Auto-invoke?
Authentication"login", "auth", "signup", "password"
security-auditor
+
backend-specialist
✅ YES
UI Component"button", "card", "layout", "style"
frontend-specialist
✅ YES
Mobile UI"screen", "navigation", "touch", "gesture"
mobile-developer
✅ YES
API Endpoint"endpoint", "route", "API", "POST", "GET"
backend-specialist
✅ YES
Database"schema", "migration", "query", "table"
database-architect
+
backend-specialist
✅ YES
Bug Fix"error", "bug", "not working", "broken"
debugger
✅ YES
Test"test", "coverage", "unit", "e2e"
test-engineer
✅ YES
Deployment"deploy", "production", "CI/CD", "docker"
devops-engineer
✅ YES
Security Review"security", "vulnerability", "exploit"
security-auditor
+
penetration-tester
✅ YES
Performance"slow", "optimize", "performance", "speed"
performance-optimizer
✅ YES
Product Def"requirements", "user story", "backlog", "MVP"
product-owner
✅ YES
New Feature"build", "create", "implement", "new app"
orchestrator
→ multi-agent
⚠️ ASK FIRST
Complex TaskMultiple domains detected
orchestrator
→ multi-agent
⚠️ ASK FIRST
使用此矩阵自动选择Agent:
用户意图关键词选中的Agent(s)自动调用?
身份验证"login", "auth", "signup", "password"
security-auditor
+
backend-specialist
✅ 是
UI组件"button", "card", "layout", "style"
frontend-specialist
✅ 是
移动端UI"screen", "navigation", "touch", "gesture"
mobile-developer
✅ 是
API端点"endpoint", "route", "API", "POST", "GET"
backend-specialist
✅ 是
数据库"schema", "migration", "query", "table"
database-architect
+
backend-specialist
✅ 是
Bug修复"error", "bug", "not working", "broken"
debugger
✅ 是
测试"test", "coverage", "unit", "e2e"
test-engineer
✅ 是
部署"deploy", "production", "CI/CD", "docker"
devops-engineer
✅ 是
安全审查"security", "vulnerability", "exploit"
security-auditor
+
penetration-tester
✅ 是
性能优化"slow", "optimize", "performance", "speed"
performance-optimizer
✅ 是
产品定义"requirements", "user story", "backlog", "MVP"
product-owner
✅ 是
新功能开发"build", "create", "implement", "new app"
orchestrator
→ 多Agent协作
⚠️ 先询问用户
复杂任务检测到多个领域
orchestrator
→ 多Agent协作
⚠️ 先询问用户

3. Automatic Routing Protocol

3. 自动路由协议

TIER 0 - Automatic Analysis (ALWAYS ACTIVE)

层级0 - 自动分析(始终激活)

Before responding to ANY request:
javascript
// Pseudo-code for decision tree
function analyzeRequest(userMessage) {
    // 1. Classify request type
    const requestType = classifyRequest(userMessage);

    // 2. Detect domains
    const domains = detectDomains(userMessage);

    // 3. Determine complexity
    const complexity = assessComplexity(domains);

    // 4. Select agent(s)
    if (complexity === "SIMPLE" && domains.length === 1) {
        return selectSingleAgent(domains[0]);
    } else if (complexity === "MODERATE" && domains.length <= 2) {
        return selectMultipleAgents(domains);
    } else {
        return "orchestrator"; // Complex task
    }
}
在响应任何请求之前:
javascript
// Pseudo-code for decision tree
function analyzeRequest(userMessage) {
    // 1. 分类请求类型
    const requestType = classifyRequest(userMessage);

    // 2. 检测领域
    const domains = detectDomains(userMessage);

    // 3. 评估复杂度
    const complexity = assessComplexity(domains);

    // 4. 选择Agent
    if (complexity === "SIMPLE" && domains.length === 1) {
        return selectSingleAgent(domains[0]);
    } else if (complexity === "MODERATE" && domains.length <= 2) {
        return selectMultipleAgents(domains);
    } else {
        return "orchestrator"; // 复杂任务
    }
}

4. Response Format

4. 响应格式

When auto-selecting an agent, inform the user concisely:
markdown
🤖 **Applying knowledge of `@security-auditor` + `@backend-specialist`...**

[Proceed with specialized response]
Benefits:
  • ✅ User sees which expertise is being applied
  • ✅ Transparent decision-making
  • ✅ Still automatic (no /commands needed)
自动选择Agent时,简洁地告知用户:
markdown
🤖 **正在应用`@security-auditor` + `@backend-specialist`的专业能力...**

[继续提供专业响应]
优势:
  • ✅ 用户可看到正在应用的专业能力
  • ✅ 决策过程透明
  • ✅ 全程自动(无需使用命令)

Domain Detection Rules

领域检测规则

Single-Domain Tasks (Auto-invoke Single Agent)

单领域任务(自动调用单个Agent)

DomainPatternsAgent
Securityauth, login, jwt, password, hash, token
security-auditor
Frontendcomponent, react, vue, css, html, tailwind
frontend-specialist
Backendapi, server, express, fastapi, node
backend-specialist
Mobilereact native, flutter, ios, android, expo
mobile-developer
Databaseprisma, sql, mongodb, schema, migration
database-architect
Testingtest, jest, vitest, playwright, cypress
test-engineer
DevOpsdocker, kubernetes, ci/cd, pm2, nginx
devops-engineer
Debugerror, bug, crash, not working, issue
debugger
Performanceslow, lag, optimize, cache, performance
performance-optimizer
SEOseo, meta, analytics, sitemap, robots
seo-specialist
Gameunity, godot, phaser, game, multiplayer
game-developer
领域匹配模式Agent
安全auth, login, jwt, password, hash, token
security-auditor
前端component, react, vue, css, html, tailwind
frontend-specialist
后端api, server, express, fastapi, node
backend-specialist
移动端react native, flutter, ios, android, expo
mobile-developer
数据库prisma, sql, mongodb, schema, migration
database-architect
测试test, jest, vitest, playwright, cypress
test-engineer
DevOpsdocker, kubernetes, ci/cd, pm2, nginx
devops-engineer
调试error, bug, crash, not working, issue
debugger
性能优化slow, lag, optimize, cache, performance
performance-optimizer
SEOseo, meta, analytics, sitemap, robots
seo-specialist
游戏开发unity, godot, phaser, game, multiplayer
game-developer

Multi-Domain Tasks (Auto-invoke Orchestrator)

多领域任务(自动调用Orchestrator)

If request matches 2+ domains from different categories, automatically use
orchestrator
:
text
Example: "Create a secure login system with dark mode UI"
→ Detected: Security + Frontend
→ Auto-invoke: orchestrator
→ Orchestrator will handle: security-auditor, frontend-specialist, test-engineer
如果请求匹配2个及以上不同类别的领域,自动使用
orchestrator
text
示例:"创建带有深色模式UI的安全登录系统"
→ 检测到:安全 + 前端
→ 自动调用:orchestrator
→ Orchestrator将协调:security-auditor、frontend-specialist、test-engineer

Complexity Assessment

复杂度评估

SIMPLE (Direct agent invocation)

简单(直接调用Agent)

  • Single file edit
  • Clear, specific task
  • One domain only
  • Example: "Fix the login button style"
Action: Auto-invoke respective agent
  • 仅修改单个文件
  • 任务清晰、具体
  • 仅涉及一个领域
  • 示例:"修复登录按钮样式"
操作:自动调用对应Agent

MODERATE (2-3 agents)

中等(调用2-3个Agent)

  • 2-3 files affected
  • Clear requirements
  • 2 domains max
  • Example: "Add API endpoint for user profile"
Action: Auto-invoke relevant agents sequentially
  • 影响2-3个文件
  • 需求清晰
  • 最多涉及2个领域
  • 示例:"添加用户资料的API端点"
操作:依次自动调用相关Agent

COMPLEX (Orchestrator required)

复杂(需要Orchestrator)

  • Multiple files/domains
  • Architectural decisions needed
  • Unclear requirements
  • Example: "Build a social media app"
Action: Auto-invoke
orchestrator
→ will ask Socratic questions
  • 涉及多个文件/领域
  • 需要架构决策
  • 需求不明确
  • 示例:"构建一个社交媒体应用"
操作:自动调用
orchestrator
→ 会提出引导性问题

Implementation Rules

实施规则

Rule 1: Silent Analysis

规则1:静默分析

DO NOT announce "I'm analyzing your request..."

请勿告知用户"我正在分析您的请求..."

  • ✅ Analyze silently
  • ✅ Inform which agent is being applied
  • ❌ Avoid verbose meta-commentary
  • ✅ 静默执行分析
  • ✅ 告知用户正在应用哪个Agent的能力
  • ❌ 避免冗长的元注释

Rule 2: Inform Agent Selection

规则2:告知Agent选择结果

DO inform which expertise is being applied:
markdown
🤖 **Applying knowledge of `@frontend-specialist`...**

I will create the component with the following characteristics:
[Continue with specialized response]
必须告知用户正在应用的专业能力:
markdown
🤖 **正在应用`@frontend-specialist`的专业能力...**

我将创建具备以下特性的组件:
[继续提供专业响应]

Rule 3: Seamless Experience

规则3:无缝体验

The user should not notice a difference from talking to the right specialist directly.
用户应感觉与直接对话对应专业Agent无差异。

Rule 4: Override Capability

规则4:用户覆盖权限

User can still explicitly mention agents:
text
User: "Use @backend-specialist to review this"
→ Override auto-selection
→ Use explicitly mentioned agent
用户仍可明确指定Agent:
text
用户:"使用@backend-specialist来审查此内容"
→ 覆盖自动选择
→ 使用用户明确提及的Agent

Edge Cases

边缘情况

Case 1: Generic Question

情况1:通用问题

text
User: "How does React work?"
→ Type: QUESTION
→ No agent needed
→ Respond directly with explanation
text
用户:"React是如何工作的?"
→ 类型:问题
→ 无需调用Agent
→ 直接给出解释

Case 2: Extremely Vague Request

情况2:极其模糊的请求

text
User: "Make it better"
→ Complexity: UNCLEAR
→ Action: Ask clarifying questions first
→ Then route to appropriate agent
text
用户:"让它变得更好"
→ 复杂度:不明确
→ 操作:先询问澄清问题
→ 再路由至对应Agent

Case 3: Contradictory Patterns

情况3:冲突模式

text
User: "Add mobile support to the web app"
→ Conflict: mobile vs web
→ Action: Ask: "Do you want responsive web or native mobile app?"
→ Then route accordingly
text
用户:"为Web应用添加移动端支持"
→ 冲突:移动端 vs Web
→ 操作:询问:"您需要响应式Web还是原生移动端应用?"
→ 再进行相应路由

Integration with Existing Workflows

与现有工作流的集成

With /orchestrate Command

与/orchestrate命令集成

  • User types
    /orchestrate
    : Explicit orchestration mode
  • AI detects complex task: Auto-invoke orchestrator (same result)
Difference: User doesn't need to know the command exists.
  • 用户输入
    /orchestrate
    :显式编排模式
  • AI检测到复杂任务:自动调用orchestrator(结果相同)
差异:用户无需知晓该命令的存在。

With Socratic Gate

与引导性审查集成

  • Auto-routing does NOT bypass Socratic Gate
  • If task is unclear, still ask questions first
  • Then route to appropriate agent
  • 自动路由不会绕过引导性审查
  • 如果任务不明确,仍需先询问问题
  • 再路由至对应Agent

With GEMINI.md Rules

与GEMINI.md规则集成

  • Priority: GEMINI.md rules > intelligent-routing
  • If GEMINI.md specifies explicit routing, follow it
  • Intelligent routing is the DEFAULT when no explicit rule exists
  • 优先级:GEMINI.md规则 > 智能路由
  • 如果GEMINI.md指定了显式路由,遵循该规则
  • 当无显式规则时,智能路由为默认方式

Testing the System

系统测试

Test Cases

测试用例

Test 1: Simple Frontend Task

测试1:简单前端任务

text
User: "Create a dark mode toggle button"
Expected: Auto-invoke frontend-specialist
Verify: Response shows "Using @frontend-specialist"
text
用户:"创建一个深色模式切换按钮"
预期:自动调用frontend-specialist
验证:响应显示"正在使用@frontend-specialist"

Test 2: Security Task

测试2:安全任务

text
User: "Review the authentication flow for vulnerabilities"
Expected: Auto-invoke security-auditor
Verify: Security-focused analysis
text
用户:"审查身份验证流程以查找漏洞"
预期:自动调用security-auditor
验证:提供安全相关分析

Test 3: Complex Multi-Domain

测试3:复杂多领域任务

text
User: "Build a chat application with real-time notifications"
Expected: Auto-invoke orchestrator
Verify: Multiple agents coordinated (backend, frontend, test)
text
用户:"构建带有实时通知的聊天应用"
预期:自动调用orchestrator
验证:协调多个Agent(后端、前端、测试)

Test 4: Bug Fix

测试4:Bug修复

text
User: "Login is not working, getting 401 error"
Expected: Auto-invoke debugger
Verify: Systematic debugging approach
text
用户:"登录功能无法使用,出现401错误"
预期:自动调用debugger
验证:采用系统化调试方法

Performance Considerations

性能考量

Token Usage

Token使用

  • Analysis adds ~50-100 tokens per request
  • Tradeoff: Better accuracy vs slight overhead
  • Overall SAVES tokens by reducing back-and-forth
  • 每次请求分析增加约50-100个Token
  • 权衡:更高的准确性 vs 轻微的开销
  • 总体通过减少来回沟通节省Token

Response Time

响应时间

  • Analysis is instant (pattern matching)
  • No additional API calls required
  • Agent selection happens before first response
  • 分析是即时的(模式匹配)
  • 无需额外API调用
  • Agent选择在首次响应前完成

User Education

用户教育

Optional: First-Time Explanation

可选:首次交互说明

If this is the first interaction in a project:
markdown
💡 **Tip**: I am configured with automatic specialist agent selection.
I will always choose the most suitable specialist for your task. You can
still mention agents explicitly with `@agent-name` if you prefer.
如果是项目中的首次交互:
markdown
💡 **提示**:我配置了自动专业Agent选择功能。
我会始终为您的任务选择最合适的专业Agent。如果您偏好,也可以通过`@agent-name`明确指定Agent。

Debugging Agent Selection

调试Agent选择

Enable Debug Mode (for development)

启用调试模式(开发环境)

Add to GEMINI.md temporarily:
markdown
undefined
临时添加至GEMINI.md:
markdown
undefined

DEBUG: Intelligent Routing

DEBUG: 智能路由

Show selection reasoning:
  • Detected domains: [list]
  • Selected agent: [name]
  • Reasoning: [why]
undefined
显示选择推理过程:
  • 检测到的领域:[列表]
  • 选中的Agent:[名称]
  • 推理原因:[说明]
undefined

Summary

总结

intelligent-routing skill enables:
✅ Zero-command operation (no need for
/orchestrate
)
✅ Automatic specialist selection based on request analysis
✅ Transparent communication of which expertise is being applied
✅ Seamless integration with existing workflows
✅ Override capability for explicit agent mentions
✅ Fallback to orchestrator for complex tasks
Result: User gets specialist-level responses without needing to know the system architecture.

Next Steps: Integrate this skill into GEMINI.md TIER 0 rules.
智能路由功能实现:
✅ 无需命令操作(无需使用
/orchestrate

✅ 基于请求分析自动选择专业Agent
✅ 透明告知正在应用的专业能力
✅ 与现有工作流无缝集成
✅ 支持用户明确指定Agent以覆盖自动选择
✅ 复杂任务自动回退至Orchestrator
结果:用户无需了解系统架构,即可获得专业级响应。

下一步:将此功能集成至GEMINI.md层级0规则中。