How OmniRoute's Intent Classifier Routes Requests to the Most Suitable Models

OmniRoute’s intent classifier uses a multilingual keyword-based detection system with strict priority logic to categorize prompts into intents like code, math, or creative, then maps these to task types that drive the AutoCombo engine’s fitness scoring to select the optimal model for each request.

OmniRoute determines the best-fit model for incoming requests through a deterministic intent classification pipeline. The system, implemented in the diegosouzapw/OmniRoute repository, analyzes user prompts using keyword matching to route traffic to specialized models capable of handling specific task types. This architecture ensures that code generation requests reach code-optimized models while creative writing tasks route to appropriately tuned alternatives.

Core Classification Logic

The intent classification system operates through a priority-based keyword matching engine that inspects prompt content to determine the user’s objective.

Multilingual Keyword Detection

The core routine lives in open-sse/services/intentClassifier.ts. The classifyPromptIntent(prompt, systemPrompt?) function constructs a lower-cased string from the user prompt and optional system prompt, then checks it against a series of keyword arrays: CODE_KEYWORDS, MATH_KEYWORDS, REASONING_KEYWORDS, CREATIVE_KEYWORDS, and SIMPLE_KEYWORDS.

The check follows a strict priority order—code → math → reasoning → creative → simple → medium—so the first matching category wins. If none of the language-specific keywords match, the function falls back to a medium intent, which serves as the default for ambiguous or long prompts.

Configuration and Extensibility

For projects requiring domain-specific triggers, classifyWithConfig (defined at line 33 of open-sse/services/intentClassifier.ts) accepts an IntentClassifierConfig object. Callers can enable or disable the classifier and supply additional keyword lists such as extraCodeKeywords or adjust thresholds like simpleMaxWords to fine-tune classification behavior for specific use cases.

Routing Pipeline Integration

Once classified, the intent drives the AutoCombo routing logic through a structured pipeline that translates categorical labels into executable routing decisions.

Intent-to-Task Mapping

The AutoCombo pipeline uses a static map (INTENT_TO_TASK) that translates the Intent enum (code, math, reasoning, creative, simple, medium) into a task type understood by the combo router. For example, the code intent maps directly to the code task type, while simple maps to simple, ensuring the routing layer receives standardized categorical input regardless of the original prompt variation.

Pipeline Router Execution

In open-sse/services/autoCombo/pipelineRouter.ts (line 56), the router extracts the last user message, invokes classifyPromptIntent, and maps the result to a task type:

const intent = classifyPromptIntent(promptText, systemText);
const taskType = INTENT_TO_TASK[intent] ?? "simple";
log.info("PIPELINE", `Intent: ${intent} → task: ${taskType}`);

The chosen taskType directly influences which pipeline configuration (buildPipelineConfig) and model fitness scoring algorithms are applied to the request.

Model Fitness Evaluation

The combo engine, implemented in open-sse/services/autoCombo/engine.ts, receives the task type and uses it to evaluate the fitness of each model in the selected combo. The fitness function applies higher scores to models explicitly flagged as optimized for the given intent—for instance, a model designated as "code-optimized" receives elevated scores when processing the code intent. The highest-scoring model is then dispatched for the request.

Fallback Behavior

If the classifier is disabled via config.enabled === false or no keywords match the prompt content, the intent defaults to medium. This triggers the combo router to select a generic fallback model (such as deepseek-chat), ensuring the system remains operational even when classification confidence is low or the feature is inactive.

Implementation Examples

You can interact with the intent classifier directly or through the high-level pipeline interface.

Direct Intent Classification

To classify a prompt without invoking the full routing pipeline:

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

const userPrompt = "Write a Python function to sort a list";
const intent = classifyPromptIntent(userPrompt);
console.log(intent); // → "code"

Pipeline Integration

For automatic model selection based on intent:

import { pipelineRouter } from "./open-sse/services/autoCombo/pipelineRouter.ts";

// `body` is the incoming request payload
await pipelineRouter(body); // internally classifies intent and selects the optimal model

Custom Configuration

To extend keyword detection for specialized domains:

import { classifyWithConfig, DEFAULT_INTENT_CONFIG } from "./open-sse/services/intentClassifier.ts";

const customConfig = {
  ...DEFAULT_INTENT_CONFIG,
  extraCodeKeywords: ["dockerfile", "k8s"],
  simpleMaxWords: 80,
};

const intent = classifyWithConfig("Create a Dockerfile for Node.js", customConfig);
console.log(intent); // → "code"

Summary

  • Keyword-based detection: The classifier in open-sse/services/intentClassifier.ts scans prompts against prioritized keyword arrays to determine intent.
  • Strict priority order: Classification follows code → math → reasoning → creative → simple → medium, with the first match winning.
  • Configurable extension: classifyWithConfig allows custom keyword injection and threshold adjustment for domain-specific routing needs.
  • AutoCombo integration: The pipeline router maps intents to task types via INTENT_TO_TASK, then the engine scores model fitness accordingly.
  • Graceful fallback: Unmatched or disabled classification defaults to the medium intent, routing to generic fallback models.

Frequently Asked Questions

What happens if a prompt matches multiple keyword categories?

The classifier evaluates keywords in a strict priority sequence—code, math, reasoning, creative, then simple. The first category containing a matching keyword wins, ensuring deterministic routing even when prompts contain overlapping terminology.

Can the intent classifier be disabled or customized?

Yes. The classifyWithConfig function accepts an IntentClassifierConfig object that includes an enabled boolean flag and arrays for custom keywords like extraCodeKeywords. This allows operators to disable classification entirely or extend detection for specialized domains.

How does the classifier handle non-English prompts?

The system performs lower-case normalization on the combined prompt and system prompt strings, then matches against multilingual keyword arrays. While the source keywords are English-centric, the matching logic supports Unicode characters, and the repository includes test files such as tests/unit/intent-classifier-pipeline.test.ts that verify behavior across multiple languages.

Which models are selected for the "medium" fallback intent?

When classification defaults to medium—either because no keywords matched or the classifier was disabled—the AutoCombo engine typically selects generic-purpose models such as deepseek-chat. The specific fallback model depends on the active combo configuration and availability, but it prioritizes generalist capabilities over specialized optimization.

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 →