1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//! Rig agents over the Agent2Agent (A2A) protocol, version 1.0, both ways:
//! serve a Rig [`Agent`](rig_agent::Agent) to any A2A client with
//! [`A2aServer`], and call any A2A agent from a Rig agent as a tool with
//! [`RemoteAgent`].
//!
//! [`A2aServer`] builds the agent card and an Axum router with the JSON-RPC
//! and HTTP+JSON bindings, streaming over server-sent events, and task get,
//! list and cancel. The protocol itself comes from the official A2A Rust SDK,
//! re-exported as [`a2a`] and [`a2a_server`].
//!
//! Each message starts a task. The reply streams into one text artifact and
//! the task completes, fails, or is canceled. Messages that share a
//! `contextId` share the agent's conversation history, which lives in memory
//! for the life of the server. [`A2aExecutor`] is the same agent as an
//! [`a2a_server::AgentExecutor`] for a handler you assemble yourself.
//!
//! ```no_run
//! use rig_a2a::A2aServer;
//! use rig_agent::AgentBuilder;
//! use rig_core::providers::openai::{self, OpenAI};
//!
//! async fn serve() -> Result<(), Box<dyn std::error::Error>> {
//! let model = OpenAI::from_env()?.completion(openai::GPT_5_4_MINI);
//! let agent = AgentBuilder::new(model).name("helper").build();
//! let app = A2aServer::new(agent, "http://localhost:3000").into_router();
//! let listener = tokio::net::TcpListener::bind("localhost:3000").await?;
//! rig_a2a::axum::serve(listener, app).await?;
//! Ok(())
//! }
//! ```
//!
//! `examples/a2a_serve.rs` runs this with a model from the environment.
//!
//! Ask a remote A2A agent directly, or give it to a model as a tool:
//!
//! ```no_run
//! use rig_a2a::RemoteAgent;
//!
//! async fn ask(question: &str) -> Result<String, Box<dyn std::error::Error>> {
//! let remote = RemoteAgent::connect("http://127.0.0.1:3000").await?;
//! let reply = remote.send(question, None).await?;
//! Ok(reply.text)
//! }
//! ```
//!
//! ```no_run
//! use rig_a2a::RemoteAgent;
//! use rig_agent::AgentBuilder;
//!
//! async fn as_tool(builder: AgentBuilder) -> Result<rig_agent::Agent, Box<dyn std::error::Error>> {
//! let remote = RemoteAgent::connect("http://127.0.0.1:3000").await?;
//! // One turn is the default, so allow the tool call and the answer.
//! Ok(builder.dynamic_tool(remote.into_tool()?).default_max_turns(4).build())
//! }
//! ```
//!
//! `examples/call.rs` streams an answer from any A2A agent, and
//! `examples/remote_tool.rs` runs the tool case end to end.
//!
//! Prompts and replies go on the trace only when the agent records them, with
//! `AgentBuilder::record_content_telemetry(true)`. It is off by default, as in Rig.
// The A2A server stack (axum, tokio, hyper) runs on native targets only.
compile_error!;
/// The A2A extension a card declares, for [`A2aServer::extension`].
pub use AgentExtension;
pub use ;
pub use ;
pub use ;
pub use ;
pub use V03_PATH;
/// The A2A protocol types this crate is built against.
pub use a2a;
/// The A2A client this crate is built against.
pub use a2a_client;
/// The A2A server framework this crate is built against.
pub use a2a_server;
/// The Axum version the router is built with, for `axum::serve`.
pub use axum;
/// The session stores and history windows conversations are kept with.
pub use rig_memory;