a2a-rs 0.1.0

Rust implementation of the Agent-to-Agent (A2A) Protocol
Documentation

a2a-rs

Crates.io Documentation License: MIT

A Rust implementation of the Agent-to-Agent (A2A) Protocol, providing a type-safe, idiomatic way to build agent communication systems.

Features

  • 🚀 Complete A2A Protocol Implementation - Full support for the A2A specification
  • 🔄 Multiple Transport Options - HTTP and WebSocket support
  • 📡 Streaming Updates - Real-time task and artifact updates
  • 🔐 Authentication & Security - JWT, OAuth2, OpenID Connect support
  • 💾 Persistent Storage - SQLx integration for task persistence
  • 🎯 Async-First Design - Built on Tokio with async/await throughout
  • 🧩 Modular Architecture - Use only the features you need
  • Type Safety - Leverages Rust's type system for protocol compliance

Quick Start

Add to your Cargo.toml:

[dependencies]
a2a-rs = "0.1.0"

# For HTTP client
a2a-rs = { version = "0.1.0", features = ["http-client"] }

# For HTTP server
a2a-rs = { version = "0.1.0", features = ["http-server"] }

# Full feature set
a2a-rs = { version = "0.1.0", features = ["full"] }

Client Example

use a2a_rs::{HttpClient, Message};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = HttpClient::new("https://api.example.com".to_string());
    
    let message = Message::user_text("Hello, agent!".to_string());
    let task = client.send_task_message("task-123", &message, None, None).await?;
    
    println!("Task created: {:?}", task);
    Ok(())
}

Server Example

use a2a_rs::{HttpServer, Message, Task, A2AError};
use a2a_rs::port::{AsyncTaskHandler, AgentInfoProvider};

struct MyAgent;

#[async_trait::async_trait]
impl AsyncTaskHandler for MyAgent {
    async fn handle_message(
        &self,
        task_id: &str,
        message: &Message,
        session_id: Option<&str>,
    ) -> Result<Task, A2AError> {
        // Process the message and return updated task
        Ok(Task::new(task_id.to_string()))
    }
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let server = HttpServer::new(
        MyAgent,
        AgentInfo::default(),
        "127.0.0.1:8080".to_string(),
    );
    
    server.start().await?;
    Ok(())
}

Architecture

This library follows a hexagonal architecture pattern:

  • Domain: Core business logic and types
  • Ports: Trait definitions for external dependencies
  • Adapters: Concrete implementations for different transports and storage

Feature Flags

  • client - Client-side functionality
  • server - Server-side functionality
  • http-client - HTTP client implementation
  • http-server - HTTP server implementation
  • ws-client - WebSocket client implementation
  • ws-server - WebSocket server implementation
  • auth - Authentication support (JWT, OAuth2, OpenID Connect)
  • sqlx-storage - SQLx-based persistent storage
  • sqlite - SQLite database support
  • postgres - PostgreSQL database support
  • mysql - MySQL database support
  • tracing - Structured logging and tracing
  • full - All features enabled

Examples

See the examples directory for complete working examples:

Documentation

Full API documentation is available on docs.rs.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.