Skip to content

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.

public struct LLMClassifier: Classifier {
public init(model: any LLMClient, instructions: String = LLMClassifier.defaultInstructions)
}
ParameterTypeDefaultNotes
modelany LLMClientThe LLM backend used for routing calls.
instructionsStringLLMClassifier.defaultInstructionsSystem prompt governing routing behaviour. See Custom instructions below.

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.

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.

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}}
"""
)

LLMClassifier.defaultInstructions is public so you can inspect or extend it:

public static let defaultInstructions: String

It 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.