SubFlowLogger
CORE · class · 运行时值
Full execution-owned recorder. Owns its store and may issue restricted delegates.
导入
ts
import { SubFlowLogger } from '@jangts/agent-core/diagnostics';js
import { SubFlowLogger } from '@jangts/agent-core/diagnostics';其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/structs、@jangts/agent-core/diagnostics。
定义
ts
class SubFlowLogger继承或实现: SubFlowLog。
构造函数
ts
new SubFlowLogger(token: typeof loggerToken, store: Store): SubFlowLogger| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
token | typeof loggerToken | 必需 | — |
store | Store | 必需 | — |
store 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
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. |
owns | (stepId: string | -1, subnodeId: string) => boolean | 必需 | 见类型定义及调用场景。 |
isActive | () => boolean | 必需 | 见类型定义及调用场景。 |
nextNativeSubnodeId | (kind: string, definitionId: string) => string | 必需 | 见类型定义及调用场景。 |
warn | (operation: "write" | "fix", reason: RejectionReason) => void | 必需 | 见类型定义及调用场景。 |
返回: SubFlowLogger。
成员目录
| 成员 | 用途 |
|---|---|
write | 完整输入输出见下方重载。 |
fix | 完整输入输出见下方重载。 |
readAll | 完整输入输出见下方重载。 |
fork | Issue a delegate for an App-owned logical group; no execution or scheduling is implied. |
成员详情
write
实例方法。
ts
write(input: SubFlowStepInput): string | -1| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
input | SubFlowStepInput | 必需 | — |
input 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
kind | string | undefined | 可省略 | 只读。Optional family classification; defaults to the custom type when omitted. |
payload | Readonly<Record<string, SubFlowValue>> | undefined | 可省略 | 只读。见类型定义及调用场景。 |
subnodeId | string | undefined | 可省略 | 只读。Logical subnode grouping within this node visit; independent of individual log ids. |
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. |
返回: string \| -1。
fix
实例方法。
ts
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
实例方法。
ts
readAll(): readonly Readonly<RecordedSubStep>[]无调用参数。
返回: readonly Readonly<RecordedSubStep>[]。
fork
实例方法。
Issue a delegate for an App-owned logical group; no execution or scheduling is implied.
ts
fork(subnodeId: string): ScopedSubFlowLoggerIssue a delegate for an App-owned logical group; no execution or scheduling is implied.
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
subnodeId | string | 必需 | — |
返回: ScopedSubFlowLogger。
使用示例
- 过程监听与节点报告: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' }));先记异步计划,再补结果
配置 · Node.js
受限 logger 自动绑定分组并只修订自己的 write;readAll 仍可读全量。每次 fix 追加独立记录并关联原 write,节点无需提交 logger。
ts
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
type State = { result?: string };
const workflow = defineWorkflow<State, string>({ id: 'prepare', nodes: [{
id: 'prepare', description: '准备资料', async run(_, context) {
const subs = context.createSubFlowLogger();
const read = subs.fork('material-read');
const id = read.write({ name: '读取资料', kind: 'read', type: 'material.read' });
read.fix(id, { status: 'running' });
const result = await Promise.resolve('已准备');
read.fix(id, { status: 'success', usedModel: false, payload: { result } });
context.report({ usedModel: false });
console.log(read.readAll());
return { result };
}, routes: [route.deliver('result')],
}] });
const agent = new AgentCoreEngine({ workflow, execution: { observe: {
accepts: ({ event, content }) => content === 'metadata' || event === 'node.progress',
event(event) { if (event.type === 'node.progress') console.log(event.payload.subStep, event.subSteps); },
} } });
console.log(await agent.run({}));js
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
const workflow = defineWorkflow({ id: 'prepare', nodes: [{
id: 'prepare', description: '准备资料', async run(_, context) {
const subs = context.createSubFlowLogger();
const read = subs.fork('material-read');
const id = read.write({ name: '读取资料', kind: 'read', type: 'material.read' });
read.fix(id, { status: 'running' });
const result = await Promise.resolve('已准备');
read.fix(id, { status: 'success', usedModel: false, payload: { result } });
context.report({ usedModel: false });
console.log(read.readAll());
return { result };
}, routes: [route.deliver('result')],
}] });
const agent = new AgentCoreEngine({ workflow, execution: { observe: {
accepts: ({ event, content }) => content === 'metadata' || event === 'node.progress',
event(event) { if (event.type === 'node.progress')
console.log(event.payload.subStep, event.subSteps); },
} } });
console.log(await agent.run({}));