OmniRoute Intent Classifier and Task-Aware Routing System: A Technical Deep Dive

The OmniRoute intent classifier and task-aware routing system uses synchronous multilingual keyword detection to categorize prompts into six intent types, then automatically routes requests to specialized model combinations based on those classifications.

The diegosouzapw/OmniRoute repository implements a zero-latency pipeline that analyzes incoming prompts before execution. This architecture ensures code generation tasks reach coding-optimized models while creative writing prompts route to appropriate providers, all without requiring manual configuration from end users.

How the Intent Classifier Analyzes Prompts

Located in open-sse/services/intentClassifier.ts, the intent classifier performs synchronous text analysis to determine what type of task the user is requesting. The system supports nine languages including English, Portuguese, Spanish, Chinese, Japanese, Russian, German, Korean, and Arabic.

Multilingual Keyword Detection Logic

The classifier maintains six readonly keyword arrays—CODE_KEYWORDS, MATH_KEYWORDS, REASONING_KEYWORDS, CREATIVE_KEYWORDS, SIMPLE_KEYWORDS, and MEDIUM_KEYWORDS—each containing approximately 50-plus trigger terms across all supported languages. When classifyPromptIntent(prompt, systemPrompt?) receives input, it iterates through these arrays and counts matches against the provided text.

Confidence Scoring and Fallback Handling

The classification algorithm calculates confidence using the formula matches / totalKeywords for each category. The intent with the highest confidence score wins. If no keywords match, the system falls back to "simple" for short prompts or "medium" for longer inputs based on character length thresholds. This entire process executes in under one millisecond without network I/O or disk access.

import { classifyPromptIntent } from './open-sse/services/intentClassifier';

const prompt = `Write a TypeScript function that fetches a JSON file and returns the parsed object.`;
const intent = classifyPromptIntent(prompt);
// Returns: { type: 'code', confidence: 0.93, signals: ['function', 'typescript'] }

How the Task-Aware Router Routes Requests

The task-aware router in open-sse/services/taskAwareRouter.ts consumes intent classification results and determines which provider combination should handle the request. This component bridges the gap between classification and execution.

Intent-to-Combo Mapping

The router maintains an internal IntentToComboMap that associates each intent type with a pre-configured combo name. For example, the "code" intent maps to "code-only" combos, while "creative" intents route to different provider configurations. The detectTaskType(prompt, systemPrompt?) function obtains the classification and resolves the appropriate combo strategy.

Fallback and Error Handling

When the intent-derived combo is unavailable due to provider outages or configuration changes, the router falls back to a generic combo while preserving the original intent metadata for telemetry. This ensures high availability without losing classification data that informs routing analytics.

End-to-End Request Flow

The integration between components follows a strict pipeline:

  1. Entry Point: The chat handler in src/sse/handlers/chat.ts receives the incoming request
  2. Classification: The handler invokes the intent classifier to determine task type
  3. Routing: The task-aware router selects the appropriate combo using detectTaskType
  4. Execution: The combo engine in open-sse/services/combo.ts resolves concrete providers and executes the request

This flow ensures that a prompt like "Calculate the integral of sin(x) from 0 to π" receives the "math" intent and routes to providers optimized for mathematical reasoning, while code generation tasks reach specialized coding models.

Implementation Examples

Direct Intent Classification

You can use the classifier standalone to analyze prompt content before processing:

import { classifyPromptIntent } from './open-sse/services/intentClassifier';

const userPrompt = `Calculate the integral of sin(x) from 0 to π.`;
const result = classifyPromptIntent(userPrompt);
console.log(result.type); // "math"
console.log(result.confidence); // 0.87

Custom Endpoint Integration

Build custom endpoints that leverage the task-aware router:

import { detectTaskType } from './open-sse/services/taskAwareRouter';
import { handleComboChat } from './open-sse/services/combo';

export async function customChatEndpoint(req) {
  const { prompt, systemPrompt } = req.body;
  const task = await detectTaskType(prompt, systemPrompt);
  // task.combo contains the resolved combo name, e.g., "code-only"
  return handleComboChat(task.combo, req);
}

Extending Intent Keywords

Add domain-specific keywords by modifying the arrays in open-sse/services/intentClassifier.ts:

// Add medical terminology to the reasoning keywords
export const REASONING_KEYWORDS = [
  ...existingKeywords,
  'diagnosis', 'symptom', 'treatment', 'prognosis'
];

Changes reflect immediately in routing decisions without requiring server rebuilds.

Testing and Validation

The repository includes comprehensive test coverage for both components. The unit tests in tests/unit/service-intent-classifier.test.ts validate detection accuracy across all six intent types and nine languages. Integration tests in tests/unit/combo-task-aware.test.ts verify that the router correctly forces code-only combos for code intents and selects appropriate providers for creative tasks.

Run the specific test suites to verify classification logic:

npm test tests/unit/service-intent-classifier.test.ts
npm test tests/unit/combo-task-aware.test.ts

Summary

  • Intent classification occurs in open-sse/services/intentClassifier.ts using synchronous multilingual keyword matching across six categories: code, math, reasoning, creative, simple, and medium
  • Zero-latency execution completes in under one millisecond without network or disk I/O
  • Task-aware routing in open-sse/services/taskAwareRouter.ts maps intents to specialized combos via IntentToComboMap
  • Automatic fallback preserves intent data when primary combos are unavailable
  • Integration point at src/sse/handlers/chat.ts coordinates the full pipeline from classification to execution

Frequently Asked Questions

How does the intent classifier handle multilingual prompts?

The classifier maintains separate keyword arrays for nine languages including English, Portuguese, Spanish, Chinese, Japanese, Russian, German, Korean, and Arabic. The classifyPromptIntent function checks against all language variants simultaneously, allowing mixed-language prompts to match keywords from any supported language. Confidence scores aggregate across languages, so a prompt containing both English and Chinese coding terms will register as a high-confidence code intent.

What happens when multiple intent keywords appear in the same prompt?

The classifier calculates confidence scores independently for each intent category using the ratio of matched keywords to total available keywords. The category with the highest confidence value wins. For example, if a prompt contains three math keywords and two code keywords, and the math keyword array has 50 total terms while the code array has 60, the math intent scores 3/50 = 0.06 and code scores 2/60 = 0.033, resulting in a math classification.

Can I disable task-aware routing for specific requests?

Yes, the router checks for explicit combo overrides before invoking intent classification. If the request specifies a combo parameter in the body or headers, the task-aware router bypasses classification and uses the provided combo directly. This allows forcing specific providers while still recording the intent for telemetry purposes.

Where does the routing system store intent classification results?

The system stores intent metadata in the request context object that flows through the pipeline. The detectTaskType function returns the intent object to the chat handler, which passes it to the combo engine in open-sse/services/combo.ts. The combo engine includes this data in logs and telemetry but does not persist it to permanent storage unless explicitly configured to do so via the observability 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:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →