ModelStrategyOptions
SUPPORT · type · 类型合同
Input of createModelStrategy: model selection, optional reasoning and budget plus explicit Core overrides. Explicit Core fields win over every generated value.
导入
ts
import type { ModelStrategyOptions } from '@jangts/agent-core/support';1
js
/** @typedef {import('@jangts/agent-core/support').ModelStrategyOptions} ModelStrategyOptions */1
其他公开入口:@jangts/agent-core/support、@jangts/agent-core/support/model。
定义
类型: ModelStrategyOptions<Transports, Execution>
类型表达式
ts
type ModelStrategyOptions<Transports extends readonly ModelTransportDefinition[] = readonly ModelTransportDefinition[], Execution = ExecutionOptions> = Partial<StrategyModel<Transports, Execution>> & {
/** An existing definition, or an ID in the explicitly supplied model catalog. */
readonly model: StrategyModel<Transports, Execution> | string;
/** Named model definitions; required when `model` is a string ID. */
readonly models?: Readonly<Record<string, StrategyModel<Transports, Execution>>>;
/** Names and supplier-specific implementations are declared by the App, never guessed. */
readonly reasoning?: string;
/** Per-reasoning overrides; entries are applied only when `reasoning` names them. */
readonly reasoningOptions?: Readonly<
Record<string, Partial<StrategyModel<Transports, Execution>>>
>;
/** Preset name, or an explicit partial budget; defaults to `medium`. */
readonly budget?: ModelBudgetStrategy;
};1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
泛型参数
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
Transports | readonly ModelTransportDefinition[] | readonly ModelTransportDefinition[] |
Execution | — | ExecutionOptions |
字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
maxOutputTokens | number | undefined | 可省略 | Default output reservation; invoke can override it for one call. |
maxCalls | number | undefined | 可省略 | Calls allowed for the whole request, including descendant runners' reservations. |
callTimeoutMs | number | undefined | 可省略 | Deadline for one provider call, in milliseconds. |
maxOutputChars | number | undefined | 可省略 | Cap on streamed output characters; exceeding it fails the call. |
usage | boolean | undefined | 可省略 | Request and record provider usage for each call. |
children | ModelChildPolicy | undefined | 可省略 | 只读。见类型定义及调用场景。 |
maxInputChars | number | undefined | 可省略 | Character budget for the assembled input. |
maxSchemaChars | number | undefined | 可省略 | Character allowance for registered capability schemas. |
tokenBudget | ModelTokenBudget | undefined | 可省略 | 见类型定义及调用场景。 |
provider | ChatProvider | undefined | 可省略 | 见类型定义及调用场景。 |
transports | Transports | undefined | 可省略 | 见类型定义及调用场景。 |
sink | { output?: ModelRunnerPorts["onOutput"]; } | undefined | 可省略 | 见类型定义及调用场景。 |
errors | { inputBudget?: ModelRunnerPorts["inputBudgetError"]; outputBudget?: ModelRunnerPorts["outputBudgetError"]; } | undefined | 可省略 | 见类型定义及调用场景。 |
execution | Execution | undefined | 可省略 | 见类型定义及调用场景。 |
model | string | StrategyModel<Transports, Execution> | 必需 | 只读。An existing definition, or an ID in the explicitly supplied model catalog. |
models | Readonly<Record<string, StrategyModel<Transports, Execution>>> | undefined | 可省略 | 只读。Named model definitions; required when model is a string ID. |
reasoning | string | undefined | 可省略 | 只读。Names and supplier-specific implementations are declared by the App, never guessed. |
reasoningOptions | Readonly<Record<string, Partial<StrategyModel<Transports, Execution>>>> | undefined | 可省略 | 只读。Per-reasoning overrides; entries are applied only when reasoning names them. |
budget | ModelBudgetStrategy | undefined | 可省略 | 只读。Preset name, or an explicit partial budget; defaults to medium. |
使用示例
- 模型策略:显式选择与推荐预算:从已登记的模型和推理配置中选择,以本地预算档位补全 Core 设置,并保留逐字段精确覆盖。
短任务使用小预算,增加需求仍沿用同一 Core 构造
入门 · Node.js
ts
import { AgentCoreEngine, ModelRunner, Support } from '@jangts/agent-core';
const provider = { async *stream() { yield '服务在线。'; } };
const config = Support.createModelStrategy({ model: { provider }, budget: 'small' });
const model = new ModelRunner(config);
console.log((await model.invoke('服务状态?')).value);
const agent = new AgentCoreEngine({ model: config });
console.log(agent.branch.agentId);1
2
3
4
5
6
7
2
3
4
5
6
7
js
import { AgentCoreEngine, ModelRunner, Support } from '@jangts/agent-core';
const provider = { async *stream() { yield '服务在线。'; } };
const config = Support.createModelStrategy({ model: { provider }, budget: 'small' });
const model = new ModelRunner(config);
console.log((await model.invoke('服务状态?')).value);
const agent = new AgentCoreEngine({ model: config });
console.log(agent.branch.agentId);1
2
3
4
5
6
7
2
3
4
5
6
7
已有模型用 ID 代指,推理方案显式登记
配置 · Node.js
示例 Provider 完全离线。实际供应商的推理参数由各 Provider 的显式配置实现。
ts
import { ModelRunner, Support } from '@jangts/agent-core';
const fast = { async *stream() { yield '简短回答'; } };
const reasoned = { async *stream() { yield '经过复核的回答'; } };
const models = { fast: { provider: fast }, thorough: { provider: reasoned } };
const config = Support.createModelStrategy({ model: 'fast', models, budget: 'small',
reasoning: 'high', reasoningOptions: { high: { provider: reasoned } },
maxCalls: 1, maxOutputTokens: 1200,
});
console.log((await new ModelRunner(config).invoke('检查资料')).value);1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
js
import { ModelRunner, Support } from '@jangts/agent-core';
const fast = { async *stream() { yield '简短回答'; } };
const reasoned = { async *stream() { yield '经过复核的回答'; } };
const models = { fast: { provider: fast }, thorough: { provider: reasoned } };
const config = Support.createModelStrategy({ model: 'fast', models, budget: 'small',
reasoning: 'high', reasoningOptions: { high: { provider: reasoned } },
maxCalls: 1, maxOutputTokens: 1200,
});
console.log((await new ModelRunner(config).invoke('检查资料')).value);1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9