Skip to content
English

ModelCallRecord ​

CORE · interface · 类型合同

Receipt of a model call that returned successfully.

导入 ​

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

其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/structs。

定义 ​

ts
interface ModelCallRecord

继承或实现: InvocationMetadata。

字段结构 ​

字段类型必需说明
status"success"必需只读。Records are only emitted for successful calls; failures are thrown instead.
stageIdstring | undefined可省略只读。Workflow stage that requested the call.
modelIdstring | undefined可省略只读。Configured model binding used for the call.
callSequencenumber必需只读。One-based position of the call within its runner's lifetime.
usageReadonly<ModelUsage> | undefined可省略只读。Provider-reported token usage; present only when the provider supplied it.
runIdstring | undefined可省略只读。Root run this invocation belongs to, when the host runs inside a diagnostics scope.
spanIdstring | undefined可省略只读。Diagnostics span of this invocation.
parentSpanIdstring | undefined可省略只读。Span that caused this invocation; absent for a root invocation.
parentInvocationIdstring | undefined可省略只读。Enclosing invocation when one call triggers another.
invocationIdstring必需只读。Opaque per-invocation id shared by receipt, events and diagnostic records.
startedAtMsnumber必需只读。Start instant in epoch milliseconds.
durationMsnumber必需只读。Elapsed milliseconds from start to completion.

使用示例 ​

同一输出的两种输入 ​

入门 · 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);

相关策略源码 ​

相关定义 ​

接口参考、使用示例与开发指南。