Advanced Orchestration Engines ⏱ 10 min read 📁 examples/17_dag_workflow.mjs

Lesson 18: DAG Workflows with Shared Task State

Synchronize task lists across independent DAG workflow steps using a shared TodoStore for reconnaissance, vulnerability discovery, and remediation.

1. Why This Feature Exists

When a multi-step DAG executes, individual steps normally run in isolated sessions. Sharing a TodoStore enables persistent task tracking across the entire workflow pipeline without polluting the prompt history.

2. Key Symbols and Exports

Shared TodoStore
A single synchronized task repository passed into each DAG step session.
Recon-to-Remediation Pipeline
Step 1 populates todos from security findings; Step 2 iterates and marks items resolved.
Step-to-Step State Sync
Preserves task tracking state across isolated execution boundaries.

3. Implementation Walkthrough

import {
    ProviderType,
    resolveProvider,
    initializeClient,
    loadCredentials,
    getDefaultModel
} from 'merci-sdk';
import { WorkflowPlanner, WorkflowExecutor } from 'merci-sdk/planning';

const PROVIDER = resolveProvider();
const { client } = await initializeClient({ provider: PROVIDER, options: loadCredentials({ provider: PROVIDER }) });
const MODEL = getDefaultModel({ provider: PROVIDER });

// Shared TodoStore instance across all steps
const sharedTodos = [];

const executor = new WorkflowExecutor(client, MODEL)
    .withSessionSetup((session) => {
        // Attach shared todo store to every step's session
        session.withTodos({ initialTodos: sharedTodos });
    });

const plan = {
    steps: [
        { id: 'recon', prompt: 'Audit codebase and create todos for all findings.' },
        { id: 'remediate', prompt: 'Review open todos and execute fixes.', dependencies: ['recon'] }
    ]
};

await executor.execute(plan);

4. Wire and Telemetry Mechanics

Each step's session registers the TodoComponent referencing the shared array. Updates in step 1 are instantly visible to step 2.

5. Run the Example

Execute the runnable example directly from the repository root:

node examples/17_dag_workflow.mjs

Read the full example: examples/17_dag_workflow.mjs →

Expected Output: Executes real source vulnerability scan, creates todos for findings, remediates items in subsequent DAG steps, and verifies clean state.