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::port::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());
    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};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a server with default implementations
    let server = HttpServer::new(
        DefaultRequestProcessor::new(),
        SimpleAgentInfo::new("my-agent".to_string(), "1.0.0".to_string()),
        "127.0.0.1:8080".to_string(),
    );

    // Start the server
    server.start().await?;
    Ok(())
}

Re-exports§

pub use domain::A2AError;
pub use domain::AgentCapabilities;
pub use domain::AgentCard;
pub use domain::AgentProvider;
pub use domain::AgentSkill;
pub use domain::Artifact;
pub use domain::AuthorizationCodeOAuthFlow;
pub use domain::ClientCredentialsOAuthFlow;
pub use domain::FileContent;
pub use domain::ImplicitOAuthFlow;
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 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