Skip to content

Sequential 流水线

本示例展示最简单的 顺序控制流:两个 Mock Unit 依次执行,结果写入 SharedState。

代码示例

文件:examples/sequential-pipeline.ts

核心结构:

typescript
const engine = createWorkflowEngine({
  workflowId: 'sequential-pipeline',
  units: new Map([
    ['research', research],
    ['write', write],
  ]),
  controlFlow: new SequentialFlow([research, write]),
  sharedState: createSharedState(),
});

const result = await engine.run({ task: '写一篇 Uni-Flow 简介' });
步骤Unit输出键
1researchoutput.research
2writeoutput.write

YAML 等价

文件:examples/yaml-sequential.yaml

yaml
flow:
  type: sequential
  order: [research, write]

运行 YAML 版本:

bash
npm run build
npx uniflow validate examples/yaml-sequential.yaml
npx tsx examples/run-yaml-sequential.ts

运行代码版

bash
npx tsx examples/sequential-pipeline.ts

预期输出包含 completedUnits: ['research', 'write'] 与非空的 output.write

相关文档

MIT Licensed