AI Agent User Intent Detection 2026
Intent detection for AI agents: a four-layer router of rules, small classifiers, embeddings and LLM structured output, plus slot validation and error-cost evaluation.
📜 Table of Contents
📖 Keep reading
Intent Detection for AI Agents: Routing Before You Call Tools
"Can you check something for me." Check what, where, and then do what? Without intent detection the agent hands an ambiguous sentence to a model and hopes. The result is the wrong tool, an off-topic answer, or three clarifying turns that go nowhere.
Define granularity
Two layers work better than a flat list: domain (orders, after-sales, account, product) crossed with action (read, modify, cancel, complain). Dozens of combinations stay maintainable and map naturally onto permission rules, since writes and cancellations deserve different confirmation flows.
Every intent needs a name, required slots, and the tool it maps to. An intent without slots cannot execute; it becomes an interrogation loop.
Four layers, ordered by cost
| Layer | Method | Latency | Use for |
|---|---|---|---|
| L1 | keywords and regex | milliseconds | fixed high-frequency phrasing |
| L2 | small classifier | tens of ms | known domain, enough labels |
| L3 | embedding nearest neighbours | ms to tens of ms | varied phrasing, tight semantics |
| L4 | LLM with structured output | 100ms to seconds | long tail, multi-intent, reasoning |
In practice L1 covers a surprising share of traffic: "refund", "invoice", "password" rarely get rephrased.
L1: let rules take the easy cases
import re
RULES = [
(r"(refund|return|money back)", "after_sales.refund"),
(r"(invoice|receipt|billing)", "finance.invoice"),
(r"(tracking|where is my order|carrier)", "order.tracking"),
]
def rule_match(text):
hits = [intent for pat, intent in RULES if re.search(pat, text, re.I)]
return hits[0] if len(hits) == 1 else None
Returning None on multiple hits matters. "How does the invoice work after a refund" is two intents; forcing one at the rule layer guarantees an error.
L2: a small classifier
A few hundred to a few thousand labels is enough to start. Include the previous user turn in the input, since single sentences often lack a subject, and carry a confidence score so low-confidence predictions fall through.
L3: embeddings
Store a handful of example phrasings per intent, embed the request, vote among nearest neighbours, and require a threshold before accepting.
def vector_intent(text, embedder, index, threshold=0.82):
v = embedder.embed([text])[0]
best = index.search(v, k=5)[0]
return best.intent if best.score >= threshold else None
Adding an intent means adding examples, not retraining, but the threshold is delicate: too high floods the LLM layer, too low turns "cancel my order" into "check my order". Tune on real data.
L4: structured output as the fallback
Constrain with JSON Schema: an array of intents (multi-intent is normal), extracted slots, and a need_clarify flag with a question. Giving the model an explicit exit beats forcing a guess. When need_clarify is true, ask the user instead of running tools.
Control cost by capping output length, sending an intent list rather than full tool descriptions, and letting simple requests stay in earlier layers.
Slots fail more often than intents
REQUIRED = {"order.change_address": ["order_id", "new_address"]}
missing = [s for s in REQUIRED.get(intent, []) if not slots.get(s)]
if missing:
return ask_user(missing)
Validate before calling the tool. Letting the tool report a missing argument shows users a technical error.
Evaluate by error cost, not accuracy
Build a confusion matrix and separate expensive mistakes. "Cancel" misread as "check" is an inconvenience; "check" misread as "cancel" is a loss. Track the expensive-direction error rate separately and require confirmation on all write operations. Ninety percent overall accuracy concentrated in the dangerous direction is not usable.
FAQ
How many intents? A dozen domains times five or six actions is usually enough; a flat list beyond fifty costs more than it returns.
LLM only? It works, but every request pays large-model latency and cost. Route the common cases earlier.
Multilingual? Separate rule sets per language, one multilingual embedding model, and an LLM layer that handles the rest.
Users change their mind? Recompute intent each turn instead of locking the first answer; keep a clearable "current task" in session state.
Related
Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.