Skip to main content

Task

Struct Task 

Source
pub struct Task {
    pub id: TaskId,
    pub context_id: ContextId,
    pub status: TaskStatus,
    pub history: Option<Vec<Message>>,
    pub artifacts: Option<Vec<Artifact>>,
    pub metadata: Option<Value>,
}
Expand description

A unit of work managed by an A2A agent.

The wire kind field ("task") is injected by enclosing discriminated unions such as crate::events::StreamResponse and crate::responses::SendMessageResponse. Standalone Task values received over the wire may include kind; serde silently tolerates unknown fields, so no action is needed on the receiving side.

Fields§

§id: TaskId

Unique task identifier.

§context_id: ContextId

Conversation context this task belongs to.

§status: TaskStatus

Current status of the task.

§history: Option<Vec<Message>>

Historical messages exchanged during this task.

§artifacts: Option<Vec<Artifact>>

Artifacts produced by this task.

§metadata: Option<Value>

Arbitrary metadata.

Implementations§

Source§

impl Task

Source

pub fn new( id: impl Into<TaskId>, context_id: impl Into<ContextId>, status: TaskStatus, ) -> Task

A task in status, with no history, artifacts or metadata — what a custom store or a test builds.

The struct is not #[non_exhaustive], so a literal still compiles; this is the form that keeps compiling when a field is added (N16).

use a2a_protocol_types::task::{Task, TaskState, TaskStatus};

let task = Task::new("t1", "c1", TaskStatus::new(TaskState::Working));
assert_eq!(task.id.as_ref(), "t1");
assert!(task.artifacts.is_none());
Source

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

Returns the text of the first text Part in this task’s artifacts, or None if it produced no text.

Reading the answer out of a finished task is what a caller does with every delegated result, and Task previously had no inherent methods at all, so each caller wrote the walk by hand. Six files under examples/ had written the same artifacts → first → text chain.

This skips artifacts with no text rather than stopping at the first, which is where it differs from the hand-written chain: a task whose first artifact is a file and whose second is text yields that text here and None from artifacts.first().and_then(Artifact::text). It is the same rule Message::text already applies across parts.

It reads artifacts only. A failure reason lives on the status message instead, at task.status.message.

use a2a_protocol_types::artifact::Artifact;
use a2a_protocol_types::message::Part;
use a2a_protocol_types::task::{ContextId, Task, TaskState, TaskStatus};

let task = Task {
    id: "t1".into(),
    context_id: ContextId::new("c1"),
    status: TaskStatus::new(TaskState::Completed),
    history: None,
    artifacts: Some(vec![
        Artifact::new("chart", vec![Part::url("https://example.com/c.png")]),
        Artifact::new("summary", vec![Part::text("revenue rose 4%")]),
    ]),
    metadata: None,
};

assert_eq!(task.text(), Some("revenue rose 4%"));
Source

pub fn failure_class(&self) -> Option<FailureClass>

Why this task failed, when the agent classified it.

Reads the class off the status message, so a caller can branch on a value rather than on prose:

match task.failure_class() {
    Some(c) if c.is_retryable() => { /* back off and try again */ }
    Some(c) if c.needs_human()  => { /* escalate, do not retry */ }
    _ => { /* give up, or inspect `task.status.message` */ }
}

None means the agent classified nothing — an older peer, or one that does not implement the extension. It does not mean the task succeeded; status says that.

Source

pub fn texts(&self) -> impl Iterator<Item = &str>

Returns the text of every text Part across every artifact, in order.

Use this when a task may produce several textual artifacts and Task::text would silently drop all but the first.

Trait Implementations§

Source§

impl Clone for Task

Source§

fn clone(&self) -> Task

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 Debug for Task

Source§

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

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

impl<'de> Deserialize<'de> for Task

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Task, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Task

Source§

impl PartialEq for Task

Source§

fn eq(&self, other: &Task) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Task

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Task

Source§

impl TryFrom<Task> for Task

Source§

type Error = ConvertError

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

fn try_from(value: Task) -> Result<Task, <Task as TryFrom<Task>>::Error>

Performs the conversion.
Source§

impl TryFrom<Task> for Task

Source§

type Error = ConvertError

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

fn try_from(value: Task) -> Result<Task, <Task as TryFrom<Task>>::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl Freeze for Task

§

impl RefUnwindSafe for Task

§

impl Send for Task

§

impl Sync for Task

§

impl Unpin for Task

§

impl UnsafeUnpin for Task

§

impl UnwindSafe for Task

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> FutureExt for T

Source§

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

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

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

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

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

impl<L> LayerExt<L> for L

Source§

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

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> 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 = !

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