Expand description
A Rust implementation of the Agent-to-Agent (A2A) Protocol
This library provides a type-safe, idiomatic Rust implementation of the A2A protocol, with support for both client and server roles. The implementation follows a hexagonal architecture with clear separation between domains, ports, and adapters.
§Features
- Complete implementation of the A2A protocol
- Support for HTTP and WebSocket transport
- Support for streaming updates
- Async and sync interfaces
- Feature flags for optional dependencies
§Examples
§Creating a client
use a2a_rs::{HttpClient, Message};
use a2a_rs::Transport;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a client
let client = HttpClient::new("https://example.com/api".to_string());
// Send a task message
let message = Message::user_text("Hello, world!".to_string(), "msg-123".to_string());
let task = client.send_task_message("task-123", &message, None, None).await?;
println!("Task: {:?}", task);
Ok(())
}§Creating a server
ⓘ
use a2a_rs::{HttpServer, SimpleAgentInfo, ConnectRpcAdapter};
use my_app::{MyMessageHandler, MyTaskManager, MyNotificationManager};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create custom handlers that implement the required traits
let message_handler = MyMessageHandler::new();
let task_manager = MyTaskManager::new();
let notification_manager = MyNotificationManager::new();
let agent_info = SimpleAgentInfo::new("my-agent".to_string(), "https://api.example.com".to_string());
// Wrap your handlers in the ConnectRPC transport adapter
let adapter = ConnectRpcAdapter::new(
message_handler,
task_manager,
notification_manager,
agent_info.clone(),
);
// Create and start the server
let server = HttpServer::new(
adapter,
agent_info,
"127.0.0.1:8080".to_string(),
);
server.start().await?;
Ok(())
}Re-exports§
pub use domain::A2AError;pub use domain::AgentCapabilities;pub use domain::AgentCard;pub use domain::AgentCardSignature;pub use domain::AgentExtension;pub use domain::AgentInterface;pub use domain::AgentProvider;pub use domain::AgentSkill;pub use domain::Artifact;pub use domain::AuthorizationCodeOAuthFlow;pub use domain::ClientCredentialsOAuthFlow;pub use domain::ContextId;pub use domain::DeleteTaskPushNotificationConfigParams;pub use domain::DeviceCodeOAuthFlow;pub use domain::ErrorDetail;pub use domain::ErrorInfo;pub use domain::FieldViolation;pub use domain::GetTaskPushNotificationConfigParams;pub use domain::ListTaskPushNotificationConfigsParams;pub use domain::ListTasksParams;pub use domain::ListTasksResult;pub use domain::Message;pub use domain::MessageSendConfiguration;pub use domain::MessageSendParams;pub use domain::OAuthFlows;pub use domain::Part;pub use domain::PushConfigId;pub use domain::PushNotificationAuthenticationInfo;pub use domain::Result;pub use domain::RetryPolicy;pub use domain::Role;pub use domain::SecurityScheme;pub use domain::Task;pub use domain::TaskArtifactUpdateEvent;pub use domain::TaskId;pub use domain::TaskIdParams;pub use domain::TaskPushNotificationConfig;pub use domain::TaskQueryParams;pub use domain::TaskSendParams;pub use domain::TaskState;pub use domain::TaskStatus;pub use domain::TaskStatusUpdateEvent;pub use domain::VersionedTask;pub use port::AsyncMessageHandler;pub use port::AsyncNotificationManager;pub use port::AsyncNotificationManagerExt;pub use port::AsyncPushNotifier;pub use port::AsyncStreamingHandler;pub use port::AsyncTaskLifecycle;pub use port::AsyncTaskLifecycleExt;pub use port::AsyncTaskQuery;pub use port::AsyncTaskVersioning;pub use port::CallContext;pub use port::CallInterceptor;pub use port::CallSide;pub use port::NoopPushNotifier;pub use port::SeqEvent;pub use port::StreamEvent;pub use port::StreamItem;pub use port::StreamingSubscriber;pub use port::Transport;pub use port::UpdateEvent;pub use adapter::HttpClient;pub use adapter::JsonRpcClient;pub use adapter::TransportFactory;pub use adapter::TransportNegotiator;pub use adapter::default_registry;pub use adapter::RetryingTransport;pub use adapter::subscribe_resilient;pub use adapter::connect;pub use adapter::fetch_agent_card;pub use adapter::HttpServer;pub use adapter::ConnectRpcAdapter;pub use adapter::InMemoryStreamingHandler;pub use adapter::InMemoryTaskStorage;pub use adapter::NoopPushNotificationSender;pub use adapter::NoopStreamingHandler;pub use adapter::PushNotificationRegistry;pub use adapter::PushNotificationSender;pub use adapter::SimpleAgentInfo;pub use adapter::HttpPushNotificationSender;pub use adapter::ApiKeyAuthenticator;pub use adapter::BearerTokenAuthenticator;pub use adapter::NoopAuthenticator;pub use adapter::JwtAuthenticator;pub use adapter::OAuth2Authenticator;pub use adapter::OpenIdConnectAuthenticator;pub use port::Authenticator;pub use adapter::LoggingInterceptor;
Modules§
- adapter
- Adapters for the A2A protocol
- application
- Application services for the A2A protocol
- domain
- Domain models for the A2A protocol
- observability
- Observability and logging utilities for a2a-rs
- port
- Ports (interfaces) for the A2A protocol
- services
- Service layer for the A2A protocol
Macros§
- log_
error - Helper macros for consistent error logging
- measure_
duration - Helper macro for performance tracking