Skip to main content

Crate zeph_a2a

Crate zeph_a2a 

Source
Expand description

A2A (Agent-to-Agent) protocol client, server, and agent discovery for Zeph.

This crate implements the A2A protocol — a JSON-RPC 2.0 based specification for communication between AI agents. It provides:

  • Client (A2aClient): sends messages and streams responses to remote A2A agents.
  • Server (A2aServer, feature server): exposes an HTTP endpoint that accepts A2A JSON-RPC requests and streams Server-Sent Events (SSE) for real-time output.
  • Discovery (AgentRegistry): fetches and caches agent capability cards from /.well-known/agent.json with configurable TTL.
  • Capability cards (AgentCardBuilder): builds AgentCard metadata describing the agent’s skills, I/O modes, and protocol version.
  • IBCT (Ibct, feature ibct): Invocation-Bound Capability Tokens for scoped delegation — HMAC-SHA256 signed tokens bound to a specific task and endpoint.
  • JSON-RPC 2.0 types (jsonrpc): request/response envelope types and the A2A method name constants.
  • Protocol types (types): shared wire-format types re-exported at the crate root.

§Architecture

zeph-a2a is an optional feature-gated dependency of the main zeph binary. The A2aServer is started as a background service when [a2a] is enabled in config. The AgentRegistry verifies a peer’s AgentCard (signature + URL-origin trust policy, A2A 1.0.0 §8.4) before zeph --connect <URL> establishes a session via A2aClient (#6200); see src/tui_remote.rs in the zeph binary crate for the wiring.

§Features

FeatureDescription
serverEnables A2aServer, TaskManager, and TaskProcessor
ibctEnables Ibct token issuance and verification (HMAC-SHA256)
card-signingEnables card_signing::verify_card_signatures and [card_signing::sign_card] (JWS/ES256 over RFC 8785 JCS). Without it, AgentCardSignature/signatures still (de)serialize, but verification always returns SignatureVerification::FeatureDisabled.

§Examples

use zeph_a2a::{A2aClient, AgentCardBuilder, AgentRegistry, SendMessageParams, Message};
use std::time::Duration;

// Build an agent card for this agent.
let card = AgentCardBuilder::new("my-agent", "http://localhost:8080", "0.1.0")
    .description("A helpful AI agent")
    .streaming(true)
    .build();

// Discover a peer agent's capabilities.
let registry = AgentRegistry::new(reqwest::Client::new(), Duration::from_secs(300));
let peer_card = registry.discover("http://peer-agent.example.com").await?;

// Send a message to the peer agent.
let client = A2aClient::new_insecure(reqwest::Client::new());
let params = SendMessageParams {
    message: Message::user_text("Hello, peer agent!"),
    configuration: None,
};
let task = client.send_message(&peer_card.url, params, None).await?;
println!("Task {} in state {:?}", task.id, task.status.state);

Re-exports§

pub use card::AgentCardBuilder;
pub use card_signing::SigAlg;
pub use card_signing::SignatureVerification;
pub use card_signing::TrustedKey;
pub use client::A2aClient;
pub use client::SecurityPolicy;
pub use client::TaskEvent;
pub use client::TaskEventStream;
pub use discovery::AgentRegistry;
pub use discovery::CardTrustPolicy;
pub use error::A2aError;
pub use ibct::Ibct;
pub use ibct::IbctError;
pub use ibct::IbctKey;
pub use jsonrpc::SendMessageParams;
pub use types::*;

Modules§

card
Builder for AgentCard capability advertisement documents.
card_signing
JWS signature verification for AgentCards (A2A 1.0.0 §8.4).
client
A2A protocol HTTP client with optional TLS enforcement and SSRF protection.
discovery
Agent discovery via /.well-known/agent.json with TTL-based caching, plus optional card-signature and URL-origin trust checks (A2A 1.0.0 §8.4, #5928).
error
Error types for A2A client, server, and discovery operations.
ibct
Invocation-Bound Capability Tokens (IBCT) for A2A delegation.
jsonrpc
JSON-RPC 2.0 envelope types and A2A method constants.
types
Wire-format types for the A2A protocol.

Constants§

A2A_PROTOCOL_VERSION
A2A protocol version implemented by this crate.