ModelRouter
Defined in: src/models/routing/router.ts:117
Routes each agent invocation among an immutable set of candidate models.
The default FallbackStrategy prefers the candidate with the fewest recorded failures and
breaks ties by declaration order. maxSwitches bounds successful candidate changes per invocation.
Example
Section titled “Example”const router = new ModelRouter([ new RoutingCandidate({ model: primary, name: 'primary' }), new RoutingCandidate({ model: fallback, name: 'fallback' }),])const agent = new Agent({ model: router })Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ModelRouter(models, options?): ModelRouter;Defined in: src/models/routing/router.ts:133
Create a model router.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
models | readonly CandidateInput[] | Candidate models, nested routers, or candidate wrappers |
options | ModelRouterOptions | Routing strategy and switch cap |
Returns
Section titled “Returns”ModelRouter
Throws
Section titled “Throws”TypeError if models or the strategy are invalid
Throws
Section titled “Throws”Error if candidates are empty, duplicated, named alike, stateful, or maxSwitches is not a non-negative integer
Properties
Section titled “Properties”readonly name: "strands:model-router" = 'strands:model-router';Defined in: src/models/routing/router.ts:118
A stable string identifier for the plugin. Used for logging, duplicate detection, and plugin management.
For strands-vended plugins, names should be prefixed with strands:.
Implementation of
Section titled “Implementation of”Accessors
Section titled “Accessors”candidates
Section titled “candidates”Get Signature
Section titled “Get Signature”get candidates(): readonly RoutingCandidate[];Defined in: src/models/routing/router.ts:152
Normalized candidates in declaration order.
Returns
Section titled “Returns”readonly RoutingCandidate[]
defaultModel
Section titled “defaultModel”Get Signature
Section titled “Get Signature”get defaultModel(): Model;Defined in: src/models/routing/router.ts:157
First declared candidate resolved without consulting a strategy.
Returns
Section titled “Returns”Methods
Section titled “Methods”initAgent()
Section titled “initAgent()”initAgent(agent): void;Defined in: src/models/routing/router.ts:179
Register routing middleware and lifecycle hooks.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
agent | LocalAgent | Agent using this router as its model |
Returns
Section titled “Returns”void
Throws
Section titled “Throws”Error if attached as an ordinary plugin rather than as the model