Workflow API
Graph
Định nghĩa DAG các bước workflow:
import { Graph } from '@moon-wave/workflow';
const graph = new Graph() .step({ name: 'fetch-data', execute: async (ctx) => { return await fetchSomeData(); }, next: (result) => result ? 'process' : 'error', }) .step({ name: 'process', execute: async (ctx) => { const data = ctx.get<MyData>('fetch-data'); return transform(data); }, }) .start('fetch-data');next() trả về tên bước tiếp theo, hoặc null để kết thúc workflow.
WorkflowEngine
import { WorkflowEngine } from '@moon-wave/workflow';
const engine = new WorkflowEngine(graph, maxSteps: 50);const result = await engine.run(input, agentCtx);WorkflowResult
interface WorkflowResult { output: unknown; steps: Array<{ name: string; result: unknown; durationMs: number }>; totalDurationMs: number;}WorkflowContext
ctx.get<T>(stepName) // lấy kết quả bước trướcctx.getLast<T>() // lấy kết quả bước gần nhấtctx.getAll() // lấy tất cả kết quảctx.agentCtx // AgentContext gốc (có env, sessionId, v.v.)ctx.input // input ban đầu của workflow