InvocationMetadata
CORE · interface · 类型合同
Identity and timing shared by every invocation receipt.
导入
ts
import type { InvocationMetadata } from '@jangts/agent-core';1
js
/** @typedef {import('@jangts/agent-core').InvocationMetadata} InvocationMetadata */1
其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/structs。
定义
ts
interface InvocationMetadata1
字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
runId | string | undefined | 可省略 | 只读。Root run this invocation belongs to, when the host runs inside a diagnostics scope. |
spanId | string | undefined | 可省略 | 只读。Diagnostics span of this invocation. |
parentSpanId | string | undefined | 可省略 | 只读。Span that caused this invocation; absent for a root invocation. |
parentInvocationId | string | undefined | 可省略 | 只读。Enclosing invocation when one call triggers another. |
invocationId | string | 必需 | 只读。Opaque per-invocation id shared by receipt, events and diagnostic records. |
startedAtMs | number | 必需 | 只读。Start instant in epoch milliseconds. |
durationMs | number | 必需 | 只读。Elapsed milliseconds from start to completion. |
使用示例
- ContextJournal:回执的请求内投影:将真实调用回执变成可用于后续上下文的请求内记录,不另起持久日志系统。
- ModelRunner:输入可以省写,输出合同保持一致:用真实 Provider 端口执行一次模型交互,返回 value 和本次 invocation。
- 真实工具调用与请求内运行时:Core 注册并执行真实工具,返回带 invocation 的回执;业务授权由 App 注册的实现拥有。
读取 Runner 已记录的模型回执
入门 · 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
应用适配器记录它实际执行的本地工具
配置 · 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