rig_a2a/lib.rs
1//! Rig agents over the Agent2Agent (A2A) protocol, version 1.0, both ways:
2//! serve a Rig [`Agent`](rig_agent::Agent) to any A2A client with
3//! [`A2aServer`], and call any A2A agent from a Rig agent as a tool with
4//! [`RemoteAgent`].
5//!
6//! [`A2aServer`] builds the agent card and an Axum router with the JSON-RPC
7//! and HTTP+JSON bindings, streaming over server-sent events, and task get,
8//! list and cancel. The protocol itself comes from the official A2A Rust SDK,
9//! re-exported as [`a2a`] and [`a2a_server`].
10//!
11//! Each message starts a task. The reply streams into one text artifact and
12//! the task completes, fails, or is canceled. Messages that share a
13//! `contextId` share the agent's conversation history, which lives in memory
14//! for the life of the server. [`A2aExecutor`] is the same agent as an
15//! [`a2a_server::AgentExecutor`] for a handler you assemble yourself.
16//!
17//! ```no_run
18//! use rig_a2a::A2aServer;
19//! use rig_agent::AgentBuilder;
20//! use rig_core::providers::openai::{self, OpenAI};
21//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
22//! let model = OpenAI::from_env()?.completion(openai::GPT_5_4_MINI);
23//! let agent = AgentBuilder::new(model).name("helper").build();
24//! let app = A2aServer::new(agent, "http://localhost:3000").into_router();
25//! let listener = tokio::net::TcpListener::bind("localhost:3000").await?;
26//! rig_a2a::axum::serve(listener, app).await?;
27//! # Ok(())
28//! # }
29//! ```
30
31#![cfg_attr(docsrs, feature(doc_cfg))]
32#![cfg_attr(
33 test,
34 allow(
35 clippy::expect_used,
36 clippy::panic,
37 clippy::unwrap_used,
38 clippy::unreachable
39 )
40)]
41
42// The A2A server stack (axum, tokio, hyper) runs on native targets only.
43#[cfg(target_family = "wasm")]
44compile_error!(
45 "rig-a2a is native-only: it serves agents over HTTP with the A2A SDK's \
46 axum server. Disable the `a2a` feature for wasm targets."
47);
48
49#[cfg(not(target_family = "wasm"))]
50mod client;
51#[cfg(not(target_family = "wasm"))]
52mod executor;
53#[cfg(not(target_family = "wasm"))]
54mod history;
55#[cfg(all(feature = "otel", not(target_family = "wasm")))]
56mod otel;
57#[cfg(not(target_family = "wasm"))]
58mod parts;
59#[cfg(not(target_family = "wasm"))]
60mod server;
61#[cfg(not(target_family = "wasm"))]
62mod v03;
63
64#[cfg(not(target_family = "wasm"))]
65pub use client::{
66 DEFAULT_TIMEOUT, FileContent, RemoteAgent, RemoteAgentBuilder, RemoteError, RemoteFile, Reply,
67 ReplyEvent,
68};
69#[cfg(not(target_family = "wasm"))]
70pub use executor::{A2aExecutor, DEFAULT_MAX_CONCURRENT_TASKS, DEFAULT_MAX_RUN_DURATION};
71#[cfg(not(target_family = "wasm"))]
72pub use history::{DEFAULT_HISTORY_TOKENS, DEFAULT_MAX_CONTEXTS};
73#[cfg(not(target_family = "wasm"))]
74pub use server::{A2aServer, DEFAULT_MAX_REQUEST_BYTES, JSONRPC_PATH, REST_PATH};
75#[cfg(not(target_family = "wasm"))]
76pub use v03::V03_PATH;
77
78/// The A2A protocol types this crate is built against.
79#[cfg(not(target_family = "wasm"))]
80pub use a2a;
81/// The A2A client this crate is built against.
82#[cfg(not(target_family = "wasm"))]
83pub use a2a_client;
84/// The A2A server framework this crate is built against.
85#[cfg(not(target_family = "wasm"))]
86pub use a2a_server;
87/// The Axum version the router is built with, for `axum::serve`.
88#[cfg(not(target_family = "wasm"))]
89pub use axum;
90/// The session stores and history windows conversations are kept with.
91#[cfg(not(target_family = "wasm"))]
92pub use rig_memory;
93
94#[cfg(all(test, not(target_family = "wasm")))]
95mod tests;