ClassifierStrategy
Defined in: src/models/routing/classifier-strategy.ts:140
Choose a candidate by applying a configurable routing policy with a classifier model.
The classifier is asked one closed question that carries the SDK’s fixed routing rules followed by the routing policy. A DecisionModel, such as a System One provider, can be passed in place of a model.
Each candidate is offered under a positional key (c0, c1, …); names, descriptions, and metadata
travel only as evidence in the routing context, so optional or arbitrary names never become answer
values. The routing context is a bounded projection of the latest request, the parent agent’s textual
instructions, and candidate evidence; it crosses the classifier provider boundary and must not contain
secrets.
Selection runs only before the first model call. A single candidate is returned without asking. The classifier must commit to a key. Classification failures, unknown keys, and timeouts warn and decline selection, so ModelRouter serves candidate zero. After an attempt this strategy declines, so a failure of the selected candidate surfaces without switching. Nested routers are treated as opaque candidates using only their wrapper evidence.
Example
Section titled “Example”const router = new ModelRouter( [ new RoutingCandidate({ model: fast, name: 'routine', description: 'Short factual requests' }), new RoutingCandidate({ model: strong, name: 'complex', description: 'Multi-step design work' }), ], { strategy: new ClassifierStrategy(classifierModel) })const agent = new Agent({ model: router })Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ClassifierStrategy(model, options?): ClassifierStrategy;Defined in: src/models/routing/classifier-strategy.ts:156
Create a classifier strategy.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
model | | Model<BaseModelConfig> | DecisionModel | Model or DecisionModel used for classification; a Model must honor forced tool selection (toolChoice), since a provider that ignores it fails classification and every selection falls back to candidate zero |
options? | ClassifierStrategyOptions | Routing policy, timeout, and character budgets |
Returns
Section titled “Returns”ClassifierStrategy
Throws
Section titled “Throws”TypeError if model is not a Model or DecisionModel
Throws
Section titled “Throws”Error if both routingPolicy and systemPrompt are set, timeoutMs is not finite, greater than zero, and at most 2147483647, or a character limit is not a positive integer
Methods
Section titled “Methods”select()
Section titled “select()”select(context): Promise<RoutingCandidate>;Defined in: src/models/routing/classifier-strategy.ts:181
Select one opening candidate, declining on a decision failure.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
context | RoutingContext | Current request and chronological routing history |
Returns
Section titled “Returns”Promise<RoutingCandidate>
The chosen candidate, or undefined to decline
Throws
Section titled “Throws”Error if the candidates’ serialized evidence exceeds maxCandidateChars; this misconfiguration is permanent, so it propagates instead of declining