Expand description
Why a task failed, as something a caller can match on.
§The gap this closes
A failed task is TaskState::Failed
plus an error message: prose, written by whoever wrote the executor. A
caller deciding what to do next is matching English.
The decisions are genuinely different, and getting them wrong is visible as bad agent behaviour to whoever is watching:
| Class | What a caller should do |
|---|---|
InvalidRequest | Never retry. Fix the request. |
Transient | Retry with backoff. |
PolicyRefusal | Stop and escalate to a human. |
BudgetExhausted | Retry with more budget, or not at all. |
Internal | The agent broke. Retry once, then escalate. |
Without this an orchestrator either retries what can never succeed or abandons what would have worked on the second attempt.
§Wire shape
Not part of A2A v1.0, so it ships as the declared extension
https://a2a-rust.com/extensions/failure/v1. Message.extensions is a
list of URIs and cannot carry a value, so the class travels in
Message.metadata under a2a-rust.com/failure while extensions
declares the URI — the same split
idempotency uses, for the same reason.
It rides on the status message of the failed task, which is the spec’s field for “additional status updates for the client” and the one place a caller already looks when a task fails.
An unrecognised class reads as FailureClass::Internal rather than an
error. A peer that classifies more finely than this enum should not make
its failures unreadable, and “something went wrong at the agent” is true
of every class a future version could add.
use a2a_protocol_types::failure::{FailureClass, class_of, set_class};
use a2a_protocol_types::message::Message;
let mut status = Message::agent_text("m1", "upstream model refused the prompt");
set_class(&mut status, FailureClass::PolicyRefusal);
assert_eq!(class_of(&status), Some(FailureClass::PolicyRefusal));
assert!(!class_of(&status).expect("set above").is_retryable());Enums§
- Failure
Class - What kind of failure a task ended in.
Constants§
- FAILURE_
EXTENSION_ URI - The extension URI a card declares and a message names in
extensions. - FAILURE_
METADATA_ KEY - The
Message.metadatakey the class travels under.
Functions§
- class_
of - Reads the class off a status message, if one was recorded.
- declares_
extension - Whether a message declares the failure extension in
extensions. - error_
class - The class a failed task gets when its executor returned
error. - set_
class - Records the class on a status message, declaring the extension URI.
- set_
error_ class - Records a class on an error, for an executor that fails by returning
Errrather than by emitting its ownFailedstatus.