Skip to main content

A2AProtocol

Struct A2AProtocol 

Source
pub struct A2AProtocol { /* private fields */ }
Expand description

A2A Protocol handler for inter-agent communication.

Implementations§

Source§

impl A2AProtocol

Source

pub const MAX_LOG_ENTRIES: usize = 10_000

Maximum number of log entries retained before pruning.

Source

pub fn new(event_bus: EventBus) -> Self

Creates a new A2A protocol handler.

Source

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.

Source

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.

Source

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.

Source

pub fn registry(&self) -> &AgentCardRegistry

Returns the agent card registry.

Source

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.

Source

pub async fn send_message( &self, from: AgentId, to: AgentId, message: A2AMessage, ) -> Result<Uuid>

Sends a message from one agent to another.

Source

pub async fn delegate_task( &self, from: AgentId, to: AgentId, task: TaskSpec, ) -> Result<Uuid>

Delegates a task from one agent to another.

Source

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.

Source

pub async fn share_result( &self, from: AgentId, to: AgentId, task_id: Uuid, result: Value, summary: String, ) -> Result<Uuid>

Shares a result from one agent to another.

Source

pub async fn query_capabilities( &self, capability: &str, ) -> Result<Vec<AgentCard>>

Queries the registry for agents that can perform a capability.

Source

pub async fn send_handshake(&self, from: AgentId, to: AgentId) -> Result<Uuid>

Initiates a handshake with another agent.

Source

pub async fn receive_messages(&self, agent_id: AgentId) -> Vec<A2ARequest>

Receives all pending messages for an agent, draining the queue.

Source

pub async fn pending_count(&self, agent_id: AgentId) -> usize

Returns the number of pending messages for an agent.

Source

pub async fn has_messages(&self, agent_id: AgentId) -> bool

Returns true if the agent has any pending messages.

Source

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.

Source

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

Source§

fn clone(&self) -> A2AProtocol

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for A2AProtocol

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more