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::domain::SendCompletion;
24//! use a2a_rs::Transport;
25//!
26//! #[tokio::main]
27//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
28//!     // Create a client
29//!     let client = HttpClient::new("https://example.com/api".to_string());
30//!
31//!     // Send a task message
32//!     let message = Message::user_text("Hello, world!".to_string(), "msg-123".to_string());
33//!     // `SendCompletion::WhenSettled` is the A2A default: the server holds the
34//!     // response until the task finishes, so `task` carries the agent's reply.
35//!     // `None` for the task id starts a new task the server names; pass
36//!     // `Some(id)` to continue one the caller already holds.
37//!     let task = client
38//!         .send_task_message(None, &message, None, None, SendCompletion::WhenSettled)
39//!         .await?;
40//!
41//!     println!("Task: {:?}", task);
42//!     Ok(())
43//! }
44//! # }
45//! ```
46//!
47//! ## Creating a server
48//!
49//! ```rust,ignore
50//! use a2a_rs::{HttpServer, SimpleAgentInfo, ConnectRpcAdapter};
51//! use my_app::{MyMessageHandler, MyTaskManager, MyNotificationManager};
52//!
53//! #[tokio::main]
54//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
55//!     // Create custom handlers that implement the required traits
56//!     let message_handler = MyMessageHandler::new();
57//!     let task_manager = MyTaskManager::new();
58//!     let notification_manager = MyNotificationManager::new();
59//!     let agent_info = SimpleAgentInfo::new("my-agent".to_string(), "https://api.example.com".to_string());
60//!
61//!     // Wrap your handlers in the ConnectRPC transport adapter
62//!     let adapter = ConnectRpcAdapter::new(
63//!         message_handler,
64//!         task_manager,
65//!         notification_manager,
66//!         agent_info.clone(),
67//!     );
68//!
69//!     // Create and start the server
70//!     let server = HttpServer::new(
71//!         adapter,
72//!         agent_info,
73//!         "127.0.0.1:8080".to_string(),
74//!     );
75//!     server.start().await?;
76//!     Ok(())
77//! }
78//! ```
79
80// Re-export key modules and types
81pub mod adapter;
82pub mod application;
83pub mod domain;
84pub mod port;
85pub mod services;
86
87#[cfg(feature = "tracing")]
88pub mod observability;
89
90// Public API exports
91pub use domain::{
92    A2AError, AgentCapabilities, AgentCard, AgentCardSignature, AgentExtension, AgentInterface,
93    AgentProvider, AgentSkill, Artifact, AuthorizationCodeOAuthFlow, ClientCredentialsOAuthFlow,
94    ContextId, DeleteTaskPushNotificationConfigParams, DeviceCodeOAuthFlow, ErrorDetail, ErrorInfo,
95    FieldViolation, GetTaskPushNotificationConfigParams, ListTaskPushNotificationConfigsParams,
96    ListTasksParams, ListTasksResult, Message, OAuthFlows, Part, PushConfigId,
97    PushNotificationAuthenticationInfo, ReadRefresh, Result, RetentionPolicy, RetryPolicy, Role,
98    SecurityScheme, Swept, Task, TaskArtifactUpdateEvent, TaskId, TaskIdParams,
99    TaskPushNotificationConfig, TaskQueryParams, TaskState, TaskStatus, TaskStatusUpdateEvent,
100    VersionedTask,
101};
102
103// Port traits for better separation of concerns
104pub use port::{
105    AsyncMessageHandler, AsyncNotificationManager, AsyncNotificationManagerExt, AsyncPushNotifier,
106    AsyncRetention, AsyncStreamingHandler, AsyncTaskLifecycle, AsyncTaskLifecycleExt,
107    AsyncTaskQuery, AsyncTaskVersioning, CallContext, CallInterceptor, CallSide, NoopPushNotifier,
108    RequestContext, SeqEvent, StreamEvent, StreamItem, StreamingSubscriber, Transport, UpdateEvent,
109};
110
111#[cfg(feature = "http-client")]
112pub use adapter::HttpClient;
113
114#[cfg(feature = "jsonrpc-client")]
115pub use adapter::JsonRpcClient;
116
117#[cfg(feature = "client")]
118pub use adapter::{ClientConfig, TransportFactory, TransportNegotiator, default_registry};
119
120#[cfg(feature = "client")]
121pub use adapter::{RetryingTransport, subscribe_resilient};
122
123#[cfg(any(feature = "http-client", feature = "jsonrpc-client"))]
124pub use adapter::{
125    auto_connect, auto_connect_with, connect, connect_with, fetch_agent_card, fetch_agent_card_with,
126};
127
128#[cfg(feature = "http-server")]
129pub use adapter::HttpServer;
130
131#[cfg(feature = "server")]
132pub use adapter::{
133    ConnectRpcAdapter, InMemoryStreamingHandler, InMemoryTaskStorage, NoopPushNotificationSender,
134    NoopStreamingHandler, PushNotificationRegistry, PushNotificationSender, SimpleAgentInfo,
135};
136
137#[cfg(all(feature = "server", feature = "http-client"))]
138pub use adapter::HttpPushNotificationSender;
139
140#[cfg(feature = "http-server")]
141pub use adapter::{ApiKeyAuthenticator, BearerTokenAuthenticator, NoopAuthenticator};
142#[cfg(feature = "auth")]
143pub use adapter::{JwtAuthenticator, OAuth2Authenticator, OpenIdConnectAuthenticator};
144#[cfg(feature = "http-server")]
145pub use port::Authenticator;
146
147#[cfg(feature = "tracing")]
148pub use adapter::LoggingInterceptor;