Expand description
A task delegated to another agent, cancelled with its parent.
A2A has no link between a task and the tasks its agent creates on other
agents: cancelling a parent does nothing to its children unless the
parent’s code cancels each one. Measured in examples/swarm, every child
was left running when its root was cancelled and the orchestrator had not
written that cascade itself (docs/swarm-orchestration.md, G1).
A Delegation is that cascade, written once. It sends the child as a
stream, learns the child’s task id from the first event that names it, and
sends CancelTask for the child when
- the parent asks it to —
cancel, or thecancelfuture given towaitcompleting; - the child’s stream is lost before the child settled and could not be
resumed (see
ResumePolicy), since nothing is left watching it; or - the handle is dropped before the child settled — the parent’s own task was aborted, or its code returned early.
A child settles when it reaches a terminal state, or an interrupted one
(input-required, auth-required): then it is waiting for the parent,
not running, and the parent decides what happens next.
On its own it does not cover a parent that crashes: the handle dies
with the process. start_leased does. It
grants the child a lease (a2a_protocol_types::lease, ADR 0020) and
renews it every third of its time to live while the handle lives, and
an agent that grants leases stops a child whose lease lapses. A parent
that crashes, hangs, is partitioned away, or detaches
stops renewing, and its child stops within the time to live.
start_budgeted sends the child a budget
carved out of the parent’s (a2a_protocol_types::budget, ADR 0023): a
deadline inside the parent’s and meters reserved from it. When the child
settles on a status update that reports its spend, the parent is charged
that instead of the reservation; every other ending refunds nothing.
Every start gives the child’s message an idempotency key
(a2a_protocol_types::idempotency, ADR 0026) when the message has none,
whatever the client believes of the agent (DEC-08). Against an agent known
to honour keys (A2aClient::honours_idempotency) a client with a retry
policy retries a send that failed ambiguously without starting a second
child; against any agent that honours them, the same message sent again
with the handle’s idempotency_key reaches
the child the first created (after Outcome::Lost with no task id, say),
and a journal record’s key does the same after a restart
(DelegationOptions::resending). A server of this SDK whose store
cannot honour keys refuses the key, typed, before it runs anything; a key
the start added is then taken off and the message sent once more.
use std::sync::Arc;
use a2a_protocol_client::{ClientBuilder, delegation::{Delegation, Outcome}};
use a2a_protocol_types::{Message, MessageSendParams, Part};
let worker = Arc::new(ClientBuilder::new("http://worker:8080").build()?);
let params = MessageSendParams::new(Message::user("m-1", vec![Part::text("summarise")]));
let child = Delegation::start(worker, params).await?;
let done = child.wait(async { let _ = parent_cancelled.await; }).await;
match done.outcome {
Outcome::Completed(_) => println!("child {:?} finished", done.task_id),
other => println!("child {:?}: {other:?}", done.task_id),
}Structs§
- Child
Steering - What became of the message sent to one child by
steer_all. - Delegated
- A delegation that has ended: the child’s id, if it was learned, and its outcome.
- Delegation
- A child task sent to another agent, which is cancelled if its parent stops watching it. See the module docs.
- Delegation
Options - What a delegation is given beyond its message: a lease, a budget, a
journal record, how a lost stream is resumed. Nothing is set by default,
which is
Delegation::start. - Hand
OffPolicy - How a delegation continues a child whose turn was handed back.
- Resume
Policy - How a
Delegationtries to get its stream back before it gives up on the child. The default is five attempts, 200 ms apart at first and doubling to 5 s, inside 30 s in all. - Steer
Handle - Steers one child, from anywhere.
Enums§
Constants§
- DEFAULT_
ID_ WAIT - How long a cancel waits for the child’s id, when it is asked for before the first event named the child.
- HAND_
OFF_ METADATA_ KEY - The status-message metadata key a server marks a handed-back turn with
(the server crate’s
executor::HAND_OFF_METADATA_KEY).
Functions§
- steer_
all - Steers each of
childrenat once, with a message made bymessagefor each (a message needs its own id, so the closure is called once per child), and returns what became of each, in the order given.