Lesson 23: Multi-Engine DAG Stage Planning
Construct hybrid orchestration pipelines: embed specialized StateMachines and Discussion sessions inside individual DAG workflow steps.
1. Why This Feature Exists
Different problem stages require different reasoning topologies. Planning a feature is best done via Discussion; implementing it is best done via StateMachine; sequencing them is best done via DAG.
2. Key Symbols and Exports
3. Implementation Walkthrough
import {
ProviderType,
resolveProvider,
initializeClient,
loadCredentials,
getDefaultModel,
DiscussionSession,
StateMachine
} from 'merci-sdk';
import { WorkflowExecutor } from 'merci-sdk/planning';
const PROVIDER = resolveProvider();
const { client } = await initializeClient({ provider: PROVIDER, options: loadCredentials({ provider: PROVIDER }) });
const MODEL = getDefaultModel({ provider: PROVIDER });
const hybridPlan = {
steps: [
{
id: 'architecture_debate',
engine: 'discussion',
objective: 'Debate GraphQL vs gRPC for internal service mesh.'
},
{
id: 'implementation_sm',
engine: 'stateMachine',
dependencies: ['architecture_debate'],
objective: 'Implement selected interface definition with verification.'
}
]
};
const executor = new WorkflowExecutor(client, MODEL)
.withEngineHandler('discussion', async (step) => {
const disc = new DiscussionSession(client, { model: MODEL, objective: step.objective });
await disc.runDebate();
return await disc.aggregate();
});
await executor.execute(hybridPlan);4. Wire and Telemetry Mechanics
The executor branches on step.engine, spinning up child engines with inherited telemetry runId and piping aggregate outputs forward.
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 →