Skip to content
中文

ContextJournal ​

CORE · class · Runtime value

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

Import ​

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

Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/context, @jangts/agent-core/journal.

Definition ​

ts
class ContextJournal

Extends or implements: ToolJournal.

Constructor ​

ts
new ContextJournal(): ContextJournal

No call parameters.

Returns: ContextJournal.

Member index ​

MemberPurpose
modelRecord one model-produced value.
beginToolOpen a tool call.
finishToolClose an open tool call with its outcome.
snapshotSee the overload below for full inputs and outputs.

Member details ​

model ​

Instance method.

Record one model-produced value.

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

Record one model-produced value.

ParameterTypePassingDescription
__0{ stageId: string; value: unknown; invocation: InvocationMetadata; }Required—
Fields of __0
FieldTypeRequiredDescription
stageIdstringRequiredSee the type definition and usage context.
valueunknownRequiredSee the type definition and usage context.
invocationInvocationMetadataRequiredSee the type definition and usage context.

Returns: void.

beginTool ​

Instance method.

Open a tool call.

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

Open a tool call.

ParameterTypePassingDescription
__0ToolJournalStartRequired—
Fields of __0
FieldTypeRequiredDescription
toolIdstringRequiredTool being invoked.
inputunknownRequiredParsed input; stored as-is so the host can build its own domain record.
invocationPartial<InvocationMetadata> | undefinedOptionalWhat the caller already knows. The journal fills gaps and generates an id when absent.

Returns: string.

finishTool ​

Instance method.

Close an open tool call with its outcome.

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

Close an open tool call with its outcome.

ParameterTypePassingDescription
__0ToolJournalFinishRequired—
Fields of __0
FieldTypeRequiredDescription
invocationIdstringRequiredInvocation opened by beginTool.
status"error" | "success" | "cancelled"RequiredTerminal status; cancelled is distinct from error.
valueunknownRequiredProduced value on success; failure detail on error; ignored for cancellation.

Returns: void.

snapshot ​

Instance method.

ts
snapshot(): readonly ContextRecord[]

No call parameters.

Returns: readonly ContextRecord[].

Examples ​

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

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

API reference, usage examples and developer guides.