Skip to content
中文

Model strategy: explicit selection and recommended budgets ​

Select from registered models and reasoning configurations, complete Core settings with local budget tiers, and keep per-field exact overrides.

createModelStrategy returns plain ModelRunnerOptions and can create a ModelRunner directly; definitions without request execution can also be bound directly to AgentCoreEngine. The model can be given directly or referred to by an ID in models. When an ID is passed, a missing model is an error; tools are not guessed from names, brands, or URLs.

The budget values small, medium, and large suit short tasks with few calls, ordinary multi-step tasks, and tasks that need more call headroom. They define local admission and output budgets and do not represent provider context capacity, real speed, or quality guarantees. small is 2 calls, 8000 input characters, 4000 output characters, 512 reserved output tokens, and a 15000ms per-call deadline; medium is 8, 32000, 16000, 1024, and 30000ms; large is 16, 64000, 32000, 4096, and 60000ms. Provider hard limits and the Core final checks still apply.

Priority from low to high: budget tier, selected model configuration, settings in explicit reasoningOptions, exact settings in the budget object, and top-level Core fields. Omitting budget uses medium. The budget object adds exact values on top of medium; an explicit undefined hands interpretation back to Core defaults, and valid 0 and Infinity are not treated as defaults.

reasoning is a name in reasoningOptions, such as low/high/off. Its content is an explicit Core model configuration override and can point to a Provider already built with provider reasoning parameters. Support does not infer how a provider enables thinking and does not assemble undeclared wire fields itself. A request is rejected when no declaration matches. Existing contracts for Provider, transport, token counter, sink, error port, and execution are preserved; App services are not deeply frozen.

Progressive examples for the same business case ​

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

Keep custom budgets and native Core ports effective ​

Extension · Node.js

The counter is for demonstration only. In production inject a counter that matches the actual model; do not use character estimates as real token counts.

ts
import { ModelRunner, Support } from '@jangts/agent-core';
const provider = { async *stream() { yield 'done'; } };
const transport = Support.createTextTransport({ id: 'app:text' });
const config = Support.createModelStrategy({ model: { provider, transports: [transport] },
  budget: { maxCalls: 3, maxInputChars: 24000, callTimeoutMs: 20000 },
  tokenBudget: { counterId: 'app-counter', contextWindowTokens: 4000,
    countTokens({ messages }) { return messages.reduce((sum, message) => sum + message.content.length, 0); } },
});
const result = await new ModelRunner(config).invoke({ input: 'hello', transport });
console.log(result.value);
js
import { ModelRunner, Support } from '@jangts/agent-core';
const provider = { async *stream() { yield 'done'; } };
const transport = Support.createTextTransport({ id: 'app:text' });
const config = Support.createModelStrategy({ model: { provider, transports: [transport] },
    budget: { maxCalls: 3, maxInputChars: 24000, callTimeoutMs: 20000 },
    tokenBudget: { counterId: 'app-counter', contextWindowTokens: 4000,
        countTokens({ messages }) { return messages.reduce((sum, message) => sum + message.content.length, 0); } },
});
const result = await new ModelRunner(config).invoke({ input: 'hello', transport });
console.log(result.value);

Policies & implementations ​

API reference, usage examples and developer guides.