CoreEventPayloads
CORE · interface · Type contract
Payload of every Core event, keyed by event name. Fields are the event's own facts only.
Import
ts
import type { CoreEventPayloads } from '@jangts/agent-core/diagnostics';js
/** @typedef {import('@jangts/agent-core/diagnostics').CoreEventPayloads} CoreEventPayloads */Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/structs, @jangts/agent-core/diagnostics.
Definition
ts
interface CoreEventPayloadsField structure
| Field | Type | Required | Description |
|---|---|---|---|
loop.event | LoopEvent | Required | One loop round transition raised by the engine. |
model.binding | { modelId: string; invocationId: string; status: "running" | "success" | "error" | "cancelled"; phase: "input" | "invoke" | "output"; durationMs?: number; errorCode?: string; } | Required | Model binding selection and its per-phase timing; recorded around one model invocation. |
model.prepare | { stageId: string; transportId: string; messages: readonly ModelMessage[]; options: unknown; context?: unknown; } | Required | Snapshot of the prepared request, emitted before the provider is called. |
model.output | { stageId: string; callSequence: number; partIndex: number; part: import("./model/messages.js").ModelPart; } | Required | One streamed model part, in arrival order. |
model.parsed | { stageId: string; callSequence: number; value?: unknown; } | Required | Parsed output of a response, once the collector resolved it. |
model.end | { stageId: string; state: Readonly<ModelCallTrace>; error?: unknown; receivedParts: number; } | Required | End of a model call, successful or not, with its accumulated trace. |
runtime.rejected | { stageId?: string; error: unknown; } | Required | A Core input or state condition rejected execution. |
node.progress | { payload?: unknown; subStep?: import("./debug.js").SubStepProgress; reportError?: "INVALID_NODE_REPORT"; } | Required | Progress reported by an active workflow node. |
model.start | { stageId: string; callSequence: number; transportId: string; } | Required | Start of one model call, emitted before any output part. |
workflow.event | { event: WorkflowEvent; payload?: unknown; } | Required | Workflow lifecycle fact raised by the engine. |
tool.call | { toolId: string; invocationId: string; input?: unknown; } | Required | A tool call was accepted for execution. |
tool.result | { toolId: string; invocationId: string; value?: unknown; error?: unknown; errorCode?: string; status: import("./common.js").InvocationStatus; durationMs: number; } | Required | A tool call settled, successfully or not. |
rule.result | { tags: readonly string[]; error: unknown; } | Required | A declarative rule rejected processing, with its ownership tags. |
Examples
- Process observation and node reports: The App subscribes to Core execution facts; nodes report their own usedModel and use an instance sub-logger to record intent first and then results, while the Loop owns identity and logging.
Observe the nodes and model events a task passes through
Beginner · Node.js
ts
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
type State = { name: string; answer?: string };
const workflow = defineWorkflow<State, string>({
id: 'greeting',
nodes: [{
id: 'greet', description: '根据本次姓名生成问候', startsRound: true,
run: state => ({ answer: '你好,' + state.name }),
routes: [route.deliver('answer')],
}],
});
const agent = new AgentCoreEngine({ workflow, execution: {
observe: { event(event) { console.log(event.type, event.eventId); } },
} });
console.log(await agent.run({ name: 'Ivan' }));js
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
const workflow = defineWorkflow({
id: 'greeting',
nodes: [{
id: 'greet', description: '根据本次姓名生成问候', startsRound: true,
run: state => ({ answer: '你好,' + state.name }),
routes: [route.deliver('answer')],
}],
});
const agent = new AgentCoreEngine({ workflow, execution: {
observe: { event(event) { console.log(event.type, event.eventId); } },
} });
console.log(await agent.run({ name: 'Ivan' }));Report a business stage while the node executes
Configuration · Node.js
The node only reports facts it knows; Core owns node identity and execution association.
ts
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
type State = { name: string; answer?: string };
const workflow = defineWorkflow<State, string>({ id: 'greeting', nodes: [{
id: 'greet', description: '生成问候', startsRound: true,
run(state, context) {
context.report({ payload: { phase: 'formatting' } });
return { answer: '你好,' + state.name };
}, routes: [route.deliver('answer')],
}] });
const agent = new AgentCoreEngine({ workflow, execution: {
observe: { event(event) { console.log(event.type); } },
} });
console.log(await agent.run({ name: 'Ivan' }));js
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
const workflow = defineWorkflow({ id: 'greeting', nodes: [{
id: 'greet', description: '生成问候', startsRound: true,
run(state, context) {
context.report({ payload: { phase: 'formatting' } });
return { answer: '你好,' + state.name };
}, routes: [route.deliver('answer')],
}] });
const agent = new AgentCoreEngine({ workflow, execution: {
observe: { event(event) { console.log(event.type); } },
} });
console.log(await agent.run({ name: 'Ivan' }));