modelRunnerDefaults
CORE · constant · 运行时值
导入
ts
import { modelRunnerDefaults } from '@jangts/agent-core';js
import { modelRunnerDefaults } from '@jangts/agent-core';其他公开入口:@jangts/agent-core、@jangts/agent-core/types。
定义
ts
const modelRunnerDefaults: Readonly<{ maxCalls: 8; callTimeoutMs: 30000; maxInputChars: 32000; maxOutputChars: 16000; maxSchemaChars: 16000; maxOutputTokens: 1024; stage: "model"; children: Readonly<{ maxDepth: 1; maxConcurrentCalls: 1; maxChildren: 32; }>; }>字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
maxCalls | 8 | 必需 | 见类型定义及调用场景。 |
callTimeoutMs | 30000 | 必需 | 见类型定义及调用场景。 |
maxInputChars | 32000 | 必需 | 见类型定义及调用场景。 |
maxOutputChars | 16000 | 必需 | 见类型定义及调用场景。 |
maxSchemaChars | 16000 | 必需 | 见类型定义及调用场景。 |
maxOutputTokens | 1024 | 必需 | 见类型定义及调用场景。 |
stage | "model" | 必需 | 见类型定义及调用场景。 |
children | Readonly<{ maxDepth: 1; maxConcurrentCalls: 1; maxChildren: 32; }> | 必需 | 见类型定义及调用场景。 |
使用示例
- ModelRunner:输入可以省写,输出合同保持一致:用真实 Provider 端口执行一次模型交互,返回 value 和本次 invocation。
同一输出的两种输入
入门 · Node.js
ts
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
async *stream(messages: readonly { content: string }[]) {
yield '收到:' + messages.at(-1)!.content;
},
};
const runner = new ModelRunner({ provider });
const first = await runner.invoke('你好');
const second = await runner.invoke({ input: '你好' });
console.log(first.value, second.value);
console.log(first.invocation.invocationId);js
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
async *stream(messages) {
yield '收到:' + messages.at(-1).content;
},
};
const runner = new ModelRunner({ provider });
const first = await runner.invoke('你好');
const second = await runner.invoke({ input: '你好' });
console.log(first.value, second.value);
console.log(first.invocation.invocationId);增加预算与请求取消
配置 · Node.js
ts
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
async *stream(messages: readonly { content: string }[]) {
yield '收到:' + messages.at(-1)!.content;
},
};
const runner = new ModelRunner({ provider, maxCalls: 2, maxInputChars: 4000,
maxOutputChars: 2000, callTimeoutMs: 15000,
execution: { signal: AbortSignal.timeout(20000) },
});
const result = await runner.invoke({ input: '你好', stageId: 'reply', maxOutputTokens: 600 });
console.log(result.value, runner.remainingCalls);js
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
async *stream(messages) {
yield '收到:' + messages.at(-1).content;
},
};
const runner = new ModelRunner({ provider, maxCalls: 2, maxInputChars: 4000,
maxOutputChars: 2000, callTimeoutMs: 15000,
execution: { signal: AbortSignal.timeout(20000) },
});
const result = await runner.invoke({ input: '你好', stageId: 'reply', maxOutputTokens: 600 });
console.log(result.value, runner.remainingCalls);增加独立的有序输出接收器
扩展 · Node.js
sink.output 按序等待。model.output 是尚未完整校验的提议,不能在此执行模型提出的工具操作。
ts
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
async *stream(messages: readonly { content: string }[]) {
yield '收到:' + messages.at(-1)!.content;
},
};
const events: string[] = [];
const runner = new ModelRunner({ provider, sink: {
async output(event) { events.push(event.type); },
} });
const result = await runner.invoke('你好');
console.log(result.value, events);js
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
async *stream(messages) {
yield '收到:' + messages.at(-1).content;
},
};
const events = [];
const runner = new ModelRunner({ provider, sink: {
async output(event) { events.push(event.type); },
} });
const result = await runner.invoke('你好');
console.log(result.value, events);