Skip to content
中文

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 ModelCallTrace

Extends or implements: InvocationMetadata.

Field structure ​

FieldTypeRequiredDescription
callSequencenumberRequiredOne-based position of the call within its runner's lifetime.
stageIdstringRequiredSee the type definition and usage context.
modelIdstring | undefinedOptionalModel binding used for the call, when one was configured.
inputCharsnumberRequiredCounted input characters (messages, instruction and schemas).
inputTokensnumber | undefinedOptionalMeasured input tokens; present only with an explicit token counter.
inputTokenLimitnumber | undefinedOptionalToken ceiling the measurement was compared against.
outputCharsnumberRequiredCharacters received from the provider.
firstOutputMsnumber | null | undefinedOptionalTime to first streamed part in milliseconds; null until a part arrived.
outputDurationMsnumber | undefinedOptionalMilliseconds from the first part to the end of the stream.
statusInvocationStatusRequiredSee the type definition and usage context.
codesstring[]RequiredError or protocol codes observed during the call, in occurrence order.
usageModelUsage | undefinedOptionalSee the type definition and usage context.
functionCall{ id: string; name: string; argumentChars: number; } | undefinedOptionalSelected function call, when the response produced one.
callsreadonly { id: string; name: string; argumentChars: number; toolId?: string; }[] | undefinedOptionalAll calls produced by a session response; omitted for single-selection transports.
context{ fragmentUsage: ContextFragmentUsage[]; stablePrefixChars: number; } | undefinedOptionalContext accounting: per-fragment usage and characters shared with the previous call.
runIdstring | undefinedOptionalRead-only. Root run this invocation belongs to, when the host runs inside a diagnostics scope.
spanIdstring | undefinedOptionalRead-only. Diagnostics span of this invocation.
parentSpanIdstring | undefinedOptionalRead-only. Span that caused this invocation; absent for a root invocation.
parentInvocationIdstring | undefinedOptionalRead-only. Enclosing invocation when one call triggers another.
invocationIdstringRequiredRead-only. Opaque per-invocation id shared by receipt, events and diagnostic records.
startedAtMsnumberRequiredRead-only. Start instant in epoch milliseconds.
durationMsnumberRequiredRead-only. Elapsed milliseconds from start to completion.

Examples ​

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' }));

API reference, usage examples and developer guides.