Advanced Orchestration Engines ⏱ 13 min read 📁 examples/15_delegation.mjs

Lesson 25: Subagents in Action: 4 Engines Compared

Benchmark the same objective and subagent profiles across FOUR orchestration engines: Naive Session, DAG Workflow, StateMachine, and MAA, plus background detached subagents.

1. Why This Feature Exists

Choosing the right orchestrator is critical. Running the exact same objective and profiles through all four architectures demonstrates the unique strengths, token efficiencies, and error resilience of each approach.

2. Key Symbols and Exports

Engine A: Naive Session
Single agentic loop with task tool delegation.
Engine B: DAG Workflow
Topological task execution where each node calls specialist subagents.
Engine C: State Machine
Cyclical node graph where terminal states are verified with retries.
Engine D: MAA
Structured runTasks + planForEach + judge aggregation.
background: true
Detached subagent execution with asynchronous task:finish notification.

3. Implementation Walkthrough

import {
    ProviderType,
    initializeClient,
    loadCredentials,
    withTaskAgents,
    DiscussionSession,
    StateMachine
} from 'merci-sdk';
import { WorkflowExecutor } from 'merci-sdk/planning';
import { resolveExample } from '../_shared/example-utils.mjs';

const { provider, defaultModel, toolModel } = resolveExample();
const { client } = await initializeClient({ provider, options: loadCredentials({ provider }) });

const PROFILES = [
    { name: 'researcher', model: toolModel, systemPrompt: 'Conduct detailed domain research.' },
    { name: 'writer', model: toolModel, systemPrompt: 'Draft clear, actionable documentation.' },
    { name: 'checker', model: toolModel, systemPrompt: 'Audit content for accuracy and completeness.' }
];

withTaskAgents(client, PROFILES, { maxDepth: 1 });

const OBJECTIVE = 'Plan a 3-day motorcycle trip from Prague to Dubrovnik in summer 2026.';

// Benchmark across all 4 engines
console.log('--- Engine A: Naive ---');
console.log('--- Engine B: DAG ---');
console.log('--- Engine C: StateMachine ---');
console.log('--- Engine D: MAA ---');

4. Wire and Telemetry Mechanics

All four engines utilize the identical task tool registration and event bus, allowing direct side-by-side comparison of turn count, tokens, and output fidelity.

5. Run the Example

Execute the runnable example directly from the repository root:

node examples/15_delegation.mjs

Read the full example: examples/15_delegation.mjs →

Expected Output: Runs all 4 orchestration patterns end-to-end, logs background task completion events, and prints comparative results.