Remote Agent Communication (A2A)

Overview

The Remote Agent Communication (A2A) module enables distributed multi-agent communication through the Agent-To-Agent (A2A) protocol. It provides a standardized mechanism for agents running in different processes or on different hosts to interact seamlessly using gRPC or HTTP transports. This module facilitates remote agent invocation, event translation between the internal Agent Development Kit (ADK) session event model and the A2A protocol message format, and resolution of remote agent metadata (agent cards).

The A2A protocol enables:

This module plays a crucial role in enabling scalable, distributed AI agent architectures where agents may delegate work, escalate interactions, or collaborate remotely.


Core Concepts

Agent-To-Agent (A2A) Protocol

The A2A protocol defines a message and event format for communication between AI agents. It supports:

The protocol supports streaming responses and incremental updates, allowing agents to communicate asynchronously and handle long-running tasks.

Agent Cards

An Agent Card describes an agent's metadata, including:

Agent cards enable dynamic discovery and resolution of remote agents before communication.

Session Events and A2A Events

The ADK internally represents agent interactions as session events (session.Event), which include user inputs, model responses, function calls, and other actions.

The A2A protocol uses its own event types (a2a.Event, a2a.Message, etc.).

This module handles bidirectional conversion between these two event representations:


Functional Components

1. A2A Agent Implementation (agent/remoteagent/a2a_agent.go)

This component provides the NewA2A function to create a remote agent proxy that communicates using the A2A protocol. It implements the agent.Agent interface by:

Important points:

This allows local agents to delegate requests transparently to remote agents over the network.

2. Event Conversion and Processing (server/adka2a/events.go, server/adka2a/parts.go, server/adka2a/processor.go)

This set of utilities and processors performs the crucial task of translating between ADK session events and A2A protocol events:

This conversion layer ensures consistent, lossless communication between local and remote agent representations.

3. Executor and Server (server/adka2a/executor.go)

The Executor implements the a2asrv.AgentExecutor interface to run an ADK agent in response to A2A requests:

This executor is the server-side bridge that wraps local ADK agents behind A2A protocol endpoints.

4. Agent Skill Building (server/adka2a/agent_card.go)

This component constructs agent skill descriptions to be included in agent cards:

This supports rich discovery and delegation scenarios where agents can advertise their abilities over A2A.


Interaction Between Components

The flow of communication and transformation in A2A remote agent communication is as follows:

  1. Local Agent Invocation:
    The local ADK agent invokes the remote agent using the a2aAgent implementation (NewA2A).

  2. Agent Card Resolution:
    The remote agent's metadata (agent card) is fetched or loaded to configure the A2A client.

  3. Session Events to A2A Message:
    The local invocation context's session events (user messages, function calls) are converted into an A2A message payload.

  4. Message Sent Over Network:
    The A2A client sends the message to the remote agent's gRPC or HTTP endpoint.

  5. Remote Agent Executor:
    The remote server receives the A2A message, converts it to ADK content, and executes the configured agent using the Executor.

  6. Session Events Produced:
    The agent produces session events (responses, function calls, outputs).

  7. Session Events to A2A Events:
    The eventProcessor converts these session events into A2A events, including chunked artifact updates and status updates.

  8. Streaming Response:
    The remote server streams these A2A events back to the client.

  9. Client Converts to Session Events:
    The a2aAgent client converts incoming A2A events into ADK session events.

  10. Returning Results:
    The local invocation receives these events as a stream, integrating them seamlessly.


Key Design Patterns and Approaches


Visualizing Remote Agent Communication Flow

sequenceDiagram
participant LocalAgent as Local Agent (ADK)
participant A2AClient as A2A Client (a2aclient)
participant RemoteServer as Remote Agent Server (A2A Executor)
participant RemoteAgent as Remote Agent (ADK)
LocalAgent->>A2AClient: Resolve Agent Card
LocalAgent->>A2AClient: Convert Session Events to A2A Message
A2AClient->>RemoteServer: Send A2A Message (gRPC/HTTP)
RemoteServer->>RemoteAgent: Convert A2A Message to ADK Content
RemoteAgent->>RemoteAgent: Run Agent with Content
RemoteAgent->>RemoteServer: Produce Session Events
RemoteServer->>RemoteServer: Convert Session Events to A2A Events
RemoteServer-->>A2AClient: Stream A2A Events (Artifact Updates, Status)
A2AClient->>LocalAgent: Convert A2A Events to Session Events
LocalAgent->>LocalAgent: Process Remote Agent Events

Summary of Relevant Files and Their Roles

File

Role

agent/remoteagent/a2a_agent.go

Implements the remote agent proxy using the A2A protocol, handling invocation, messaging, and event translation.

agent/remoteagent/utils.go

Utility functions for event inspection, session event conversion, and contextual presentation of remote agent messages.

server/adka2a/events.go

Conversion functions between ADK session events and A2A protocol events; manages metadata and action flags.

server/adka2a/parts.go

Converts message content parts between ADK genai.Part and A2A parts, including text, code, function calls, and files.

server/adka2a/processor.go

Processes ADK session events during agent execution, translates to A2A artifact updates and status events, manages terminal event logic.

server/adka2a/executor.go

Implements the A2A server executor that receives A2A requests, runs the configured ADK agent, and streams back A2A events.

server/adka2a/agent_card.go

Builds detailed agent skill metadata for agent cards, enabling capability discovery and dynamic resolution.


Interaction with Other Topics

Refer to [A2A Agent Implementation](/agent/remoteagent/a2a_agent.go), [Event Conversion and Processing](/server/adka2a/events.go), [Executor and Server](/server/adka2a/executor.go), and [Agent Skill Building](/server/adka2a/agent_card.go) for detailed explanations of their implementation and interactions.


This detailed explanation covers the purpose, functionality, and interaction of components within the Remote Agent Communication (A2A) module, illustrating its role in enabling distributed multi-agent communication within the system.