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

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

Hybrid Multi-Engine Architecture
DAG coordinates macro stages while embedding StateMachines or Discussions inside steps.
Per-Step Engine Routing
Step 1: standard task; Step 2: Discussion session; Step 3: StateMachine.
Bounded Deliverables
Explicit token/char budgets per step preventing context explosion.

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.mjs

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

Expected Output: Executes DAG step 1 as a multi-agent debate, passes verdict to step 2 state machine, and synthesizes complete deliverable.