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
impl Delegation
Sourcepub 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>
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.
Sourcepub fn with_journal(
self,
journal: Arc<dyn DelegationJournal>,
record_id: impl Into<String>,
) -> Delegation
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.
Sourcepub fn journal_id(&self) -> Option<&str>
pub fn journal_id(&self) -> Option<&str>
The id of this delegation’s journal record, if it has one.
Source§impl Delegation
impl Delegation
Sourcepub async fn start_with(
client: Arc<A2aClient>,
params: MessageSendParams,
options: DelegationOptions,
) -> Result<Delegation, ClientError>
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.
Sourcepub 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>
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).
Sourcepub async fn start_leased(
client: Arc<A2aClient>,
params: MessageSendParams,
ttl: Duration,
) -> Result<Delegation, ClientError>
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.
Sourcepub async fn start_budgeted(
client: Arc<A2aClient>,
params: MessageSendParams,
grant: ChildGrant,
lease: Option<Duration>,
) -> Result<Delegation, ClientError>
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
impl Delegation
Sourcepub const fn with_resume(self, policy: ResumePolicy) -> Delegation
pub const fn with_resume(self, policy: ResumePolicy) -> Delegation
Sets how a lost stream is resumed; see ResumePolicy.
Sourcepub fn last_event_id(&self) -> Option<&str>
pub fn last_event_id(&self) -> Option<&str>
Sourcepub async fn reattach(
client: Arc<A2aClient>,
tenant: Option<String>,
task_id: impl Into<String>,
last_event_id: Option<String>,
) -> Result<Delegation, ClientError>
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
impl Delegation
Sourcepub fn steer_handle(&self) -> Option<SteerHandle>
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.
Sourcepub async fn steer(&self, message: Message) -> Result<Steering, ClientError>
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
impl Delegation
Sourcepub async fn start(
client: Arc<A2aClient>,
params: MessageSendParams,
) -> Result<Delegation, ClientError>
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.
Sourcepub fn idempotency_key(&self) -> Option<&str>
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.
Sourcepub const fn with_id_wait(self, wait: Duration) -> Delegation
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.
Sourcepub const fn is_settled(&self) -> bool
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.
Sourcepub async fn next_event(
&mut self,
) -> Option<Result<StreamResponse, ClientError>>
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.
Sourcepub async fn wait<F>(self, cancel: F) -> Delegated
pub async fn wait<F>(self, cancel: F) -> Delegated
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.
Sourcepub async fn wait_or_hand_off<C, H>(self, cancel: C, hand_off: H) -> Delegated
pub async fn wait_or_hand_off<C, H>(self, cancel: C, hand_off: H) -> Delegated
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.
Trait Implementations§
Source§impl Debug for Delegation
impl Debug for Delegation
Auto Trait Implementations§
impl !RefUnwindSafe for Delegation
impl !UnwindSafe for Delegation
impl Forget for Delegation
impl Freeze for Delegation
impl Move for Delegation
impl Send for Delegation
impl Sync for Delegation
impl Unpin for Delegation
impl UnsafeUnpin for Delegation
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].