WorkflowEvent
CORE · interface · 类型合同
Metadata only: never includes state, prompt, parameters, results or raw errors.
导入
ts
import type { WorkflowEvent } from '@jangts/agent-core/engine';js
/** @typedef {import('@jangts/agent-core/engine').WorkflowEvent} WorkflowEvent */其他公开入口:@jangts/agent-core、@jangts/agent-core/engine、@jangts/agent-core/types、@jangts/agent-core/structs。
定义
ts
interface WorkflowEvent字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
eventId | string | 必需 | 只读。见类型定义及调用场景。 |
errorEventId | string | undefined | 可省略 | 只读。Id of the failure that caused this transition, when recovering from an error. |
workflowId | string | 必需 | 只读。见类型定义及调用场景。 |
agentId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
branchId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
agentVersionId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
parentBranchId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
parentAgentVersionId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
forkPointId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
workflowInvocationId | string | 必需 | 只读。见类型定义及调用场景。 |
targetSpanId | string | undefined | 可省略 | 只读。Chosen successor span; absence of its enter event does not prove entry. |
nodeId | string | 必需 | 只读。见类型定义及调用场景。 |
roundIndex | number | 必需 | 只读。见类型定义及调用场景。 |
targetNodeId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
type | "error" | "transition" | "complete" | "enter" | 必需 | 只读。见类型定义及调用场景。 |
durationMs | number | undefined | 可省略 | 只读。Elapsed milliseconds for the phase the event reports. |
route | number | undefined | 可省略 | 只读。Zero-based index of the selected route in node.routes. |
routeId | string | undefined | 可省略 | 只读。Id of the selected route, when it declared one. |
conditionId | string | undefined | 可省略 | 只读。Id of the selected condition, when the route declared one. |
phase | "complete" | "boundary" | "requires" | "run" | "provides" | "route" | "result" | undefined | 可省略 | 只读。Logical phase that produced the event. |
failedRouteId | string | undefined | 可省略 | 只读。Route that failed on route, complete or result phases. |
runId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
spanId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
parentSpanId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
errorCode | string | undefined | 可省略 | 只读。Error classification for error events. |
使用示例
- 过程监听与节点报告:App 订阅 Core 执行事实;节点报告自身 usedModel,并用实例式子日志先记意图、再补结果,Loop 负责身份和日志。
监听任务经过的节点与模型事件
入门 · 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' }));节点执行时报告业务阶段
配置 · Node.js
节点只报告它知道的事实;Core 负责节点身份和执行关联。
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' }));