Skip to content
中文

ModelBudgetStrategy ​

SUPPORT · type · Type contract

Preset name, or an explicit partial set of Core runner settings.

Import ​

ts
import type { ModelBudgetStrategy } from '@jangts/agent-core/support';
js
/** @typedef {import('@jangts/agent-core/support').ModelBudgetStrategy} ModelBudgetStrategy */

Other public entry points:@jangts/agent-core/support, @jangts/agent-core/support/model.

Definition ​

Type: ModelBudgetStrategy

Type expression
ts
type ModelBudgetStrategy = keyof typeof modelBudgetStrategies | Partial<ModelRunnerSettings>;

Union branch structure ​

Optional shapes of ModelBudgetStrategy: choose one shape; required fields for each branch are listed separately.

Branch 1

"small"

Branch 2

"medium"

Branch 3

"large"

Branch 4
FieldTypeRequiredDescription
childrenModelChildPolicy | undefinedOptionalRead-only. See the type definition and usage context.
maxInputCharsnumber | undefinedOptionalCharacter budget for the assembled input.
maxSchemaCharsnumber | undefinedOptionalCharacter allowance for registered capability schemas.
tokenBudgetModelTokenBudget | undefinedOptionalSee the type definition and usage context.
maxOutputTokensnumber | undefinedOptionalDefault output reservation; invoke can override it for one call.
maxCallsnumber | undefinedOptionalCalls allowed for the whole request, including descendant runners' reservations.
callTimeoutMsnumber | undefinedOptionalDeadline for one provider call, in milliseconds.
maxOutputCharsnumber | undefinedOptionalCap on streamed output characters; exceeding it fails the call.
usageboolean | undefinedOptionalRequest and record provider usage for each call.

Examples ​

Use a small budget for a short task and keep the same Core construction as needs grow ​

Beginner · 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);

Refer to an existing model by ID and register the reasoning scheme explicitly ​

Configuration · Node.js

The example Providers are fully offline. Reasoning parameters for real providers are implemented through each Provider's explicit configuration.

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);

API reference, usage examples and developer guides.