WorkflowEvent
CORE · interface · Type contract
Metadata only: never includes state, prompt, parameters, results or raw errors.
Import
ts
import type { WorkflowEvent } from '@jangts/agent-core/engine';js
/** @typedef {import('@jangts/agent-core/engine').WorkflowEvent} WorkflowEvent */Other public entry points:@jangts/agent-core, @jangts/agent-core/engine, @jangts/agent-core/types, @jangts/agent-core/structs.
Definition
ts
interface WorkflowEventField structure
| Field | Type | Required | Description |
|---|---|---|---|
eventId | string | Required | Read-only. See the type definition and usage context. |
errorEventId | string | undefined | Optional | Read-only. Id of the failure that caused this transition, when recovering from an error. |
workflowId | string | Required | Read-only. See the type definition and usage context. |
agentId | string | undefined | Optional | Read-only. See the type definition and usage context. |
branchId | string | undefined | Optional | Read-only. See the type definition and usage context. |
agentVersionId | string | undefined | Optional | Read-only. See the type definition and usage context. |
parentBranchId | string | undefined | Optional | Read-only. See the type definition and usage context. |
parentAgentVersionId | string | undefined | Optional | Read-only. See the type definition and usage context. |
forkPointId | string | undefined | Optional | Read-only. See the type definition and usage context. |
workflowInvocationId | string | Required | Read-only. See the type definition and usage context. |
targetSpanId | string | undefined | Optional | Read-only. Chosen successor span; absence of its enter event does not prove entry. |
nodeId | string | Required | Read-only. See the type definition and usage context. |
roundIndex | number | Required | Read-only. See the type definition and usage context. |
targetNodeId | string | undefined | Optional | Read-only. See the type definition and usage context. |
type | "error" | "transition" | "complete" | "enter" | Required | Read-only. See the type definition and usage context. |
durationMs | number | undefined | Optional | Read-only. Elapsed milliseconds for the phase the event reports. |
route | number | undefined | Optional | Read-only. Zero-based index of the selected route in node.routes. |
routeId | string | undefined | Optional | Read-only. Id of the selected route, when it declared one. |
conditionId | string | undefined | Optional | Read-only. Id of the selected condition, when the route declared one. |
phase | "complete" | "boundary" | "requires" | "run" | "provides" | "route" | "result" | undefined | Optional | Read-only. Logical phase that produced the event. |
failedRouteId | string | undefined | Optional | Read-only. Route that failed on route, complete or result phases. |
runId | string | undefined | Optional | Read-only. See the type definition and usage context. |
spanId | string | undefined | Optional | Read-only. See the type definition and usage context. |
parentSpanId | string | undefined | Optional | Read-only. See the type definition and usage context. |
errorCode | string | undefined | Optional | Read-only. Error classification for error events. |
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' }));