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
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.mjsRead the full example: examples/17_dag_workflow.mjs →