Advanced Orchestration Engines ⏱ 10 min read 📁 examples/26_a2a.mjs

Lesson 16: Distributed Multi-Agent Swarms

Unify local agents and remote A2A HTTP nodes into a single heterogeneous discussion swarm with mesh coordination.

1. Why This Feature Exists

In enterprise environments, specialized agents often run in dedicated network perimeters (e.g., inside private VPCs or specific cloud accounts). Distributed discussions allow these agents to deliberate without centralizing sensitive tooling.

2. Key Symbols and Exports

Heterogeneous Swarms
Combines in-process agents with remote HTTP-hosted agents transparently.
A2A Swarm Participation
Remote agents receive discussion context over JSON-RPC and contribute to the shared ledger.
Distributed Consensus
Enables cross-organizational and cross-service agent collaboration.

3. Implementation Walkthrough

import {
    ProviderType,
    resolveProvider,
    initializeClient,
    loadCredentials,
    getDefaultModel,
    DiscussionSession
} from 'merci-sdk';
import { loadA2ATool } from 'merci-sdk/tools';

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

// Incorporate remote A2A specialist into local discussion swarm
const remoteAgent = await loadA2ATool('http://127.0.0.1:4001/agent-card.json');

const swarm = new DiscussionSession(client, {
    model: getDefaultModel({ provider: PROVIDER }),
    objective: 'Design cross-region disaster recovery strategy.',
    agents: [
        { name: 'LocalPlanner', perspective: 'Infrastructure topologies' },
        { name: 'RemoteSecuritySpecialist', isRemote: true, tool: remoteAgent }
    ]
});

await swarm.runDebate();
const deliverable = await swarm.aggregate();
console.log(deliverable);

4. Wire and Telemetry Mechanics

Local agents execute via standard session steps; remote agents receive discussion payloads via HTTP JSON-RPC tools/call.

5. Run the Example

Execute the runnable example directly from the repository root:

node examples/26_a2a.mjs

Read the full example: examples/26_a2a.mjs →

Expected Output: Spawns background A2A agent server, joins remote agent to discussion swarm, and produces consolidated decision verdict.