pub struct A2AProtocol { /* private fields */ }Expand description
A2A Protocol handler for inter-agent communication.
Implementations§
Source§impl A2AProtocol
impl A2AProtocol
Sourcepub const MAX_LOG_ENTRIES: usize = 10_000
pub const MAX_LOG_ENTRIES: usize = 10_000
Maximum number of log entries retained before pruning.
Sourcepub async fn set_delegation_handler(&self, handler: DelegationHandler)
pub async fn set_delegation_handler(&self, handler: DelegationHandler)
Register a handler that executes delegated tasks.
When a TaskDelegation message arrives and a handler is set,
the protocol spawns a background task to execute it and sends
the result back as a ResultSharing message.
Sourcepub fn get_message_log(&self, limit: Option<usize>) -> Vec<A2AMessageLogEntry>
pub fn get_message_log(&self, limit: Option<usize>) -> Vec<A2AMessageLogEntry>
Returns recent message log entries, most recent last.
If limit is Some(n), returns at most the last n entries.
Sourcepub fn recent_messages(&self, secs: u64) -> Vec<A2AMessageLogEntry>
pub fn recent_messages(&self, secs: u64) -> Vec<A2AMessageLogEntry>
Returns message-log entries whose timestamp is within the last
secs seconds, most recent last.
Used by the topology endpoint to derive edges from a sliding window of recent activity.
Sourcepub fn registry(&self) -> &AgentCardRegistry
pub fn registry(&self) -> &AgentCardRegistry
Returns the agent card registry.
Sourcepub async fn execute_delegation(
&self,
from: AgentId,
to: AgentId,
task: TaskSpec,
) -> Option<Result<Value>>
pub async fn execute_delegation( &self, from: AgentId, to: AgentId, task: TaskSpec, ) -> Option<Result<Value>>
Execute a delegated task through the registered handler (blocking).
Also enqueues the delegation message and publishes events for audit trail purposes, then calls the handler directly and waits.
Returns None if no handler is registered.
Sourcepub async fn send_message(
&self,
from: AgentId,
to: AgentId,
message: A2AMessage,
) -> Result<Uuid>
pub async fn send_message( &self, from: AgentId, to: AgentId, message: A2AMessage, ) -> Result<Uuid>
Sends a message from one agent to another.
Sourcepub async fn delegate_task(
&self,
from: AgentId,
to: AgentId,
task: TaskSpec,
) -> Result<Uuid>
pub async fn delegate_task( &self, from: AgentId, to: AgentId, task: TaskSpec, ) -> Result<Uuid>
Delegates a task from one agent to another.
Sourcepub async fn send_status_update(
&self,
from: AgentId,
to: AgentId,
task_id: Uuid,
progress: u8,
message: String,
) -> Result<Uuid>
pub async fn send_status_update( &self, from: AgentId, to: AgentId, task_id: Uuid, progress: u8, message: String, ) -> Result<Uuid>
Sends a status update from one agent to another.
Shares a result from one agent to another.
Sourcepub async fn query_capabilities(
&self,
capability: &str,
) -> Result<Vec<AgentCard>>
pub async fn query_capabilities( &self, capability: &str, ) -> Result<Vec<AgentCard>>
Queries the registry for agents that can perform a capability.
Sourcepub async fn send_handshake(&self, from: AgentId, to: AgentId) -> Result<Uuid>
pub async fn send_handshake(&self, from: AgentId, to: AgentId) -> Result<Uuid>
Initiates a handshake with another agent.
Sourcepub async fn receive_messages(&self, agent_id: AgentId) -> Vec<A2ARequest>
pub async fn receive_messages(&self, agent_id: AgentId) -> Vec<A2ARequest>
Receives all pending messages for an agent, draining the queue.
Sourcepub async fn pending_count(&self, agent_id: AgentId) -> usize
pub async fn pending_count(&self, agent_id: AgentId) -> usize
Returns the number of pending messages for an agent.
Sourcepub async fn has_messages(&self, agent_id: AgentId) -> bool
pub async fn has_messages(&self, agent_id: AgentId) -> bool
Returns true if the agent has any pending messages.
Sourcepub async fn deliver_pending_messages(
&self,
agent_id: AgentId,
) -> Result<Vec<A2ARequest>>
pub async fn deliver_pending_messages( &self, agent_id: AgentId, ) -> Result<Vec<A2ARequest>>
Deliver all pending messages to an agent.
Unlike receive_messages (which drains the queue silently),
this method does NOT re-publish MessageReceived events since
they were already published when the messages were originally sent.
Sourcepub async fn send_and_wait(
&self,
from: AgentId,
to: AgentId,
message: A2AMessage,
timeout: Duration,
) -> Result<A2AResponse>
pub async fn send_and_wait( &self, from: AgentId, to: AgentId, message: A2AMessage, timeout: Duration, ) -> Result<A2AResponse>
Send a message and wait for a response within a timeout.
Uses tokio::select! with Notify instead of polling.
Matches ResultSharing messages by checking if task_id equals the
delegated task’s ID (not the envelope request_id). This works because
delegate_task creates a TaskDelegation { task_id: task.task_id, ... }
message, and the handler responds with ResultSharing { task_id: task.task_id }.
Trait Implementations§
Source§impl Clone for A2AProtocol
impl Clone for A2AProtocol
Source§fn clone(&self) -> A2AProtocol
fn clone(&self) -> A2AProtocol
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more