Skip to content
中文

modelBudgetStrategies ​

SUPPORT · constant · Runtime value

Import ​

ts
import { modelBudgetStrategies } from '@jangts/agent-core/support';
js
import { modelBudgetStrategies } from '@jangts/agent-core/support';

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

Definition ​

ts
const modelBudgetStrategies: Readonly<{ small: Readonly<{ maxCalls: 2; maxInputChars: 8000; maxOutputChars: 4000; maxOutputTokens: 512; callTimeoutMs: 15000; }>; medium: Readonly<{ maxCalls: 8; maxInputChars: 32000; maxOutputChars: 16000; maxOutputTokens: 1024; callTimeoutMs: 30000; }>; large: Readonly<{ maxCalls: 16; maxInputChars: 64000; maxOutputChars: 32000; maxOutputTokens: 4096; callTimeoutMs: 60000; }>; }>

Field structure ​

FieldTypeRequiredDescription
smallReadonly<{ maxCalls: 2; maxInputChars: 8000; maxOutputChars: 4000; maxOutputTokens: 512; callTimeoutMs: 15000; }>RequiredSee the type definition and usage context.
mediumReadonly<{ maxCalls: 8; maxInputChars: 32000; maxOutputChars: 16000; maxOutputTokens: 1024; callTimeoutMs: 30000; }>RequiredSee the type definition and usage context.
largeReadonly<{ maxCalls: 16; maxInputChars: 64000; maxOutputChars: 32000; maxOutputTokens: 4096; callTimeoutMs: 60000; }>RequiredSee the type definition and usage context.

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

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

API reference, usage examples and developer guides.