LLMClassifier
LLMClassifier is the default classifier. It builds a system prompt from all registered agents’ id, name, and description, then calls your LLM client with a select_agent tool. The model calls that tool with the chosen agent’s id and a confidence value; an absent or hallucinated id resolves to nil, triggering the Orchestrator’s default-agent fallback.
See the Classifiers overview for how ClassifierResult and the routing dispatch work.
Initializer
Section titled “Initializer”public struct LLMClassifier: Classifier { public init(model: any LLMClient, instructions: String = LLMClassifier.defaultInstructions)}| Parameter | Type | Default | Notes |
|---|---|---|---|
model | any LLMClient | — | The LLM backend used for routing calls. |
instructions | String | LLMClassifier.defaultInstructions | System prompt governing routing behaviour. See Custom instructions below. |
Basic usage
Section titled “Basic usage”Pass any LLMClient and you’re done:
let classifier = LLMClassifier( model: BedrockLLMClient(modelId: "us.anthropic.claude-3-5-haiku-20241022-v1:0"))
let orchestrator = Orchestrator(classifier: classifier, storage: storage)A lightweight model (Haiku, Flash, etc.) is usually sufficient — the task is structured tool-call routing, not open-ended generation.
Conversation continuity
Section titled “Conversation continuity”The history passed to classify is the merged, [agentId]-prefixed conversation fetched from chat storage. The default prompt instructs the model to use it for follow-up detection: short affirmations like “yes” or “ok” stay with the previously selected agent rather than triggering a fresh match.
Custom instructions
Section titled “Custom instructions”LLMClassifier.defaultInstructions contains an {{AGENT_DESCRIPTIONS}} placeholder that is replaced at classify time with a roster built from all registered agents. When you supply your own instructions string:
- With
{{AGENT_DESCRIPTIONS}}— the placeholder is replaced as usual. - Without
{{AGENT_DESCRIPTIONS}}— the agent roster is appended to the end of your instructions.
let classifier = LLMClassifier( model: myClient, instructions: """ You are a strict router. Only route to agents explicitly listed below. If no agent matches, do not call select_agent. {{AGENT_DESCRIPTIONS}} """)Default instructions reference
Section titled “Default instructions reference”LLMClassifier.defaultInstructions is public so you can inspect or extend it:
public static let defaultInstructions: StringIt encodes the AgentMatcher prompt ported from the Python agent-squad, including:
- Categorisation against the
{{AGENT_DESCRIPTIONS}}roster. - Confidence levels: High ≈ 0.9+, Medium ≈ 0.6–0.8, Low < 0.6.
- Follow-up continuation — short replies like “yes”, “ok”, or numeric answers route to the previously selected agent.
- Four worked examples covering initial queries, context switches, follow-ups, and multi-turn switches.
Related pages
Section titled “Related pages”- Classifiers overview — the
Classifierprotocol,ClassifierResult, and the nil-classifier path. - Custom classifiers — implement your own routing logic.
- LLM clients — the
LLMClientprotocol and built-in implementations.