Skip to main content

When to use it

  • Short user inputs need to be mapped to a handful of flows before you invest in full orchestration.
  • You want to gate automation on a confidence score (only auto-run when the intent is clear, otherwise escalate).
  • You need structured metadata—like extracted entities or a human-readable reason—to feed into downstream logic.
  • You want deterministic categorisation (embeddings) or richer explanations (LLM) without building a bespoke classifier.

Defining intents

Every classifier consumes a list of Intent objects:
  • description gives the classifier context and is surfaced in tracing metadata.
  • examples dramatically improve accuracy—provide several phrasing variants.
  • metadata is propagated to the result so you can attach business logic (e.g. SLA, handoff target).

Choosing a classifier

LLM classification enforces a strict JSON schema (StructuredIntentResponse), ensuring stable output even under temperature.

Quick start

Working with results

  • LLM classifier returns LLMIntentClassificationResult with:
    • intent: matched intent name.
    • confidence: "low", "medium", "high" (auto-quantised from raw scores).
    • p_score: continuous probability (0–1).
    • reasoning: short explanation.
    • extracted_entities: optional name/value pairs surfaced by the LLM.
  • Embedding classifier returns IntentClassificationResult with intent and p_score. Sort or threshold the score to decide automation boundaries.
Both variants support top_k, letting you offer alternatives to a human or feed multiple candidates into a downstream router.

Integrating with the router

Intent classifiers and routers pair naturally: classify first, then route using a richer skill set.
The intent name/metadata can be prepended to the router prompt (as above) or used to select different router instances entirely.

Tuning and operations

  • Override classification_instruction to bias LLM behaviour (hierarchical intents, abstain thresholds, multilingual hints).
  • Pass request_params=RequestParams(strict=True, temperature=0) to disable sampling variance for high-stakes automation.
  • Pre-compute embeddings for cold start by calling await classifier.initialize() at app startup.
  • Record tracing output (otel.enabled: true) to inspect intent descriptions, examples, and resulting confidence scores per request.

Example projects