InvocationMetadata
CORE · interface · Type contract
Identity and timing shared by every invocation receipt.
Import
ts
import type { InvocationMetadata } from '@jangts/agent-core';1
js
/** @typedef {import('@jangts/agent-core').InvocationMetadata} InvocationMetadata */1
Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/structs.
Definition
ts
interface InvocationMetadata1
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
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
- ContextJournal: the in-request projection of receipts: Turn real call receipts into in-request records usable in later context, without starting another persistent logging system.
- 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.
- Real tool invocation and in-request runtime: Core registers and executes real tools and returns receipts carrying an invocation; business authorization is owned by the implementation registered by the App.
Read the model receipt already recorded by the Runner
Beginner · Node.js
ts
import { ModelRunner } from '@jangts/agent-core';
const runner = new ModelRunner({ provider: { async *stream() { yield '服务运行正常'; } } });
const result = await runner.invoke('查询服务状态');
console.log(result.invocation.invocationId);
console.log(runner.journal.snapshot());1
2
3
4
5
2
3
4
5
js
import { ModelRunner } from '@jangts/agent-core';
const runner = new ModelRunner({ provider: { async *stream() { yield '服务运行正常'; } } });
const result = await runner.invoke('查询服务状态');
console.log(result.invocation.invocationId);
console.log(runner.journal.snapshot());1
2
3
4
5
2
3
4
5
An App adapter records the local tool it actually executes
Configuration · Node.js
ts
import { ContextJournal } from '@jangts/agent-core/journal';
const journal = new ContextJournal();
const invocationId = journal.beginTool({ toolId: 'get_status', input: {} });
// 此处由 App 实际执行本地读取;不是模型提供的回执。
const status = '服务运行正常';
journal.finishTool({ invocationId, status: 'success', value: status });
console.log(journal.snapshot());1
2
3
4
5
6
7
2
3
4
5
6
7
js
import { ContextJournal } from '@jangts/agent-core/journal';
const journal = new ContextJournal();
const invocationId = journal.beginTool({ toolId: 'get_status', input: {} });
// 此处由 App 实际执行本地读取;不是模型提供的回执。
const status = '服务运行正常';
journal.finishTool({ invocationId, status: 'success', value: status });
console.log(journal.snapshot());1
2
3
4
5
6
7
2
3
4
5
6
7