ModelCallRequest
CORE · type · 类型合同
One model call request. The input shape selects prompt mode or message mode.
导入
ts
import type { ModelCallRequest } from '@jangts/agent-core/model';js
/** @typedef {import('@jangts/agent-core/model').ModelCallRequest} ModelCallRequest */其他公开入口:@jangts/agent-core、@jangts/agent-core/model、@jangts/agent-core/types、@jangts/agent-core/structs。
定义
类型: ModelCallRequest<Transport>
泛型参数
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
Transport | — | string |
联合分支结构
ModelCallRequest的可选结构: 选择其中一种结构,各分支的字段要求分别列出。
分支 1
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
logger | SubFlowLogger | undefined | 可省略 | 只读。Record this call in the supplied logger; omission adds no sub-flow record. |
signal | AbortSignal | undefined | 可省略 | 只读。Additional cancellation can shorten, never replace, the Runner lifetime. |
diagnostics | DiagnosticContext | undefined | 可省略 | 只读。Parent observation scope for this invocation; never changes execution budget or signal. |
prepared | PreparedModelCall<unknown> | undefined | 可省略 | 只读。Reuse a prepared call; its stage, transport and output reservation then take precedence. |
maxOutputTokens | number | undefined | 可省略 | 只读。见类型定义及调用场景。 |
stageId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
transport | Transport | undefined | 可省略 | 只读。见类型定义及调用场景。 |
input | string | 必需 | 见类型定义及调用场景。 |
instructions | string | undefined | 可省略 | 见类型定义及调用场景。 |
分支 2
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
logger | SubFlowLogger | undefined | 可省略 | 只读。Record this call in the supplied logger; omission adds no sub-flow record. |
signal | AbortSignal | undefined | 可省略 | 只读。Additional cancellation can shorten, never replace, the Runner lifetime. |
diagnostics | DiagnosticContext | undefined | 可省略 | 只读。Parent observation scope for this invocation; never changes execution budget or signal. |
prepared | PreparedModelCall<unknown> | undefined | 可省略 | 只读。Reuse a prepared call; its stage, transport and output reservation then take precedence. |
maxOutputTokens | number | undefined | 可省略 | 只读。见类型定义及调用场景。 |
stageId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
transport | Transport | undefined | 可省略 | 只读。见类型定义及调用场景。 |
input | readonly ModelMessage[] | BuiltContext | ContextPlan | 必需 | 见类型定义及调用场景。 |
instructions | undefined | 可省略 | 见类型定义及调用场景。 |
使用示例
- 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);