Skip to content

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.

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 })
new ClassifierStrategy(model, options?): ClassifierStrategy;

Defined in: src/models/routing/classifier-strategy.ts:156

Create a classifier strategy.

ParameterTypeDescription
model| Model<BaseModelConfig> | DecisionModelModel 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?ClassifierStrategyOptionsRouting policy, timeout, and character budgets

ClassifierStrategy

TypeError if model is not a Model or DecisionModel

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

select(context): Promise<RoutingCandidate>;

Defined in: src/models/routing/classifier-strategy.ts:181

Select one opening candidate, declining on a decision failure.

ParameterTypeDescription
contextRoutingContextCurrent request and chronological routing history

Promise<RoutingCandidate>

The chosen candidate, or undefined to decline

Error if the candidates’ serialized evidence exceeds maxCandidateChars; this misconfiguration is permanent, so it propagates instead of declining

RoutingStrategy.select