Smart Routing Skill
Intelligent routing engine for the /toh smart command. Routes any natural language request to the right agent(s).
🧠 Routing Pipeline
┌─────────────────────────────────────────────────────────────────┐
│ USER REQUEST │
├─────────────────────────────────────────────────────────────────┤
│ │
│ STEP 0: MEMORY CHECK (ALWAYS FIRST!) │
│ ├── Read .toh/memory/active.md │
│ ├── Read .toh/memory/summary.md │
│ ├── Read .toh/memory/decisions.md │
│ └── Build context understanding │
│ │
│ STEP 1: INTENT CLASSIFICATION │
│ ├── Pattern matching (keywords, phrases) │
│ ├── Context inference (from memory) │
│ └── Scope detection (simple/complex) │
│ │
│ STEP 2: CONFIDENCE SCORING │
│ ├── HIGH (80%+) → Direct execution │
│ ├── MEDIUM (50-80%) → Plan Agent first │
│ └── LOW (<50%) → Ask for clarification │
│ │
│ STEP 3: IDE DETECTION │
│ ├── Claude Code → Parallel execution enabled │
│ └── Other IDEs → Sequential execution only │
│ │
│ STEP 4: AGENT SELECTION & EXECUTION │
│ └── Route to appropriate agent(s) │
│ │
└─────────────────────────────────────────────────────────────────┘
📊 Intent Classification Matrix
Primary Patterns → Agent Mapping
| Pattern Category |
Keywords (EN) |
Keywords (TH) |
Primary Agent |
Confidence |
| Create UI |
create, add, make, build + page/component/UI |
สร้าง, เพิ่ม, ทำ + หน้า/component |
UI Agent |
HIGH |
| Add Logic |
logic, state, function, hook, validation |
logic, state, function, เพิ่ม logic |
Dev Agent |
HIGH |
| Fix Bug |
bug, error, broken, fix, not working |
bug, error, พัง, ไม่ทำงาน, แก้ |
Fix Agent |
HIGH |
| Improve Design |
prettier, beautiful, design, polish, style |
สวย, design, ปรับ design |
Design Agent |
HIGH |
| Testing |
test, check, verify |
test, ทดสอบ, เช็ค |
Test Agent |
HIGH |
| Connect Backend |
connect, database, Supabase, API, backend |
เชื่อม, database, Supabase |
Connect Agent |
HIGH |
| Deploy |
deploy, ship, production, publish |
deploy, ship, ขึ้น production |
Ship Agent |
HIGH |
| LINE Platform |
LINE, LIFF, Mini App |
LINE, LIFF |
LINE Agent |
HIGH |
| Mobile Platform |
mobile, iOS, Android, Expo, React Native |
mobile, มือถือ |
Mobile Agent |
HIGH |
| New Project |
new project, start, build app, create system |
project ใหม่, สร้าง app |
Vibe Agent |
HIGH |
| Planning |
plan, analyze, PRD, architecture |
วางแผน, วิเคราะห์ |
Plan Agent |
HIGH |
| AI/Prompt |
prompt, AI, chatbot, system prompt |
prompt, AI, chatbot |
Dev Agent + prompt-optimizer |
HIGH |
| Continue |
continue, resume, go on |
ทำต่อ, ต่อ |
Memory → Last Agent |
MEDIUM |
| Complex Request |
Multiple features, system, e-commerce, etc. |
ระบบ + หลาย features |
Plan Agent |
MEDIUM |
| Vague Request |
help, fix it, make better (without context) |
ช่วยด้วย, แก้ที |
Ask Clarification |
LOW |
🎯 Confidence Scoring Algorithm
interface ConfidenceFactors {
keywordMatch: number; // 0-40 points
contextClarity: number; // 0-30 points
memorySupport: number; // 0-20 points
scopeDefinition: number; // 0-10 points
}
function calculateConfidence(request: string, memory: Memory): number {
let score = 0;
// Keyword matching (0-40 points)
// Strong match with primary patterns = 40
// Partial match = 20
// No match = 0
score += keywordMatchScore(request);
// Context clarity (0-30 points)
// Specific page/component mentioned = 30
// General area mentioned = 15
// No specifics = 0
score += contextClarityScore(request);
// Memory support (0-20 points)
// Request relates to active task = 20
// Request relates to project = 10
// No memory context = 0
score += memorySupportScore(request, memory);
// Scope definition (0-10 points)
// Single clear task = 10
// Multiple related tasks = 5
// Unclear scope = 0
score += scopeDefinitionScore(request);
return score; // 0-100
}
// Thresholds
const HIGH_CONFIDENCE = 80; // Execute directly
const MEDIUM_CONFIDENCE = 50; // Route to Plan Agent
// Below 50 = Ask for clarification
🖥️ IDE Detection
Detection Method
function detectIDE(): 'claude-code' | 'cursor' | 'gemini' | 'codex' | 'unknown' {
// Check for IDE-specific markers
// Claude Code detection
if (hasClaudeCodeMarkers()) {
return 'claude-code';
}
// Cursor detection
if (hasCursorRules()) {
return 'cursor';
}
// Gemini CLI detection
if (hasGeminiConfig()) {
return 'gemini';
}
// Codex CLI detection
if (hasCodexConfig()) {
return 'codex';
}
return 'unknown';
}
Execution Strategy by IDE
| IDE |
Multi-Agent Strategy |
Reason |
| Claude Code |
Parallel (spawn sub-agents) |
Native support for parallel tool calls |
| Cursor |
Sequential |
More predictable, follows diff flow |
| Gemini CLI |
Sequential |
Safer execution model |
| Codex CLI |
Sequential |
Linear task processing |
| Unknown |
Sequential (default) |
Safe fallback |
🔄 Routing Decision Tree
Request arrives
│
▼
┌─────────────────────────────────────┐
│ 1. Load Memory Context │
└─────────────────────────────────────┘
│
▼
┌─────────────────────────────────────┐
│ 2. Is request "continue"/"ทำต่อ"? │
├── YES → Read memory, resume task │
└── NO → Continue analysis │
│
▼
┌─────────────────────────────────────┐
│ 3. Calculate Confidence Score │
└─────────────────────────────────────┘
│
├── Score >= 80 (HIGH)
│ └─→ Select agent based on intent
│ └─→ Execute directly
│
├── Score 50-79 (MEDIUM)
│ └─→ Route to Plan Agent
│ └─→ Plan Agent analyzes & routes
│
└── Score < 50 (LOW)
└─→ Ask clarifying question
└─→ Wait for user response
📋 Clarification Patterns
When to Ask
| Situation |
Example |
Action |
| No verb/action |
"the login" |
Ask: "What would you like to do with login?" |
| No target |
"make it work" |
Ask: "Which page/component should I fix?" |
| Multiple interpretations |
"improve it" |
Ask: "Design, performance, or features?" |
| Missing context + no memory |
"fix it" |
Ask: "What's broken? Describe the issue." |
When NOT to Ask
| Situation |
Example |
Action |
| Clear intent |
"create login page" |
Execute directly |
| Memory provides context |
"continue" + active task exists |
Resume from memory |
| Reasonable default exists |
"add a button" |
Add to current page context |
🎨 Skill Loading by Intent
| Detected Intent |
Skills to Load |
| New Project |
vibe-orchestrator, design-mastery, business-context, response-format |
| Create UI |
ui-first-builder, design-excellence, response-format |
| Add Logic |
dev-engineer, error-handling, response-format |
| Fix Bug |
debug-protocol, error-handling, response-format |
| Connect Backend |
backend-engineer, integrations, response-format |
| Improve Design |
design-excellence, design-mastery, response-format |
| AI/Chatbot |
prompt-optimizer, dev-engineer, response-format |
| Testing |
test-engineer, error-handling, response-format |
| Planning |
plan-orchestrator, business-context, response-format |
Note: response-format skill is ALWAYS loaded for proper output formatting.
💾 Memory Integration
Pre-Routing Memory Check
Before routing, ALWAYS:
1. Read .toh/memory/active.md
- Current task context
- In-progress work
- Blockers
2. Read .toh/memory/summary.md
- Project overview
- Completed features
- Tech stack used
3. Read .toh/memory/decisions.md
- Past architectural decisions
- Design choices
- Naming conventions
Use memory to:
- Boost confidence (if request matches active work)
- Provide context (for ambiguous "it" references)
- Maintain consistency (follow established patterns)
Post-Execution Memory Save
After routing completes, ALWAYS:
1. Update .toh/memory/active.md
- Mark completed items
- Update current focus
- Set next steps
2. Add to .toh/memory/decisions.md
- If new decisions were made
3. Update .toh/memory/summary.md
- If feature was completed
⚠️ NEVER finish without saving memory!
📌 Examples
Example 1: High Confidence → Direct
Request: "/toh สร้างหน้า dashboard"
Analysis:
- Keyword match: "สร้าง" + "หน้า" = Create UI (40 pts)
- Context clarity: "dashboard" = specific page (30 pts)
- Memory: Project has other pages (15 pts)
- Scope: Single page (10 pts)
Total: 95 pts = HIGH
Route: UI Agent (direct)
Example 2: Medium Confidence → Plan First
Request: "/toh build e-commerce"
Analysis:
- Keyword match: "build" = Create (40 pts)
- Context clarity: "e-commerce" = general concept (10 pts)
- Memory: New project (0 pts)
- Scope: Multiple features (0 pts)
Total: 50 pts = MEDIUM
Route: Plan Agent first → then execute plan
Example 3: Low Confidence → Ask
Request: "/toh fix it"
Analysis:
- Keyword match: "fix" (20 pts)
- Context clarity: "it" = unclear (0 pts)
- Memory: No recent bugs (0 pts)
- Scope: Unknown (0 pts)
Total: 20 pts = LOW
Action: Ask "What would you like me to fix? Please describe the issue."
⚠️ Critical Rules
- Memory ALWAYS first - Never route without checking context
- Confidence drives action - Trust the scoring system
- Plan Agent is your friend - When in doubt, route to Plan
- IDE awareness matters - Parallel only in Claude Code
- response-format always loaded - Every response needs 3 sections
Smart Routing Skill v1.0.0 - Intelligent Request Routing Engine
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: wasintoh-toh-framework-smart-routing3description: Smart Routing Skill4---56# Smart Routing Skill78Intelligent routing engine for the `/toh` smart command. Routes any natural language request to the right agent(s).910---1112## 🧠 Routing Pipeline1314```15┌─────────────────────────────────────────────────────────────────┐16│ USER REQUEST │17├─────────────────────────────────────────────────────────────────┤18│ │19│ STEP 0: MEMORY CHECK (ALWAYS FIRST!) │20│ ├── Read .toh/memory/active.md │21│ ├── Read .toh/memory/summary.md │22│ ├── Read .toh/memory/decisions.md │23│ └── Build context understanding │24│ │25│ STEP 1: INTENT CLASSIFICATION │26│ ├── Pattern matching (keywords, phrases) │27│ ├── Context inference (from memory) │28│ └── Scope detection (simple/complex) │29│ │30│ STEP 2: CONFIDENCE SCORING │31│ ├── HIGH (80%+) → Direct execution │32│ ├── MEDIUM (50-80%) → Plan Agent first │33│ └── LOW (<50%) → Ask for clarification │34│ │35│ STEP 3: IDE DETECTION │36│ ├── Claude Code → Parallel execution enabled │37│ └── Other IDEs → Sequential execution only │38│ │39│ STEP 4: AGENT SELECTION & EXECUTION │40│ └── Route to appropriate agent(s) │41│ │42└─────────────────────────────────────────────────────────────────┘43```4445---4647## 📊 Intent Classification Matrix4849### Primary Patterns → Agent Mapping5051| Pattern Category | Keywords (EN) | Keywords (TH) | Primary Agent | Confidence |52|------------------|---------------|---------------|---------------|------------|53| **Create UI** | create, add, make, build + page/component/UI | สร้าง, เพิ่ม, ทำ + หน้า/component | UI Agent | HIGH |54| **Add Logic** | logic, state, function, hook, validation | logic, state, function, เพิ่ม logic | Dev Agent | HIGH |55| **Fix Bug** | bug, error, broken, fix, not working | bug, error, พัง, ไม่ทำงาน, แก้ | Fix Agent | HIGH |56| **Improve Design** | prettier, beautiful, design, polish, style | สวย, design, ปรับ design | Design Agent | HIGH |57| **Testing** | test, check, verify | test, ทดสอบ, เช็ค | Test Agent | HIGH |58| **Connect Backend** | connect, database, Supabase, API, backend | เชื่อม, database, Supabase | Connect Agent | HIGH |59| **Deploy** | deploy, ship, production, publish | deploy, ship, ขึ้น production | Ship Agent | HIGH |60| **LINE Platform** | LINE, LIFF, Mini App | LINE, LIFF | LINE Agent | HIGH |61| **Mobile Platform** | mobile, iOS, Android, Expo, React Native | mobile, มือถือ | Mobile Agent | HIGH |62| **New Project** | new project, start, build app, create system | project ใหม่, สร้าง app | Vibe Agent | HIGH |63| **Planning** | plan, analyze, PRD, architecture | วางแผน, วิเคราะห์ | Plan Agent | HIGH |64| **AI/Prompt** | prompt, AI, chatbot, system prompt | prompt, AI, chatbot | Dev Agent + prompt-optimizer | HIGH |65| **Continue** | continue, resume, go on | ทำต่อ, ต่อ | Memory → Last Agent | MEDIUM |66| **Complex Request** | Multiple features, system, e-commerce, etc. | ระบบ + หลาย features | Plan Agent | MEDIUM |67| **Vague Request** | help, fix it, make better (without context) | ช่วยด้วย, แก้ที | Ask Clarification | LOW |6869---7071## 🎯 Confidence Scoring Algorithm7273```typescript74interface ConfidenceFactors {75 keywordMatch: number; // 0-40 points76 contextClarity: number; // 0-30 points77 memorySupport: number; // 0-20 points78 scopeDefinition: number; // 0-10 points79}8081function calculateConfidence(request: string, memory: Memory): number {82 let score = 0;83 84 // Keyword matching (0-40 points)85 // Strong match with primary patterns = 4086 // Partial match = 2087 // No match = 088 score += keywordMatchScore(request);89 90 // Context clarity (0-30 points)91 // Specific page/component mentioned = 3092 // General area mentioned = 1593 // No specifics = 094 score += contextClarityScore(request);95 96 // Memory support (0-20 points)97 // Request relates to active task = 2098 // Request relates to project = 1099 // No memory context = 0100 score += memorySupportScore(request, memory);101 102 // Scope definition (0-10 points)103 // Single clear task = 10104 // Multiple related tasks = 5105 // Unclear scope = 0106 score += scopeDefinitionScore(request);107 108 return score; // 0-100109}110111// Thresholds112const HIGH_CONFIDENCE = 80; // Execute directly113const MEDIUM_CONFIDENCE = 50; // Route to Plan Agent114// Below 50 = Ask for clarification115```116117---118119## 🖥️ IDE Detection120121### Detection Method122123```typescript124function detectIDE(): 'claude-code' | 'cursor' | 'gemini' | 'codex' | 'unknown' {125 // Check for IDE-specific markers126 127 // Claude Code detection128 if (hasClaudeCodeMarkers()) {129 return 'claude-code';130 }131 132 // Cursor detection133 if (hasCursorRules()) {134 return 'cursor';135 }136 137 // Gemini CLI detection138 if (hasGeminiConfig()) {139 return 'gemini';140 }141 142 // Codex CLI detection143 if (hasCodexConfig()) {144 return 'codex';145 }146 147 return 'unknown';148}149```150151### Execution Strategy by IDE152153| IDE | Multi-Agent Strategy | Reason |154|-----|---------------------|--------|155| **Claude Code** | Parallel (spawn sub-agents) | Native support for parallel tool calls |156| **Cursor** | Sequential | More predictable, follows diff flow |157| **Gemini CLI** | Sequential | Safer execution model |158| **Codex CLI** | Sequential | Linear task processing |159| **Unknown** | Sequential (default) | Safe fallback |160161---162163## 🔄 Routing Decision Tree164165```166Request arrives167 │168 ▼169┌─────────────────────────────────────┐170│ 1. Load Memory Context │171└─────────────────────────────────────┘172 │173 ▼174┌─────────────────────────────────────┐175│ 2. Is request "continue"/"ทำต่อ"? │176├── YES → Read memory, resume task │177└── NO → Continue analysis │178 │179 ▼180┌─────────────────────────────────────┐181│ 3. Calculate Confidence Score │182└─────────────────────────────────────┘183 │184 ├── Score >= 80 (HIGH)185 │ └─→ Select agent based on intent186 │ └─→ Execute directly187 │188 ├── Score 50-79 (MEDIUM)189 │ └─→ Route to Plan Agent190 │ └─→ Plan Agent analyzes & routes191 │192 └── Score < 50 (LOW)193 └─→ Ask clarifying question194 └─→ Wait for user response195```196197---198199## 📋 Clarification Patterns200201### When to Ask202203| Situation | Example | Action |204|-----------|---------|--------|205| No verb/action | "the login" | Ask: "What would you like to do with login?" |206| No target | "make it work" | Ask: "Which page/component should I fix?" |207| Multiple interpretations | "improve it" | Ask: "Design, performance, or features?" |208| Missing context + no memory | "fix it" | Ask: "What's broken? Describe the issue." |209210### When NOT to Ask211212| Situation | Example | Action |213|-----------|---------|--------|214| Clear intent | "create login page" | Execute directly |215| Memory provides context | "continue" + active task exists | Resume from memory |216| Reasonable default exists | "add a button" | Add to current page context |217218---219220## 🎨 Skill Loading by Intent221222| Detected Intent | Skills to Load |223|-----------------|----------------|224| New Project | vibe-orchestrator, design-mastery, business-context, response-format |225| Create UI | ui-first-builder, design-excellence, response-format |226| Add Logic | dev-engineer, error-handling, response-format |227| Fix Bug | debug-protocol, error-handling, response-format |228| Connect Backend | backend-engineer, integrations, response-format |229| Improve Design | design-excellence, design-mastery, response-format |230| AI/Chatbot | prompt-optimizer, dev-engineer, response-format |231| Testing | test-engineer, error-handling, response-format |232| Planning | plan-orchestrator, business-context, response-format |233234**Note:** `response-format` skill is ALWAYS loaded for proper output formatting.235236---237238## 💾 Memory Integration239240### Pre-Routing Memory Check241242```markdown243Before routing, ALWAYS:2441. Read .toh/memory/active.md245 - Current task context246 - In-progress work247 - Blockers248 2492. Read .toh/memory/summary.md250 - Project overview251 - Completed features252 - Tech stack used253 2543. Read .toh/memory/decisions.md255 - Past architectural decisions256 - Design choices257 - Naming conventions258259Use memory to:260- Boost confidence (if request matches active work)261- Provide context (for ambiguous "it" references)262- Maintain consistency (follow established patterns)263```264265### Post-Execution Memory Save266267```markdown268After routing completes, ALWAYS:2691. Update .toh/memory/active.md270 - Mark completed items271 - Update current focus272 - Set next steps273 2742. Add to .toh/memory/decisions.md275 - If new decisions were made276 2773. Update .toh/memory/summary.md278 - If feature was completed279280⚠️ NEVER finish without saving memory!281```282283---284285## 📌 Examples286287### Example 1: High Confidence → Direct288289```290Request: "/toh สร้างหน้า dashboard"291292Analysis:293- Keyword match: "สร้าง" + "หน้า" = Create UI (40 pts)294- Context clarity: "dashboard" = specific page (30 pts)295- Memory: Project has other pages (15 pts)296- Scope: Single page (10 pts)297Total: 95 pts = HIGH298299Route: UI Agent (direct)300```301302### Example 2: Medium Confidence → Plan First303304```305Request: "/toh build e-commerce"306307Analysis:308- Keyword match: "build" = Create (40 pts)309- Context clarity: "e-commerce" = general concept (10 pts)310- Memory: New project (0 pts)311- Scope: Multiple features (0 pts)312Total: 50 pts = MEDIUM313314Route: Plan Agent first → then execute plan315```316317### Example 3: Low Confidence → Ask318319```320Request: "/toh fix it"321322Analysis:323- Keyword match: "fix" (20 pts)324- Context clarity: "it" = unclear (0 pts)325- Memory: No recent bugs (0 pts)326- Scope: Unknown (0 pts)327Total: 20 pts = LOW328329Action: Ask "What would you like me to fix? Please describe the issue."330```331332---333334## ⚠️ Critical Rules3353361. **Memory ALWAYS first** - Never route without checking context3372. **Confidence drives action** - Trust the scoring system3383. **Plan Agent is your friend** - When in doubt, route to Plan3394. **IDE awareness matters** - Parallel only in Claude Code3405. **response-format always loaded** - Every response needs 3 sections341342---343344*Smart Routing Skill v1.0.0 - Intelligent Request Routing Engine*345346---347> Converted and distributed by [TomeVault](https://tomevault.io/claim/wasintoh) — claim your Tome and manage your conversions.348<!-- tomevault:4.0:skill_md:2026-04-11 -->