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 ContextJournalExtends or implements: ToolJournal.
Constructor
ts
new ContextJournal(): ContextJournalNo call parameters.
Returns: ContextJournal.
Member index
| Member | Purpose |
|---|---|
model | Record one model-produced value. |
beginTool | Open a tool call. |
finishTool | Close an open tool call with its outcome. |
snapshot | See 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; }): voidRecord one model-produced value.
| Parameter | Type | Passing | Description |
|---|---|---|---|
__0 | { stageId: string; value: unknown; invocation: InvocationMetadata; } | Required | — |
Fields of __0
| Field | Type | Required | Description |
|---|---|---|---|
stageId | string | Required | See the type definition and usage context. |
value | unknown | Required | See the type definition and usage context. |
invocation | InvocationMetadata | Required | See the type definition and usage context. |
Returns: void.
beginTool
Instance method.
Open a tool call.
ts
beginTool({ toolId, input, invocation }: ToolJournalStart): stringOpen a tool call.
| Parameter | Type | Passing | Description |
|---|---|---|---|
__0 | ToolJournalStart | Required | — |
Fields of __0
| Field | Type | Required | Description |
|---|---|---|---|
toolId | string | Required | Tool being invoked. |
input | unknown | Required | Parsed input; stored as-is so the host can build its own domain record. |
invocation | Partial<InvocationMetadata> | undefined | Optional | What 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): voidClose an open tool call with its outcome.
| Parameter | Type | Passing | Description |
|---|---|---|---|
__0 | ToolJournalFinish | Required | — |
Fields of __0
| Field | Type | Required | Description |
|---|---|---|---|
invocationId | string | Required | Invocation opened by beginTool. |
status | "error" | "success" | "cancelled" | Required | Terminal status; cancelled is distinct from error. |
value | unknown | Required | Produced 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
- 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.
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());