fix: classify current prompt intent, not full history#10
Conversation
Route classification now uses only system prompt + last 3 messages + current prompt instead of the entire conversation history (235+ msgs). This prevents every request from being classified as 'reasoning' with 'lengthy-content' signal regardless of actual complexity. Fixes #9
There was a problem hiding this comment.
Score: Excellent ✅
The PR addresses a critical issue where the routing classifier was over-classifying prompts due to excessive context. The fix involves adjusting the classifyWithRouter input to be more focused, incorporating only the system prompt, the last three messages, and the current prompt. This ensures accurate and contextually relevant routing decisions, improving the efficiency and correctness of the slimclaw plugin.
1 finding posted as inline comments below.
Review completed in 27s | Basic Plan | Gemini 2.5 Flash
| const history = (historyMessages as any[]) || []; | ||
| const recentHistory = history.slice(-3); | ||
| for (const msg of recentHistory) { | ||
| if (!msg) continue; |
There was a problem hiding this comment.
ℹ️ Info
The history.slice(-3) operation will always return an array, even if empty. If history is undefined or null, recentHistory will be an empty array, and the loop will not execute. Therefore, the if (!msg) continue; check at src/index.ts:352 is redundant and can be removed.
Fix: Remove the if (!msg) continue; statement as msg will always be defined within the loop if recentHistory contains elements. The recentHistory array will not contain null or undefined elements itself.
🤖 Prompt for AI Agents
In src/index.ts around line 352:
Issue: The `history.slice(-3)` operation will always return an array, even if empty. If `history` is `undefined` or `null`, `recentHistory` will be an empty array, and the loop will not execute. Therefore, the `if (!msg) continue;` check at `src/index.ts:352` is redundant and can be removed.
Remove the `if (!msg) continue;` statement as `msg` will always be defined within the loop if `recentHistory` contains elements. The `recentHistory` array will not contain `null` or `undefined` elements itself.
- Replace `as any` routing config access with typed Record<string, unknown> - Type routingTier as ComplexityTier instead of string (remove `as any`) - Handle content blocks properly: extract text from arrays instead of JSON.stringify - Remove redundant null guard in classification message loop Closes #12
- Replace `as any` routing config access with typed Record<string, unknown> - Type routingTier as ComplexityTier instead of string (remove `as any`) - Handle content blocks properly: extract text from arrays instead of JSON.stringify - Remove redundant null guard in classification message loop Closes #12
Problem
The routing classifier was passing the entire conversation history (235+ messages, 300k+ chars) to
classifyWithRouter. This caused every single request — even a simple "oi" — to be classified asreasoningtier withlengthy-contentsignal.Fix
Changed the classification input to only include:
This ensures the classifier evaluates the intent of the current request, not the volume of prior conversation.
Before
After
Files Changed
src/index.ts—llm_inputhook routing classificationFixes #9
🐕 GitSniff Summary
What this PR does
This pull request refines the routing classification logic within the
slimclawplugin by reducing the input context provided to theclassifyWithRouterfunction. It now intelligently filters the conversation history, including only the system prompt, the last three messages, and the current prompt, to accurately assess the intent of the current request rather than the cumulative volume of the entire conversation. This change significantly improves the precision of AI model routing, preventing simple requests from being misclassified as complex, leading to more efficient resource utilization.Key Changes
llm_inputhook to pass a curated set of messages (system prompt, last 3 messages, current prompt) toclassifyWithRouter.Review Score: Excellent 🟢
Tip
No major issues found. Safe to merge.
🐕 Reviewed by GitSniff