Skip to main content

Delegation

Struct Delegation 

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

A child task sent to another agent, which is cancelled if its parent stops watching it. See the module docs.

Implementations§

Source§

impl Delegation

Source

pub async fn start_journaled( client: Arc<A2aClient>, params: MessageSendParams, journal: Arc<dyn DelegationJournal>, owner: impl Into<String> + Send, agent: impl Into<String> + Send, ) -> Result<Delegation, ClientError>

start, recorded in journal first.

The record (owner, the agent’s URL, the tenant, the message’s idempotency key) is written before the message is sent. If the journal cannot store it, nothing is sent. The child’s id and stream position are noted as events arrive, at most every two seconds, and the record is settled with the delegation’s outcome when it ends.

A supervisor that restarts lists its open records (DelegationJournal::open) and picks each up: with reattach and with_journal when the record names the child, or by sending the same message again under the record’s idempotency key when it does not. The key is recorded only when the message carries one, which start adds for an agent known to honour keys; set one on the message for any other.

§Errors

As start; also the journal’s error, as ClientError::Protocol, when the record cannot be written. When the agent refuses the request the record is settled not_started: no child exists.

Source

pub fn with_journal( self, journal: Arc<dyn DelegationJournal>, record_id: impl Into<String>, ) -> Delegation

Keeps record_id, a record in journal, up to date from here on: for a delegation picked up with reattach from a record DelegationJournal::open listed.

Source

pub fn journal_id(&self) -> Option<&str>

The id of this delegation’s journal record, if it has one.

Source§

impl Delegation

Source

pub async fn start_with( client: Arc<A2aClient>, params: MessageSendParams, options: DelegationOptions, ) -> Result<Delegation, ClientError>

start with every part of options at once: a lease renewed until the handle ends, a budget settled when it does, a journal record written before the message is sent.

§Errors

As start; also the journal’s error, as ClientError::Protocol, when the record cannot be written (nothing is sent then), and ClientError::Config when options names an existing journal record, which only reattach_with can keep, or resends for a record whose child was named, or that has no key to resend under. When the agent refuses the request, a budget reservation is returned and a new record is settled not_started: no child exists. A resent record’s is left open: an earlier send may have made a child.

Source

pub async fn reattach_with( client: Arc<A2aClient>, tenant: Option<String>, task_id: impl Into<String> + Send, last_event_id: Option<String>, options: DelegationOptions, ) -> Result<Delegation, ClientError>

reattach with the lease, the journal record, the resume policy and the id wait of options: the child is picked up with its lease renewed again, from the moment the handle exists, and its record kept up to date.

A lease the child was granted before the restart lapses after its time to live without a renewal; a supervisor that restarts must reattach, and so start renewing, inside it. A budget grant cannot be restored: the parent’s meter died with the process, and the reservation was kept as spent.

§Errors

As reattach; also ClientError::Config when options carries a budget, or a new journal record (which is written before a message is sent, and a reattach sends none).

Source

pub async fn start_leased( client: Arc<A2aClient>, params: MessageSendParams, ttl: Duration, ) -> Result<Delegation, ClientError>

start, granting the child a lease of ttl and renewing it every third of ttl until this handle settles, is cancelled, is detached or is dropped (see the module docs). The agent must grant leases (its card declares a2a_protocol_types::lease::LEASE_EXTENSION_URI); one that does not ignores the grant, and the child runs as with start.

§Errors

As start; an agent that grants leases also refuses a ttl outside its bounds.

Source

pub async fn start_budgeted( client: Arc<A2aClient>, params: MessageSendParams, grant: ChildGrant, lease: Option<Duration>, ) -> Result<Delegation, ClientError>

start with grant, a budget carved out of the parent’s by BudgetHandle::grant, and a lease of lease as start_leased grants one when it is Some.

When the handle ends, the grant is settled. If the status update that settled the child (terminal or interrupted) carried a budget report, the parent is charged that spend instead of the reservation. Any other ending (a lost stream, a cancel answered by CancelTask, an unreachable child), a report-less update, or a handle detached or dropped keeps the whole reservation as spent. An agent that does not implement the extension reports nothing.

§Errors

As start. The reservation is returned only when the error shows the agent refused the request, so no child exists: an A2A error, an HTTP error status, an authentication challenge, or an endpoint the client cannot use. After a transport error or a timeout a child may be running, and the reservation is kept.

Source§

impl Delegation

Source

pub const fn with_resume(self, policy: ResumePolicy) -> Delegation

Sets how a lost stream is resumed; see ResumePolicy.

Source

pub fn last_event_id(&self) -> Option<&str>

The position of the last event received: the id to resume from, to record with task_id before detach so that reattach can pick the child up again. None until an event carried one, and always None on gRPC and WebSocket streams.

