ModelCallTrace
CORE · interface · Type contract
Accumulated facts of one model call, reported on success and on failure.
Import
ts
import type { ModelCallTrace } from '@jangts/agent-core/model';js
/** @typedef {import('@jangts/agent-core/model').ModelCallTrace} ModelCallTrace */Other public entry points:@jangts/agent-core, @jangts/agent-core/model, @jangts/agent-core/types, @jangts/agent-core/structs.
Definition
ts
interface ModelCallTraceExtends or implements: InvocationMetadata.
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
callSequence | number | Required | One-based position of the call within its runner's lifetime. |
stageId | string | Required | See the type definition and usage context. |
modelId | string | undefined | Optional | Model binding used for the call, when one was configured. |
inputChars | number | Required | Counted input characters (messages, instruction and schemas). |
inputTokens | number | undefined | Optional | Measured input tokens; present only with an explicit token counter. |
inputTokenLimit | number | undefined | Optional | Token ceiling the measurement was compared against. |
outputChars | number | Required | Characters received from the provider. |
firstOutputMs | number | null | undefined | Optional | Time to first streamed part in milliseconds; null until a part arrived. |
outputDurationMs | number | undefined | Optional | Milliseconds from the first part to the end of the stream. |
status | InvocationStatus | Required | See the type definition and usage context. |
codes | string[] | Required | Error or protocol codes observed during the call, in occurrence order. |
usage | ModelUsage | undefined | Optional | See the type definition and usage context. |
functionCall | { id: string; name: string; argumentChars: number; } | undefined | Optional | Selected function call, when the response produced one. |
calls | readonly { id: string; name: string; argumentChars: number; toolId?: string; }[] | undefined | Optional | All calls produced by a session response; omitted for single-selection transports. |
context | { fragmentUsage: ContextFragmentUsage[]; stablePrefixChars: number; } | undefined | Optional | Context accounting: per-fragment usage and characters shared with the previous call. |
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
- Process observation and node reports: The App subscribes to Core execution facts; nodes report their own usedModel and use an instance sub-logger to record intent first and then results, while the Loop owns identity and logging.
- 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.
- Actual request measurement and same-call preparation snapshot: Use prepare only when context must be handled ahead of time; multiple measurements and the final send reuse the same transport preparation.
- Child execution: isolated records, shared ancestor quota: A child Runner does not inherit conversation or the output receiver, but cannot bypass parent budget, cancellation, or deadlines.
Observe the nodes and model events a task passes through
Beginner · Node.js
ts
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
type State = { name: string; answer?: string };
const workflow = defineWorkflow<State, string>({
id: 'greeting',
nodes: [{
id: 'greet', description: '根据本次姓名生成问候', startsRound: true,
run: state => ({ answer: '你好,' + state.name }),
routes: [route.deliver('answer')],
}],
});
const agent = new AgentCoreEngine({ workflow, execution: {
observe: { event(event) { console.log(event.type, event.eventId); } },
} });
console.log(await agent.run({ name: 'Ivan' }));js
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
const workflow = defineWorkflow({
id: 'greeting',
nodes: [{
id: 'greet', description: '根据本次姓名生成问候', startsRound: true,
run: state => ({ answer: '你好,' + state.name }),
routes: [route.deliver('answer')],
}],
});
const agent = new AgentCoreEngine({ workflow, execution: {
observe: { event(event) { console.log(event.type, event.eventId); } },
} });
console.log(await agent.run({ name: 'Ivan' }));Report a business stage while the node executes
Configuration · Node.js
The node only reports facts it knows; Core owns node identity and execution association.
ts
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
type State = { name: string; answer?: string };
const workflow = defineWorkflow<State, string>({ id: 'greeting', nodes: [{
id: 'greet', description: '生成问候', startsRound: true,
run(state, context) {
context.report({ payload: { phase: 'formatting' } });
return { answer: '你好,' + state.name };
}, routes: [route.deliver('answer')],
}] });
const agent = new AgentCoreEngine({ workflow, execution: {
observe: { event(event) { console.log(event.type); } },
} });
console.log(await agent.run({ name: 'Ivan' }));js
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
const workflow = defineWorkflow({ id: 'greeting', nodes: [{
id: 'greet', description: '生成问候', startsRound: true,
run(state, context) {
context.report({ payload: { phase: 'formatting' } });
return { answer: '你好,' + state.name };
}, routes: [route.deliver('answer')],
}] });
const agent = new AgentCoreEngine({ workflow, execution: {
observe: { event(event) { console.log(event.type); } },
} });
console.log(await agent.run({ name: 'Ivan' }));Related policy source
- Shared execution fact source and consumption isolation
- Sub-step statuses and their progression
- Core default budget values
- Same-call preparation and real input measurement