Lesson 13: Directed Acyclic Graph (DAG) Workflows
Architect resilient multi-step pipelines with WorkflowPlanner, WorkflowExecutor, and WorkflowEvaluator: plan generation, topological execution, and self-healing replanning.
1. Why This Feature Exists
Single-prompt LLM execution fails on complex, multi-stage objectives. The DAG Workflow Engine decomposes high-level goals into structured tasks with explicit dependency tracking and automated self-healing.
2. Key Symbols and Exports
3. Implementation Walkthrough
import {
ProviderType,
resolveProvider,
initializeClient,
loadCredentials,
getDefaultModel
} from 'merci-sdk';
import {
WorkflowPlanner,
WorkflowExecutor,
WorkflowEvaluator
} from 'merci-sdk/planning';
const PROVIDER = resolveProvider();
const { client } = await initializeClient({ provider: PROVIDER, options: loadCredentials({ provider: PROVIDER }) });
const MODEL = getDefaultModel({ provider: PROVIDER });
// 1. Plan workflow graph
const planner = new WorkflowPlanner(client, MODEL);
const plan = await planner.plan('Audit API endpoints, perform latency benchmark, and synthesize markdown report.');
// 2. Execute with self-healing evaluator
const evaluator = new WorkflowEvaluator(client, MODEL);
const executor = new WorkflowExecutor(client, MODEL)
.withEvaluator(evaluator)
.withMaxReplanRounds(2);
const result = await executor.execute(plan);
console.log('Workflow Output:', result.output);4. Wire and Telemetry Mechanics
The planner outputs a validated JSON graph of steps and dependencies. The executor resolves topological order, injects upstream step outputs, runs sessions, and evaluates outputs against node criteria.
5. Run the Example
Execute the runnable example directly from the repository root:
node examples/17_dag_workflow.mjsRead the full example: examples/17_dag_workflow.mjs →