Source

pub async fn reattach( client: Arc<A2aClient>, tenant: Option<String>, task_id: impl Into<String>, last_event_id: Option<String>, ) -> Result<Delegation, ClientError>

Follows a child that is already running, from the position last_event_id (or from its current state when None): a supervisor that recorded task_id and last_event_id before it stopped picks the child up after a restart.

A child that has settled in the meantime returns a handle that is already settled, so wait answers at once with what it became. The handle owns the child again: dropped unsettled, it cancels. A lease or budget grant is not restored (ADR 0030).

§Errors

The subscription’s error when the stream cannot be opened and the child’s state cannot be read to show it settled. No handle exists then, and nothing is cancelled.

Source§

impl Delegation

Source

pub fn steer_handle(&self) -> Option<SteerHandle>

A handle that steers this child from anywhere (SteerHandle), once an event has named the child; None before that.

Source

pub async fn steer(&self, message: Message) -> Result<Steering, ClientError>

Sends message to the child’s running task, so its executor can read it between steps; see SteerHandle::steer for what is added to the message and how it can be refused.

The child must have been named by an event (next_event, or task_id answering Some): nothing is sent before that.

§Errors

ClientError::Transport when the child has not been named yet; SteerHandle::steer’s otherwise.

Source§

impl Delegation

Source

pub async fn start( client: Arc<A2aClient>, params: MessageSendParams, ) -> Result<Delegation, ClientError>

Sends params as a streaming message and returns the handle following it. Nothing is cancelled until the handle is asked to, or dropped.

The message is given a fresh idempotency key when it has none (see the module docs); a key already on the message is kept.

§Errors

Returns the client’s error when the stream cannot be opened. No child was created then, or none whose id the agent told us.

Source

pub fn idempotency_key(&self) -> Option<&str>

The idempotency key the child’s message carried: the caller’s, or the one start gave it. The same message sent with it reaches the same child.

Source

pub const fn with_id_wait(self, wait: Duration) -> Delegation

Sets how long a cancel waits for the child’s id when none has been seen yet (DEFAULT_ID_WAIT by default). The child exists from the moment the agent accepts the message; until its first event arrives, only waiting for that event can name it.

Source

pub fn task_id(&self) -> Option<&str>

The child’s task id, once an event has named it.

Source

pub const fn is_settled(&self) -> bool

Whether the child has settled — terminal, interrupted, or answered with a message — so that dropping the handle cancels nothing.

Source

pub async fn next_event( &mut self, ) -> Option<Result<StreamResponse, ClientError>>

The child’s next event, for a parent that wants to see them; the handle keeps track of the child’s id and state either way. None when the stream has ended.

Source

pub async fn wait<F>(self, cancel: F) -> Delegated
where F: Future<Output = ()>,

Follows the child until it settles, or until cancel completes — then the child is cancelled and the outcome is what CancelTask reported.

A stream that ends before the child settled is resumed first, from the last event id, under the ResumePolicy; a child found settled meanwhile is reported as what it became. Only a child still running after the policy is spent is cancelled, with Outcome::Lost.

Source

pub async fn wait_or_hand_off<C, H>(self, cancel: C, hand_off: H) -> Delegated
where C: Future<Output = ()>, H: Future<Output = ()>,

wait for a supervisor that is shut down on purpose and must not take its children with it.

cancel is the parent being cancelled: the child is cancelled, as wait does. hand_off is the supervisor being shut down (the signal it passes to Server::serve_with_shutdown, for one). When it completes and the delegation keeps a journal record (see start_journaled) and the child has been named, the child is left running, the record is left open at the position the stream reached, and the outcome is Outcome::HandedOff: the next supervisor lists its open records (DelegationJournal::open) and reattaches. With no journal there is nothing to find the child by, so it is cancelled. When both futures are ready, hand_off wins: a graceful shutdown fires the executor’s cancellation token as well as the supervisor’s own signal, and must not be read as the parent’s cancel.

A child’s lease, if it has one, stops being renewed with this handle; the next supervisor renews it (see reattach_with) before its time to live runs out.

Source

pub async fn cancel(self) -> Delegated

Cancels the child now, unless it has already settled. If its id is not yet known, reads its stream for up to the id wait to learn it.

Source

pub fn detach(self) -> Option<String>

Stops following the child without cancelling it, and returns its id if known. From here the caller is responsible for the child — for instance a supervisor that records the id and last_event_id durably and reattaches after a restart.

Trait Implementations§

Source§

impl Debug for Delegation

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for Delegation

Source§

fn drop(&mut self)

Cancels an unsettled child in the background, on the current Tokio runtime. Outside a runtime nothing can be sent, and the drop is only logged.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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
§

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

§

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

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

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

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

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
§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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