Skip to content

transport

A2A Transport Abstraction

Defines the transport abstraction for A2A protocol communication. This trait provides a clean interface between the A2A protocol logic and the underlying transport implementation (HTTP, WebSocket, etc.).

A2A Transport trait

Defines the interface for sending A2A protocol messages over various transport mechanisms. Implementations handle the actual network communication while the protocol core handles the A2A semantics.

  • Transport Agnostic: Works with HTTP, WebSocket, gRPC, etc.
  • JSON-RPC Foundation: Uses JSON-RPC 2.0 message types
  • Async Compatible: Supports both sync and async implementations
  • Error Transparent: Transport errors are mapped to A2A errors
use a2a_protocol_core::{A2ATransport, JsonRpcRequest, JsonRpcResponse, JsonRpcNotification, A2AResult};
use serde_json::json;
// Mock transport implementation
struct MockTransport;
impl A2ATransport for MockTransport {
async fn send_request(&self, request: JsonRpcRequest) -> A2AResult<JsonRpcResponse> {
// Implementation sends request over network
Ok(JsonRpcResponse::success(request.id, json!({"pong": true})))
}
async fn send_notification(&self, notification: JsonRpcNotification) -> A2AResult<()> {
// Implementation sends notification (fire-and-forget)
Ok(())
}
async fn health_check(&self) -> A2AResult<()> {
// Check if transport is available
Ok(())
}
}

Required / Provided Methods

async fn send_request(&self, request: JsonRpcRequest) -> A2AResult<JsonRpcResponse>

Send a JSON-RPC request and wait for response

This method sends a request to a remote agent and waits for the response. The transport implementation handles the actual network communication, serialization, and correlation of requests with responses.

  • request: The JSON-RPC 2.0 request to send
  • Ok(JsonRpcResponse): The response from the remote agent
  • Err(A2AError): Transport or protocol error
async fn send_notification(&self, notification: JsonRpcNotification) -> A2AResult<()>

Send a JSON-RPC notification (fire-and-forget)

This method sends a notification to a remote agent without waiting for a response. Notifications are used for logging, metrics, events, and other operations where the sender doesn’t need confirmation.

  • notification: The JSON-RPC 2.0 notification to send
  • Ok(()): Notification was sent successfully
  • Err(A2AError): Transport error occurred
async fn health_check(&self) -> A2AResult<()>

Check if the transport is available and healthy

This method verifies that the transport can communicate with remote agents. It’s used for health checks, circuit breakers, and load balancing decisions.

  • Ok(()): Transport is healthy and available
  • Err(A2AError): Transport is unavailable or unhealthy
fn get_metadata(&self) -> HashMap<String, Value>

Get transport-specific metadata

This method returns metadata about the transport implementation, such as connection info, capabilities, or configuration details.

A map of metadata key-value pairs

fn transport_type(&self) -> &''static str

Get the transport type identifier

Returns a string identifying the transport type (e.g., “http”, “websocket”). This is used for logging, monitoring, and debugging.

A2A Transport Factory trait

Factory for creating transport instances for different agents or endpoints. This enables connection pooling, load balancing, and dynamic transport configuration.

Associated Types

  • type Transport — Transport type created by this factory

Required / Provided Methods

async fn create_transport(&self, agent_id: &str, endpoint: &str, config: Option<HashMap<String, Value>>) -> A2AResult<<Self as ?>::Transport>

Create a transport instance for the specified agent

  • agent_id: Target agent identifier
  • endpoint: Agent endpoint URL or connection string
  • config: Optional transport-specific configuration
  • Ok(Transport): Successfully created transport
  • Err(A2AError): Failed to create transport
async fn get_transport(&self, agent_id: &str, endpoint: &str) -> A2AResult<<Self as ?>::Transport>

Get or create cached transport for agent

This method may reuse existing connections for better performance.

  • agent_id: Target agent identifier
  • endpoint: Agent endpoint URL or connection string
  • Ok(Transport): Transport ready for use
  • Err(A2AError): Failed to get/create transport
async fn remove_transport(&self, agent_id: &str) -> A2AResult<()>

Remove cached transport for agent

Forces creation of a new transport on next request. Useful for handling connection failures or configuration changes.

fn get_config(&self) -> HashMap<String, Value>

Get factory configuration