OmniRoute Intent Classifier and Task-Aware Routing Architecture Explained
The OmniRoute intent classifier and task-aware routing architecture categorizes incoming LLM requests into specific task types (code, math, reasoning, creative, simple, or medium) using multilingual keyword detection, then routes each request to a specialized model combination (combo) optimized for that particular workload.
The diegosouzapw/OmniRoute repository implements a sophisticated intent classifier and task-aware routing architecture that enables intelligent request distribution across multiple LLM providers. This system analyzes user prompts at the edge to determine the nature of the task before selecting the optimal routing strategy. By combining zero-latency keyword classification with dynamic combo selection, OmniRoute ensures that code generation requests, mathematical queries, and creative writing tasks each reach the models best suited to handle them.
How the Intent Classifier Works
The intent classification system operates entirely within open-sse/services/intentClassifier.ts, providing synchronous, in-process analysis of every incoming request.
Multilingual Keyword Detection
The classifier maintains six distinct keyword arrays (CODE_KEYWORDS, MATH_KEYWORDS, REASONING_KEYWORDS, CREATIVE_KEYWORDS, SIMPLE_KEYWORDS, and MEDIUM_KEYWORDS) containing trigger words across nine languages including English, Portuguese, Spanish, Chinese, Japanese, Russian, German, Korean, and Arabic. Each category contains approximately 50-plus carefully curated terms designed to catch domain-specific language patterns.
When classifyPromptIntent(prompt, systemPrompt?) receives a request, it scans both the user prompt and optional system prompt against these arrays, counting matches and calculating confidence scores using the formula matches / totalKeywords.
Synchronous Classification Logic
The classification function executes in under 1 millisecond with zero I/O overhead, ensuring no network or disk latency impacts request processing. It returns a structured result containing the detected type (one of the six intent categories), a confidence score between 0 and 1, and an array of matching signals (the specific keywords that triggered the classification).
If no keywords match, the system applies fallback logic: prompts below a certain length threshold default to "simple", while longer prompts default to "medium".
// Example: classifying a developer prompt
import { classifyPromptIntent } from '@omniroute/open-sse/services/intentClassifier';
const prompt = `Write a TypeScript function that fetches a JSON file and returns the parsed object.`;
const intent = classifyPromptIntent(prompt);
// → { type: 'code', confidence: 0.93, signals: ['function', 'typescript'] }
Task-Aware Routing Architecture
Once the intent is determined, the task-aware routing system in open-sse/services/taskAwareRouter.ts takes over to map abstract task types to concrete infrastructure decisions.
Intent-to-Combo Mapping
The router maintains an internal IntentToComboMap that associates each intent type with a specific combo configuration. For example, a "code" intent triggers the "code-only" combo, while "creative" intents route to specialized creative writing combinations. This mapping ensures that requests requiring specific capabilities (like code execution or mathematical reasoning) are directed to providers that have proven performance in those domains.
The detectTaskType(prompt, systemPrompt?) function orchestrates this process by first invoking the intent classifier, then resolving the appropriate combo name through the mapping table.
Router Integration Points
The chat handler in src/sse/handlers/chat.ts serves as the primary entry point for this architecture. Upon receiving a request, it delegates to the task-aware router, which returns both the detected intent and the target combo name. The router then hands this combo configuration to the core combo engine in open-sse/services/combo.ts, which resolves the concrete provider/model list and executes the request.
If the intent-derived combo is unavailable (for instance, if a specific provider is disabled), the router implements fallback logic that selects a generic combo while preserving the original intent data for telemetry and analytics purposes.
import { detectTaskType } from '@omniroute/open-sse/services/taskAwareRouter';
import { handleComboChat } from '@omniroute/open-sse/services/combo';
export async function customChatEndpoint(req) {
const { prompt, systemPrompt } = req.body;
const task = await detectTaskType(prompt, systemPrompt); // → {type: 'code', combo: 'code-only'}
const comboName = task.combo;
return handleComboChat(comboName, req);
}
End-to-End Request Pipeline
The complete flow through the intent classifier and task-aware routing architecture follows this sequence:
- Request Ingress: The chat handler in
src/sse/handlers/chat.tsreceives the incoming request - Intent Detection: The classifier scans the prompt andreturns the task type and confidence score
- Combo Resolution: The router maps the intent to a specific combo via
IntentToComboMap - Provider Execution: The combo engine in
open-sse/services/combo.tsinstantiates the appropriate provider chain - Response Streaming: The selected provider executes the request and streams results back through the pipeline
This architecture ensures that a prompt like "Calculate the integral of sin(x) from 0 to π" receives a "math" classification with high confidence, routes to a combo optimized for mathematical reasoning, and avoids wasting tokens on general-purpose models that might struggle with calculus.
Testing and Validation
The implementation includes comprehensive test coverage to ensure routing accuracy:
tests/unit/service-intent-classifier.test.ts: Validates detection of all six intent types across multiple languages, ensuring keyword updates don't break classification accuracytests/unit/combo-task-aware.test.ts: Verifies that specific intents correctly force their associated combos (e.g., confirming"code"intent selects"code-only"combo) and that fallback behavior works when preferred combos are unavailable
These tests allow developers to extend keyword lists or modify routing logic confidently, knowing that the core classification and routing semantics remain intact.
Summary
- Zero-latency classification: The
classifyPromptIntentfunction inopen-sse/services/intentClassifier.tsperforms synchronous keyword matching across nine languages without network calls - Intent-driven routing: The
detectTaskTypefunction maps detected intents to specialized combos viaIntentToComboMapinopen-sse/services/taskAwareRouter.ts - Six task categories: The system recognizes
code,math,reasoning,creative,simple, andmediumintents with configurable confidence thresholds - Fallback resilience: When intent-specific combos are unavailable, the router gracefully degrades to generic combos while preserving intent metadata
- Pipeline integration: Classification occurs at the entry point in
src/sse/handlers/chat.tsbefore provider selection, ensuring optimal model matching
Frequently Asked Questions
How does the intent classifier handle multilingual prompts?
The classifier maintains separate keyword arrays for each intent type that include trigger words in nine languages (English, Portuguese, Spanish, Chinese, Japanese, Russian, German, Korean, and Arabic). When classifyPromptIntent processes a prompt, it scans against all language variants simultaneously, allowing it to correctly identify a coding request written in Japanese or a mathematical query in Spanish with equal accuracy.
What happens when a prompt matches multiple intent categories?
If keywords from multiple categories match (for example, a prompt containing both mathematical notation and code), the classifier calculates confidence scores for each category using the ratio of matches to total keywords in that category. It selects the intent with the highest confidence score. If confidence scores are tied, the system applies deterministic ordering based on the internal priority of the intent types.
Can I customize the combo selection for a specific intent type?
Yes. You can modify the IntentToComboMap in open-sse/services/taskAwareRouter.ts to change which combo handles each intent type, or create custom combos in open-sse/services/combo.ts and reference them in the mapping. The architecture supports adding new intent types by extending the keyword arrays in intentClassifier.ts and creating corresponding entries in the router's mapping table.
How does the system perform when no keywords match?
When classifyPromptIntent finds no matching keywords, it applies heuristic fallback logic based on prompt length. Short prompts default to the "simple" intent, while longer prompts default to "medium". This ensures every request receives a routing decision even when the content doesn't clearly match specialized categories, preventing requests from stalling in the classification layer.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →