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 already maintains its own journal. result.invocation links the actual call to the context record; text generated by the model cannot forge a call identity. snapshot returns an isolated copy, and modifying the copy does not rewrite the journal.
Manually using beginTool/finishTool applies only to call adapters owned by the App itself. An invocation can only begin and finish once. They record facts; they do not execute tools, authorize anything, or automatically write to a relational database. When persistent diagnostics are needed, the App hands Core facts to its own logging adapter.
Progressive examples for the same business case
Read the model receipt already recorded by the Runner
Beginner · Node.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());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
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());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());