Lesson 11: Agent-to-Agent (A2A) Delegation
Enable distributed agent collaboration using Agent Cards, HTTP JSON-RPC delegation, origin pinning (SSRF protection), and end-to-end telemetry correlation.
1. Why This Feature Exists
Monolithic agent architectures do not scale. A2A protocol allows specialized agents (e.g. database query agent, code reviewer agent) to run as isolated services while appearing as local tools to orchestrators.
2. Key Symbols and Exports
3. Implementation Walkthrough
import {
ProviderType,
resolveProvider,
initializeClient,
loadCredentials,
getDefaultModel
} from 'merci-sdk';
import { loadA2ATool } from 'merci-sdk/tools';
const PROVIDER = resolveProvider();
const { client } = await initializeClient({ provider: PROVIDER, options: loadCredentials({ provider: PROVIDER }) });
// Load remote agent as a tool from its agent card endpoint
const specialistTool = await loadA2ATool('http://127.0.0.1:4000/agent-card.json', {
allowedOrigins: ['http://127.0.0.1:4000']
});
const session = client.session(getDefaultModel({ provider: PROVIDER }))
.withTools([specialistTool] });
const result = await session.run('Delegate a security review of our auth router to the specialist agent.');
console.log('Orchestrator Result:', result);4. Wire and Telemetry Mechanics
Fetches /agent-card.json via HTTP GET. When the orchestrator invokes the tool, an HTTP POST JSON-RPC request is sent to the target agent endpoint with correlated tracing headers.
5. Run the Example
Execute the runnable example directly from the repository root:
node examples/26_a2a.mjsRead the full example: examples/26_a2a.mjs →