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
1---2name: smart-routing-23description: Intelligent request routing for /toh command. Analyzes user intent, assesses confidence, detects IDE environment, and routes to the appropriate agent(s). Memory-first approach ensures context awareness. Triggers: /toh command, natural language requests, ambiguous inputs.4---5
6# Smart Routing Skill
7
8Intelligent routing engine for the `/toh` smart command. Routes any natural language request to the right agent(s).
9
10---
11
12## 🧠 Routing Pipeline
13
14```
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```
44
45---
46
47## 📊 Intent Classification Matrix
48
49### Primary Patterns → Agent Mapping
50
51| 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 |
68
69---
70
71## 🎯 Confidence Scoring Algorithm
72
73```typescript
74interface ConfidenceFactors {
75 keywordMatch: number; // 0-40 points
76 contextClarity: number; // 0-30 points
77 memorySupport: number; // 0-20 points
78 scopeDefinition: number; // 0-10 points
79}
80
81function calculateConfidence(request: string, memory: Memory): number {
82 let score = 0;
83
84 // Keyword matching (0-40 points)
85 // Strong match with primary patterns = 40
86 // Partial match = 20
87 // No match = 0
88 score += keywordMatchScore(request);
89
90 // Context clarity (0-30 points)
91 // Specific page/component mentioned = 30
92 // General area mentioned = 15
93 // No specifics = 0
94 score += contextClarityScore(request);
95
96 // Memory support (0-20 points)
97 // Request relates to active task = 20
98 // Request relates to project = 10
99 // No memory context = 0
100 score += memorySupportScore(request, memory);
101
102 // Scope definition (0-10 points)
103 // Single clear task = 10
104 // Multiple related tasks = 5
105 // Unclear scope = 0
106 score += scopeDefinitionScore(request);
107
108 return score; // 0-100
109}
110
111// Thresholds
112const HIGH_CONFIDENCE = 80; // Execute directly
113const MEDIUM_CONFIDENCE = 50; // Route to Plan Agent
114// Below 50 = Ask for clarification
115```
116
117---
118
119## 🖥️ IDE Detection
120
121### Detection Method
122
123```typescript
124function detectIDE(): 'claude-code' | 'cursor' | 'gemini' | 'codex' | 'unknown' {
125 // Check for IDE-specific markers
126
127 // Claude Code detection
128 if (hasClaudeCodeMarkers()) {
129 return 'claude-code';
130 }
131
132 // Cursor detection
133 if (hasCursorRules()) {
134 return 'cursor';
135 }
136
137 // Gemini CLI detection
138 if (hasGeminiConfig()) {
139 return 'gemini';
140 }
141
142 // Codex CLI detection
143 if (hasCodexConfig()) {
144 return 'codex';
145 }
146
147 return 'unknown';
148}
149```
150
151### Execution Strategy by IDE
152
153| 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 |
160
161---
162
163## 🔄 Routing Decision Tree
164
165```
166Request arrives
167 │
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 intent
186 │ └─→ Execute directly
187 │
188 ├── Score 50-79 (MEDIUM)
189 │ └─→ Route to Plan Agent
190 │ └─→ Plan Agent analyzes & routes
191 │
192 └── Score < 50 (LOW)
193 └─→ Ask clarifying question
194 └─→ Wait for user response
195```
196
197---
198
199## 📋 Clarification Patterns
200
201### When to Ask
202
203| 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." |
209
210### When NOT to Ask
211
212| 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 |
217
218---
219
220## 🎨 Skill Loading by Intent
221
222| 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 |
233
234**Note:** `response-format` skill is ALWAYS loaded for proper output formatting.
235
236---
237
238## 💾 Memory Integration
239
240### Pre-Routing Memory Check
241
242```markdown
243Before routing, ALWAYS:
2441. Read .toh/memory/active.md
245 - Current task context
246 - In-progress work
247 - Blockers
248
2492. Read .toh/memory/summary.md
250 - Project overview
251 - Completed features
252 - Tech stack used
253
2543. Read .toh/memory/decisions.md
255 - Past architectural decisions
256 - Design choices
257 - Naming conventions
258
259Use memory to:
260- Boost confidence (if request matches active work)
261- Provide context (for ambiguous "it" references)
262- Maintain consistency (follow established patterns)
263```
264
265### Post-Execution Memory Save
266
267```markdown
268After routing completes, ALWAYS:
2691. Update .toh/memory/active.md
270 - Mark completed items
271 - Update current focus
272 - Set next steps
273
2742. Add to .toh/memory/decisions.md
275 - If new decisions were made
276
2773. Update .toh/memory/summary.md
278 - If feature was completed
279
280⚠️ NEVER finish without saving memory!
281```
282
283---
284
285## 📌 Examples
286
287### Example 1: High Confidence → Direct
288
289```
290Request: "/toh สร้างหน้า dashboard"
291
292Analysis:
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 = HIGH
298
299Route: UI Agent (direct)
300```
301
302### Example 2: Medium Confidence → Plan First
303
304```
305Request: "/toh build e-commerce"
306
307Analysis:
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 = MEDIUM
313
314Route: Plan Agent first → then execute plan
315```
316
317### Example 3: Low Confidence → Ask
318
319```
320Request: "/toh fix it"
321
322Analysis:
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 = LOW
328
329Action: Ask "What would you like me to fix? Please describe the issue."
330```
331
332---
333
334## ⚠️ Critical Rules
335
3361. **Memory ALWAYS first** - Never route without checking context
3372. **Confidence drives action** - Trust the scoring system
3383. **Plan Agent is your friend** - When in doubt, route to Plan
3394. **IDE awareness matters** - Parallel only in Claude Code
3405. **response-format always loaded** - Every response needs 3 sections
341
342---
343
344*Smart Routing Skill v1.0.0 - Intelligent Request Routing Engine*