Skip to main content

Crate a2a_rs

Crate a2a_rs 

Source
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::services::AsyncA2AClient;

#[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, DefaultRequestProcessor};
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());

    // Create a request processor with your handlers
    let processor = DefaultRequestProcessor::new(
        message_handler,
        task_manager,
        notification_manager,
        agent_info.clone(),
    );

    // Create and start the server
    let server = HttpServer::new(
        processor,
        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::DeleteTaskPushNotificationConfigParams;
pub use domain::FileContent;
pub use domain::GetTaskPushNotificationConfigParams;
pub use domain::ImplicitOAuthFlow;
pub use domain::ListTaskPushNotificationConfigParams;
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::PasswordOAuthFlow;
pub use domain::PushNotificationAuthenticationInfo;
pub use domain::PushNotificationConfig;
pub use domain::Role;
pub use domain::SecurityScheme;
pub use domain::Task;
pub use domain::TaskArtifactUpdateEvent;
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::TransportProtocol;
pub use port::AsyncMessageHandler;
pub use port::AsyncNotificationManager;
pub use port::AsyncStreamingHandler;
pub use port::AsyncTaskManager;
pub use port::MessageHandler;
pub use port::NotificationManager;
pub use port::StreamingHandler;
pub use port::StreamingSubscriber;
pub use port::TaskManager;
pub use port::UpdateEvent;
pub use adapter::DefaultRequestProcessor;
pub use adapter::InMemoryTaskStorage;
pub use adapter::NoopPushNotificationSender;
pub use adapter::PushNotificationRegistry;
pub use adapter::PushNotificationSender;
pub use adapter::SimpleAgentInfo;

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