Skip to main content

TaskService

Struct TaskService 

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

Use-case orchestration over the A2A ports.

Constructed at the composition edge with concrete adapters injected; the fields are Arc<dyn …> so the service type carries no generic parameters. All methods return domain types and A2AError — there is no transport vocabulary in this layer.

Implementations§

Source§

impl TaskService

Source

pub fn new( message_handler: impl AsyncMessageHandler + 'static, tasks: impl AsyncTaskLifecycle + AsyncTaskQuery + 'static, notification_manager: impl AsyncNotificationManager + 'static, agent_info: impl AgentInfoProvider + 'static, streaming_handler: impl AsyncStreamingHandler + 'static, push_notifier: impl AsyncPushNotifier + 'static, ) -> Self

Assemble a service from separate handlers.

tasks supplies both the lifecycle and query capabilities; it is stored once and shared between the two Arc<dyn …> fields.

Source

pub fn with_handler( handler: impl AsyncMessageHandler + AsyncTaskLifecycle + AsyncTaskQuery + AsyncNotificationManager + 'static, agent_info: impl AgentInfoProvider + 'static, streaming_handler: impl AsyncStreamingHandler + 'static, push_notifier: impl AsyncPushNotifier + 'static, ) -> Self

Assemble a service from a single handler that implements every port.

Source

pub fn with_streaming_handler( self, streaming_handler: impl AsyncStreamingHandler + 'static, ) -> Self

Replace the streaming handler, returning the updated service.

Source

pub fn with_push_notifier( self, push_notifier: impl AsyncPushNotifier + 'static, ) -> Self

Replace the push notifier, returning the updated service.

Source

pub fn with_send_wait(self, send_wait: Duration) -> Self

How long a blocking SendMessage waits for the task to settle before returning it unsettled. Defaults to 25s.

Raise it for agents that legitimately take minutes — but raise the calling client’s request timeout with it. The two are a pair: whichever is shorter decides what the caller sees, and if the client gives up first it gets a transport error instead of the task.

Source

pub async fn send_message( &self, task_id: &str, message: &Message, session_id: Option<&str>, opts: SendOptions, ) -> Result<Task, A2AError>

Process a message for a task, optionally configuring push notifications and limiting the returned history.

With SendCompletion::WhenSettled — the spec default — the response is held until the task reaches a terminal or interrupted state, bounded by with_send_wait. The wait is driven by the streaming handler rather than a poll loop: it already broadcasts every transition, so a subscriber is the wait.

Two ordering details are load-bearing. The subscription is opened before process_message, because a handler that finishes synchronously (the echo responder does) broadcasts its terminal event during that call — subscribing afterwards would miss it and then wait for a transition that has already happened. And the task is re-fetched after the wait rather than assembled from the event, because the event carries a status, not the artifacts and history the caller asked for.

Source

pub async fn send_streaming_message( &self, task_id: &str, message: &Message, session_id: Option<&str>, push_config: Option<TaskPushNotificationConfig>, history_limit: Option<u32>, ) -> Result<(Task, UpdateStream), A2AError>

Process a message and subscribe to its update stream.

The update stream is started before the message is processed so no early updates are missed. Returns the initial task and the stream; the caller is responsible for emitting the initial task ahead of stream items.

The stream ends once the task settles (see [until_settled]), so a caller that reads to completion is not left holding an open connection to a finished task.

Source

pub async fn get( &self, id: &TaskId, history_length: Option<u32>, ) -> Result<Task, A2AError>

Get a task by ID with optional history length limit.

Source

pub async fn list( &self, params: &ListTasksParams, ) -> Result<ListTasksResult, A2AError>

List tasks with filtering and pagination.

Source

pub async fn cancel(&self, id: &TaskId) -> Result<Task, A2AError>

Cancel a task, then announce the terminal status to streaming subscribers.

Storage no longer self-broadcasts on cancellation (§4.0.2), so the service owns the “commit then announce” step via the TaskStatusBroadcast mixin it hosts.

Source

pub async fn subscribe( &self, task_id: &str, from_event_id: Option<u64>, ) -> Result<(Option<Task>, UpdateStream), A2AError>

Subscribe to a task’s update stream, returning the current task (if it exists) and the stream of subsequent updates.

from_event_id carries a client’s Last-Event-ID for resumption: when set, the handler replays buffered events with a greater id before streaming live updates.

The stream ends once the task settles (see [until_settled]). If the task is already terminal and no resumption point was given, the caller gets its snapshot and an empty stream, because nothing further can ever be broadcast for it.

That short-circuit is conditional on from_event_id being unset, and that condition is load-bearing: resuming after a disconnect on a task that has since finished is precisely when the replay buffer matters — the events the client missed are the ones it reconnected for. Skipping the handler because the task looks finished would turn resumption into silence.

A task already sitting in an interrupted state (INPUT_REQUIRED, AUTH_REQUIRED) deliberately does not short-circuit: it resumes under the same id once the caller supplies what it asked for, and a subscriber that attached first is entitled to watch that happen. The asymmetry with UpdateEvent::settles_task is the point — arriving at an interrupted state ends a stream, finding one already there does not.

Source

pub async fn set_push_config( &self, config: &TaskPushNotificationConfig, ) -> Result<TaskPushNotificationConfig, A2AError>

Create or replace a push-notification config (validated).

Source

pub async fn get_push_config( &self, params: &GetTaskPushNotificationConfigParams, ) -> Result<TaskPushNotificationConfig, A2AError>

Get a push-notification config for a task.

Source

pub async fn list_push_configs( &self, params: &ListTaskPushNotificationConfigsParams, ) -> Result<Vec<TaskPushNotificationConfig>, A2AError>

List push-notification configs for a task.

Source

pub async fn delete_push_config( &self, params: &DeleteTaskPushNotificationConfigParams, ) -> Result<(), A2AError>

Delete a push-notification config.

Source

pub async fn extended_agent_card(&self) -> Result<AgentCard, A2AError>

Fetch the authenticated extended agent card.

Trait Implementations§

Source§

impl Clone for TaskService

Source§

fn clone(&self) -> TaskService

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 HasPushNotifier for TaskService

Source§

impl HasStreaming for TaskService

Source§

impl HasTaskLifecycle for TaskService

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<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> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> TaskStatusBroadcast for T

Source§

fn update_and_broadcast<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 TaskId, state: TaskState, message: Option<Message>, ) -> Pin<Box<dyn Future<Output = Result<Task, A2AError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Update a task’s status, then broadcast the new status to subscribers. Read more
Source§

fn cancel_and_broadcast<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 TaskId, ) -> Pin<Box<dyn Future<Output = Result<Task, A2AError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Cancel a task through the lifecycle port, then broadcast the resulting (terminal) status to subscribers. Read more
Source§

fn broadcast_artifact<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 TaskId, event: TaskArtifactUpdateEvent, ) -> Pin<Box<dyn Future<Output = Result<(), A2AError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Broadcast an artifact update: fan it out to streaming subscribers, then deliver it to the task’s push endpoint (best-effort). Read more
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