SubFlowLog
CORE · interface · 类型合同
Common read/write surface for both independently implemented logger classes.
导入
ts
import type { SubFlowLog } from '@jangts/agent-core/diagnostics';js
/** @typedef {import('@jangts/agent-core/diagnostics').SubFlowLog} SubFlowLog */其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/structs、@jangts/agent-core/diagnostics。
定义
ts
interface SubFlowLog字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
write | (input: ScopedSubFlowStepInput) => string | -1 | 必需 | 见类型定义及调用场景。 |
fix | (stepId: string | -1, patch: SubFlowStepFix) => boolean | 必需 | 见类型定义及调用场景。 |
readAll | () => readonly Readonly<RecordedSubStep>[] | 必需 | Both logger classes return the same complete immutable ledger. |
成员目录
| 成员 | 用途 |
|---|---|
write | 完整输入输出见下方重载。 |
fix | 完整输入输出见下方重载。 |
readAll | Both logger classes return the same complete immutable ledger. |
成员详情
write
ts
SubFlowLog.write(input: ScopedSubFlowStepInput): string | -1| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
input | ScopedSubFlowStepInput | 必需 | — |
input 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
kind | string | undefined | 可省略 | 只读。Optional family classification; defaults to the custom type when omitted. |
type | string | undefined | 可省略 | 只读。App-defined business log type; never a write/fix operation enum. |
parentStepId | string | undefined | 可省略 | 只读。Reported parent step, forming a tree; absent for a top-level step. |
relatedDefinitionId | string | undefined | 可省略 | 只读。Self-reported reference only; never a workflow dispatch identity. |
relatedInvocationId | string | undefined | 可省略 | 只读。Real model/tool invocation identity, kept separate from the node-local subnode id. |
name | string | 必需 | 只读。Short reported label. |
status | "error" | "success" | "unknown" | "planned" | "running" | "cancelled" | "skipped" | undefined | 可省略 | 只读。Reported lifecycle status; omission means the node did not report one. |
usedModel | boolean | undefined | 可省略 | 只读。This step's own reported model use, never a descendant rollup. |
startedAtMs | number | undefined | 可省略 | 只读。Reported start instant in epoch milliseconds. |
endedAtMs | number | undefined | 可省略 | 只读。Reported end instant in epoch milliseconds; only meaningful for terminal statuses. |
nextStepIds | readonly string[] | undefined | 可省略 | 只读。Reported successor step ids, for display only. |
caseId | string | undefined | 可省略 | 只读。Reported case or variant id, interpreted by the App. |
summary | string | undefined | 可省略 | 只读。Reported one-line summary. |
payload | Readonly<Record<string, SubFlowValue>> | undefined | 可省略 | 只读。见类型定义及调用场景。 |
返回: string \| -1。
fix
ts
SubFlowLog.fix(stepId: string | -1, patch: SubFlowStepFix): boolean| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
stepId | string | -1 | 必需 | — |
patch | SubFlowStepFix | 必需 | — |
patch 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
status | "error" | "success" | "unknown" | "planned" | "running" | "cancelled" | "skipped" | undefined | 可省略 | 只读。见类型定义及调用场景。 |
usedModel | boolean | undefined | 可省略 | 只读。见类型定义及调用场景。 |
startedAtMs | number | undefined | 可省略 | 只读。见类型定义及调用场景。 |
endedAtMs | number | undefined | 可省略 | 只读。见类型定义及调用场景。 |
summary | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
nextStepIds | readonly string[] | undefined | 可省略 | 只读。见类型定义及调用场景。 |
payload | Readonly<Record<string, SubFlowValue>> | undefined | 可省略 | 只读。Fill missing result fields; existing facts cannot be replaced. |
返回: boolean。
readAll
Both logger classes return the same complete immutable ledger.
ts
SubFlowLog.readAll(): readonly Readonly<RecordedSubStep>[]Both logger classes return the same complete immutable ledger.
无调用参数。
返回: readonly Readonly<RecordedSubStep>[]。
使用示例
- 过程监听与节点报告: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' }));