Skip to main content

a2a_rs/
lib.rs

1//! A Rust implementation of the Agent-to-Agent (A2A) Protocol
2//!
3//! This library provides a type-safe, idiomatic Rust implementation of the A2A protocol,
4//! with support for both client and server roles. The implementation follows a hexagonal
5//! architecture with clear separation between domains, ports, and adapters.
6//!
7//! # Features
8//!
9//! - Complete implementation of the A2A protocol
10//! - Support for HTTP and WebSocket transport
11//! - Support for streaming updates
12//! - Async and sync interfaces
13//! - Feature flags for optional dependencies
14//!
15//! # Examples
16//!
17//! ## Creating a client
18//!
19//! ```rust,no_run
20//! # #[cfg(feature = "http-client")]
21//! # {
22//! use a2a_rs::{HttpClient, Message};
23//! use a2a_rs::services::AsyncA2AClient;
24//!
25//! #[tokio::main]
26//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
27//!     // Create a client
28//!     let client = HttpClient::new("https://example.com/api".to_string());
29//!
30//!     // Send a task message
31//!     let message = Message::user_text("Hello, world!".to_string(), "msg-123".to_string());
32//!     let task = client.send_task_message("task-123", &message, None, None).await?;
33//!
34//!     println!("Task: {:?}", task);
35//!     Ok(())
36//! }
37//! # }
38//! ```
39//!
40//! ## Creating a server
41//!
42//! ```rust,ignore
43//! use a2a_rs::{HttpServer, SimpleAgentInfo, DefaultRequestProcessor};
44//! use my_app::{MyMessageHandler, MyTaskManager, MyNotificationManager};
45//!
46//! #[tokio::main]
47//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
48//!     // Create custom handlers that implement the required traits
49//!     let message_handler = MyMessageHandler::new();
50//!     let task_manager = MyTaskManager::new();
51//!     let notification_manager = MyNotificationManager::new();
52//!     let agent_info = SimpleAgentInfo::new("my-agent".to_string(), "https://api.example.com".to_string());
53//!
54//!     // Create a request processor with your handlers
55//!     let processor = DefaultRequestProcessor::new(
56//!         message_handler,
57//!         task_manager,
58//!         notification_manager,
59//!         agent_info.clone(),
60//!     );
61//!
62//!     // Create and start the server
63//!     let server = HttpServer::new(
64//!         processor,
65//!         agent_info,
66//!         "127.0.0.1:8080".to_string(),
67//!     );
68//!     server.start().await?;
69//!     Ok(())
70//! }
71//! ```
72
73// Re-export key modules and types
74pub mod adapter;
75pub mod application;
76pub mod domain;
77pub mod port;
78pub mod services;
79
80#[cfg(feature = "tracing")]
81pub mod observability;
82
83// Public API exports
84pub use domain::{
85    A2AError, AgentCapabilities, AgentCard, AgentCardSignature, AgentExtension, AgentInterface,
86    AgentProvider, AgentSkill, Artifact, AuthorizationCodeOAuthFlow, ClientCredentialsOAuthFlow,
87    DeleteTaskPushNotificationConfigParams, FileContent, GetTaskPushNotificationConfigParams,
88    ImplicitOAuthFlow, ListTaskPushNotificationConfigParams, ListTasksParams, ListTasksResult,
89    Message, MessageSendConfiguration, MessageSendParams, OAuthFlows, Part, PasswordOAuthFlow,
90    PushNotificationAuthenticationInfo, PushNotificationConfig, Role, SecurityScheme, Task,
91    TaskArtifactUpdateEvent, TaskIdParams, TaskPushNotificationConfig, TaskQueryParams,
92    TaskSendParams, TaskState, TaskStatus, TaskStatusUpdateEvent, TransportProtocol,
93};
94
95// Port traits for better separation of concerns
96pub use port::{
97    AsyncMessageHandler, AsyncNotificationManager, AsyncStreamingHandler, AsyncTaskManager,
98    MessageHandler, NotificationManager, StreamingHandler, StreamingSubscriber, TaskManager,
99    UpdateEvent,
100};
101
102#[cfg(feature = "http-client")]
103pub use adapter::HttpClient;
104
105#[cfg(feature = "ws-client")]
106pub use adapter::WebSocketClient;
107
108#[cfg(feature = "http-server")]
109pub use adapter::HttpServer;
110
111#[cfg(feature = "ws-server")]
112pub use adapter::WebSocketServer;
113
114#[cfg(feature = "server")]
115pub use adapter::{
116    DefaultRequestProcessor, InMemoryTaskStorage, NoopPushNotificationSender,
117    PushNotificationRegistry, PushNotificationSender, SimpleAgentInfo,
118};
119
120#[cfg(all(feature = "server", feature = "http-client"))]
121pub use adapter::HttpPushNotificationSender;
122
123#[cfg(any(feature = "http-server", feature = "ws-server"))]
124pub use adapter::{ApiKeyAuthenticator, BearerTokenAuthenticator, NoopAuthenticator};
125#[cfg(feature = "auth")]
126pub use adapter::{JwtAuthenticator, OAuth2Authenticator, OpenIdConnectAuthenticator};
127#[cfg(any(feature = "http-server", feature = "ws-server"))]
128pub use port::Authenticator;