Classifiers Overview
A classifier runs before each turn and decides which agent should handle it. The Orchestrator calls classify(_:history:agents:), gets back a ClassifierResult, and dispatches to selectedAgent — or falls back to the default agent when selectedAgent is nil.
Core types
Section titled “Core types”public struct ClassifierResult: Sendable { public let selectedAgent: (any AgentProtocol)? public let confidence: Double
public init(selectedAgent: (any AgentProtocol)?, confidence: Double)}
public protocol Classifier: Sendable { func classify( _ input: String, history: [ConversationMessage], agents: [any AgentProtocol] ) async throws -> ClassifierResult}ClassifierResult fields
Section titled “ClassifierResult fields”| Field | Type | Notes |
|---|---|---|
selectedAgent | (any AgentProtocol)? | The chosen agent, or nil when nothing matched. Always one of the agents passed to classify. |
confidence | Double | Nominally 0...1. Captured for tracing only. |
How routing works
Section titled “How routing works”- The Orchestrator fetches merged conversation history from storage.
- It calls
classifier.classify(_:history:agents:)with the user input, that history, and all registered agents. selectedAgentfrom the returnedClassifierResultis dispatched directly. No second lookup is performed — the agent instance must come from theagentsparameter.- When
selectedAgentisnil, the Orchestrator routes to the first registered agent (the default).
Skipping the classifier (nil path)
Section titled “Skipping the classifier (nil path)”Pass nil as the classifier when constructing the Orchestrator. Every turn goes straight to the first registered agent with no LLM call for routing.
let orchestrator = Orchestrator(classifier: nil, storage: storage)Built-in classifiers
Section titled “Built-in classifiers”| Classifier | Description |
|---|---|
LLMClassifier | Uses an LLMClient and a select_agent tool call to pick the best agent. The default when a classifier is needed. |
Next steps
Section titled “Next steps”- LLMClassifier — built-in LLM-based routing, init options, and custom instructions.
- Custom classifiers — implement the
Classifierprotocol to write your own routing logic.