Agent-to-Agent Protocol
A2A inlib/a2a.ts enables agents to send and receive messages during a workflow. It is used in tests (/api/test/a2a) and can be wired into execution for richer coordination.
Message Types
| Type | Purpose |
|---|---|
| request | Ask another agent for data or an action; expectsResponse and correlationId for matching. |
| response | Reply to a request; must include correlationId of the request. |
| notification | Inform one or more agents; no response expected. |
| data_share | Send structured data with a dataType to one or more agents. |
A2AMessage
- A2ARequest:
type: 'request',expectsResponse: boolean. - A2AResponse:
type: 'response',correlationId: string. - A2ADataShare:
type: 'data_share',dataType: string,data: any.
Communication Patterns
Request–Response
sendA2ARequest(from, to, payload, sessionId, timeout?)— Sends a request, subscribes for a response with matchingcorrelationId, resolves withpayloador rejects on timeout (default 30s).sendA2AResponse(from, to, payload, sessionId, correlationId)— Sends a response; the request’sfromis typically thetoof the response.
One-way
sendA2ANotification(from, to, notification, sessionId, metadata?)—tocan be one agent or an array.shareA2AData(from, to, dataType, data, sessionId)— Same forto;datais arbitrary.
Helpers
createA2AMessage(from, to, type, payload, sessionId, correlationId?)— Builds a message withidandtimestamp.getAgentCommunicationFlows(agentName)— FromAGENT_ROLES[agentName].communication_flows.canCommunicate(from, to)— Whethertois infrom’scommunication_flows.getAgentMessages(sessionId, agentName)— Messages whereagentNameis into.clearA2AMessages(sessionId)— Removes all messages for that session.
Implementation Details
Message Bus
A2AMessageBus— In-memory:Map<sessionId, A2AMessage[]>andMap<agentName, Set<callback>>.send(message)— Appends to the session’s list and invokes subscribers for each recipient into.subscribe(agentName, callback)— Registers a callback; returns an unsubscribe function.getMessages(sessionId),getMessagesBetween(sessionId, from, to),clear(sessionId)— Query and cleanup.
messageBus is exported. For production, this could be replaced with Redis, RabbitMQ, or similar.
A2AWorkflowIntegration
new A2AWorkflowIntegration(sessionId)initialize()— Clears A2A messages for thatsessionId.registerAgentHandler(agentName, handler)— Subscribes to the bus foragentNameandsessionId:- On
requestfrom another agent: runshandler(message); ifexpectsResponse, sends a response (or an error payload on exception). - On
data_shareornotification: runshandler(message).
- On
getCommunicationHistory()— ReturnsgetMessages(sessionId).
Agent Names
AgentName in a2a.ts includes: CEO, X402Agent, IdeaProcessor, IntentAnalyzer, PlatformSelector, PaymentValidator, ProductManager, FrontendDev, BackendDev, AIEngineer, DevOpsEngineer, ToolManager. getAgentCommunicationFlows and canCommunicate use AGENT_ROLES from lib/x402.ts.