Home Projects Portfolio Dashboard Export PDF Log in

Implementing Semantic Intent Classification in Cronix

Improving Agent Intelligence

Building robust AI agents often hits a wall when the model struggles to differentiate between simple user intents, leading to unnecessary hallucinations or inefficient tool calls. In the Cronix project, we needed a lightweight way to classify user input into canonical intents—like booking or cancelling an appointment—without incurring additional latency or API costs.

The Problem: Intent Ambiguity

Our existing ReAct loop handled logic well, but it lacked a pre-processing step to help it understand user objectives immediately. Relying solely on a large language model for classification at every turn introduced:

  1. Latency overhead on the hot path.
  2. Increased token costs.
  3. Risk of inconsistent intent detection.

The Solution: Semantic Routing

We implemented a semantic router that uses precomputed embeddings (gte-small) to categorize incoming messages locally. By running this classification in parallel with existing memory retrieval, we achieve zero additional latency.

We defined an interface to ensure cross-runtime parity between our Node.js agent and our Deno-based Edge functions:

interface ISemanticRouter {
  classify(input: string): Promise<Intent | null>;
}

class SemanticRouter implements ISemanticRouter {
  constructor(private embedder: IEmbedder) {}

  async classify(input: string): Promise<Intent | null> {
    const vector = await this.embedder.embed(input);
    const matches = this.compare(vector, this.prototypes);
    return matches.confidence >= 0.85 ? matches.intent : null;
  }
}

This pattern allows the router to act as a "soft signal" provider. If the confidence threshold of 0.85 is met, we inject a hint into the system prompt, guiding the LLM without forcing a hard-coded path.

Results and Performance

By precomputing embeddings at build time and injecting them as static JSON, the runtime component only performs a vector dot-product calculation. This ensures the classification logic remains completely off the main critical path of the agent's response generation.

  • Zero DB load: Classification is memory-resident.
  • Zero API lag: Parallel execution with memory retrieval.
  • High Reliability: Parity tests ensure the same intent logic works across both Node and Deno environments.

Getting Started

  1. Define your canonical intents and provide 4-5 sample phrases for each.
  2. Create a script to generate embeddings for these phrases at build time.
  3. Implement a SemanticRouter that compares incoming query vectors against your precomputed prototypes.
  4. Use the result as a hint in your system prompt rather than a rigid controller.

Key Insight

Don't let your LLM do the heavy lifting for classification. Offloading intent detection to a lightweight, precomputed vector router keeps your agents fast, cost-effective, and focused on the creative work.


Generated with Gitvlg.com

Implementing Semantic Intent Classification in Cronix
Luis Romero

Luis Romero

Author

Share: