Skip to content

ClassifierStrategy

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

Choose a candidate by applying a configurable policy with a classifier model.

Classification adds one call to the explicitly configured model. Candidate declaration order does not inform classification. Candidate names, descriptions, metadata, the latest request, and textual parent-agent instructions may cross the classifier provider boundary and must not contain secrets. Structured parent-system-prompt blocks such as cache points are omitted because the classifier receives rebuilt, bounded context rather than the original prompt.

Classification failures warn and decline selection, so ModelRouter serves candidate zero. If the selected candidate later fails, this strategy declines further selection and lets the original model error surface without switching. Nested routers are treated as opaque candidates using only their wrapper evidence.

const router = new ModelRouter(
[
new RoutingCandidate({ model: fast, name: 'routine', metadata: { supportsToolUse: true } }),
new RoutingCandidate({ model: strong, name: 'complex' }),
],
{ strategy: new ClassifierStrategy(classifierModel) }
)
const agent = new Agent({ model: router })
new ClassifierStrategy(model, options?): ClassifierStrategy;

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

Create a classifier strategy.

ParameterTypeDescription
modelModelModel used for classification; it must honor forced tool selection (toolChoice), since a provider that ignores it fails classification silently and every selection falls back to candidate zero
optionsClassifierStrategyOptionsRouting policy, timeout, and character budgets

ClassifierStrategy

TypeError if model is not a Model

Error if timeoutMs is not finite and greater than zero or a character limit is not a positive integer

select(context): Promise<RoutingCandidate>;

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

Select one opening candidate, declining on classification or serving-time failure.

ParameterTypeDescription
contextRoutingContextCurrent request and chronological routing history

Promise<RoutingCandidate>

The classified 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