ModelCallRecord
CORE · interface · Type contract
Receipt of a model call that returned successfully.
Import
ts
import type { ModelCallRecord } from '@jangts/agent-core';js
/** @typedef {import('@jangts/agent-core').ModelCallRecord} ModelCallRecord */Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/structs.
Definition
ts
interface ModelCallRecordExtends or implements: InvocationMetadata.
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
status | "success" | Required | Read-only. Records are only emitted for successful calls; failures are thrown instead. |
stageId | string | undefined | Optional | Read-only. Workflow stage that requested the call. |
modelId | string | undefined | Optional | Read-only. Configured model binding used for the call. |
callSequence | number | Required | Read-only. One-based position of the call within its runner's lifetime. |
usage | Readonly<ModelUsage> | undefined | Optional | Read-only. Provider-reported token usage; present only when the provider supplied it. |
runId | string | undefined | Optional | Read-only. Root run this invocation belongs to, when the host runs inside a diagnostics scope. |
spanId | string | undefined | Optional | Read-only. Diagnostics span of this invocation. |
parentSpanId | string | undefined | Optional | Read-only. Span that caused this invocation; absent for a root invocation. |
parentInvocationId | string | undefined | Optional | Read-only. Enclosing invocation when one call triggers another. |
invocationId | string | Required | Read-only. Opaque per-invocation id shared by receipt, events and diagnostic records. |
startedAtMs | number | Required | Read-only. Start instant in epoch milliseconds. |
durationMs | number | Required | Read-only. Elapsed milliseconds from start to completion. |
Examples
- ModelRunner: input can be shortened while the output contract stays the same: Execute one model interaction through the real Provider port and return a value plus the invocation for this call.
Two inputs for the same output
Beginner · 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);Add budget and request cancellation
Configuration · 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);