Skip to content
English

ContextJournal ​

CORE · class · 运行时值

Request-local context projection of execution receipts; not a separate persistent log store.

导入 ​

ts
import { ContextJournal } from '@jangts/agent-core/context';
js
import { ContextJournal } from '@jangts/agent-core/context';

其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/context、@jangts/agent-core/journal。

定义 ​

ts
class ContextJournal

继承或实现: ToolJournal。

构造函数 ​

ts
new ContextJournal(): ContextJournal

无调用参数。

返回: ContextJournal。

成员目录 ​

成员用途
modelRecord one model-produced value.
beginToolOpen a tool call.
finishToolClose an open tool call with its outcome.
snapshot完整输入输出见下方重载。

成员详情 ​

model ​

实例方法。

Record one model-produced value.

ts
model({ stageId, value, invocation, }: { stageId: string; value: unknown; invocation: InvocationMetadata; }): void

Record one model-produced value.

参数类型传递说明
__0{ stageId: string; value: unknown; invocation: InvocationMetadata; }必需—
__0 的字段
字段类型必需说明
stageIdstring必需见类型定义及调用场景。
valueunknown必需见类型定义及调用场景。
invocationInvocationMetadata必需见类型定义及调用场景。

返回: void。

beginTool ​

实例方法。

Open a tool call.

ts
beginTool({ toolId, input, invocation }: ToolJournalStart): string

Open a tool call.

参数类型传递说明
__0ToolJournalStart必需—
__0 的字段
字段类型必需说明
toolIdstring必需Tool being invoked.
inputunknown必需Parsed input; stored as-is so the host can build its own domain record.
invocationPartial<InvocationMetadata> | undefined可省略What the caller already knows. The journal fills gaps and generates an id when absent.

返回: string。

finishTool ​

实例方法。

Close an open tool call with its outcome.

ts
finishTool({ invocationId, status, value }: ToolJournalFinish): void

Close an open tool call with its outcome.

参数类型传递说明
__0ToolJournalFinish必需—
__0 的字段
字段类型必需说明
invocationIdstring必需Invocation opened by beginTool.
status"error" | "success" | "cancelled"必需Terminal status; cancelled is distinct from error.
valueunknown必需Produced value on success; failure detail on error; ignored for cancellation.

返回: void。

snapshot ​

实例方法。

ts
snapshot(): readonly ContextRecord[]

无调用参数。

返回: readonly ContextRecord[]。

使用示例 ​

读取 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());
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());

应用适配器记录它实际执行的本地工具 ​

配置 · 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());
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());

相关定义 ​

接口参考、使用示例与开发指南。