Skip to content
English

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';
js
/** @typedef {import('@jangts/agent-core/support').ModelStrategyOptions} ModelStrategyOptions */

其他公开入口:@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;
};

泛型参数 ​

类型参数约束默认类型
Transportsreadonly ModelTransportDefinition[]readonly ModelTransportDefinition[]
Execution—ExecutionOptions

字段结构 ​

字段类型必需说明
maxOutputTokensnumber | undefined可省略Default output reservation; invoke can override it for one call.
maxCallsnumber | undefined可省略Calls allowed for the whole request, including descendant runners' reservations.
callTimeoutMsnumber | undefined可省略Deadline for one provider call, in milliseconds.
maxOutputCharsnumber | undefined可省略Cap on streamed output characters; exceeding it fails the call.
usageboolean | undefined可省略Request and record provider usage for each call.
childrenModelChildPolicy | undefined可省略只读。见类型定义及调用场景。
maxInputCharsnumber | undefined可省略Character budget for the assembled input.
maxSchemaCharsnumber | undefined可省略Character allowance for registered capability schemas.
tokenBudgetModelTokenBudget | undefined可省略见类型定义及调用场景。
providerChatProvider | undefined可省略见类型定义及调用场景。
transportsTransports | undefined可省略见类型定义及调用场景。
sink{ output?: ModelRunnerPorts["onOutput"]; } | undefined可省略见类型定义及调用场景。
errors{ inputBudget?: ModelRunnerPorts["inputBudgetError"]; outputBudget?: ModelRunnerPorts["outputBudgetError"]; } | undefined可省略见类型定义及调用场景。
executionExecution | undefined可省略见类型定义及调用场景。
modelstring | StrategyModel<Transports, Execution>必需只读。An existing definition, or an ID in the explicitly supplied model catalog.
modelsReadonly<Record<string, StrategyModel<Transports, Execution>>> | undefined可省略只读。Named model definitions; required when model is a string ID.
reasoningstring | undefined可省略只读。Names and supplier-specific implementations are declared by the App, never guessed.
reasoningOptionsReadonly<Record<string, Partial<StrategyModel<Transports, Execution>>>> | undefined可省略只读。Per-reasoning overrides; entries are applied only when reasoning names them.
budgetModelBudgetStrategy | undefined可省略只读。Preset name, or an explicit partial budget; defaults to medium.

使用示例 ​

短任务使用小预算,增加需求仍沿用同一 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);
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);

已有模型用 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);
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);

相关策略源码 ​

相关定义 ​

接口参考、使用示例与开发指南。