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.
Example
Section titled “Example”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 })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:121
Create a classifier strategy.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
model | Model | Model 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 |
options | ClassifierStrategyOptions | Routing policy, timeout, and character budgets |
Returns
Section titled “Returns”ClassifierStrategy
Throws
Section titled “Throws”TypeError if model is not a Model
Throws
Section titled “Throws”Error if timeoutMs is not finite and greater than zero 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:152
Select one opening candidate, declining on classification or serving-time failure.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
context | RoutingContext | Current request and chronological routing history |
Returns
Section titled “Returns”Promise<RoutingCandidate>
The classified 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