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 ofIntent objects:
descriptiongives the classifier context and is surfaced in tracing metadata.examplesdramatically improve accuracy—provide several phrasing variants.metadatais propagated to the result so you can attach business logic (e.g. SLA, handoff target).
Choosing a classifier
| Variant | Factory helper | Best for | Output extras |
|---|---|---|---|
| LLM-based | create_intent_classifier_llm(...) | Highest quality natural language understanding, explanations, entity extraction | confidence (low/medium/high), p_score, reasoning, extracted_entities |
| Embedding-based | create_intent_classifier_embedding(...) | Deterministic scoring, lower latency, custom embedding providers | p_score (0–1 similarity) |
StructuredIntentResponse), ensuring stable output even under temperature.
Quick start
Working with results
- LLM classifier returns
LLMIntentClassificationResultwith: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
IntentClassificationResultwithintentandp_score. Sort or threshold the score to decide automation boundaries.
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.Tuning and operations
- Override
classification_instructionto 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
- workflow_intent_classifier – shows LLM + embedding classifiers side by side with downstream routing.
- Temporal examples – includes a classifier-driven Temporal workflow.
