Expand description
Rig agents over the Agent2Agent (A2A) protocol, version 1.0, both ways:
serve a Rig 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.
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:
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)
}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.
Re-exports§
pub use a2a;Non- target_family=wasmpub use a2a_client;Non- target_family=wasmpub use a2a_server;Non- target_family=wasmpub use axum;Non- target_family=wasmpub use rig_memory;Non- target_family=wasm
Structs§
- A2aExecutor
Non- target_family=wasm - A Rig
Agentas an A2AAgentExecutor. - A2aServer
Non- target_family=wasm - A Rig agent served over A2A: its agent card, its task store, and the
router
into_routerbuilds from them. - Agent
Extension Non- target_family=wasm - The A2A extension a card declares, for
A2aServer::extension. A protocol extension supported by the agent. - Remote
Agent Non- target_family=wasm - An A2A agent reached over the network.
- Remote
Agent Builder Non- target_family=wasm - Options for
RemoteAgent: a bearer token, extensions to activate, and a timeout. - Remote
File Non- target_family=wasm - A file in an answer.
- Reply
Non- target_family=wasm - One answer from a remote agent.
Enums§
- File
Content Non- target_family=wasm - Where a
RemoteFile’s bytes are. - Remote
Error Non- target_family=wasm - Why a remote agent could not be reached or did not answer.
- Reply
Event Non- target_family=wasm - What
RemoteAgent::streamreports while an answer is written.
Constants§
- DEFAULT_
HISTORY_ TOKENS Non- target_family=wasm - How many tokens of history a request sends by default.
- DEFAULT_
MAX_ CONCURRENT_ TASKS Non- target_family=wasm - How many tasks run at once by default; more are rejected as busy.
- DEFAULT_
MAX_ CONTEXTS Non- target_family=wasm - How many conversations the in-memory store remembers by default.
- DEFAULT_
MAX_ REQUEST_ BYTES Non- target_family=wasm - The largest request body a server reads by default: 2 MiB.
- DEFAULT_
MAX_ RUN_ DURATION Non- target_family=wasm - How long one run may take by default before it is stopped.
- DEFAULT_
TIMEOUT Non- target_family=wasm - How long a remote agent may stay silent before a call gives up, unless told otherwise: the whole wait without streaming, the gap between two events with it.
- JSONRPC_
PATH Non- target_family=wasm - The path of the JSON-RPC binding under the server’s base URL.
- REST_
PATH Non- target_family=wasm - The path of the HTTP+JSON binding under the server’s base URL.
- V03_
PATH Non- target_family=wasm - Where the v0.3 surface is mounted under the server’s base URL.
Functions§
- activated_
extensions Non- target_family=wasm - The declared A2A extensions the request of the current agent run activated, sorted and without repeats.