pub struct Task {
pub id: Arc<str>,
pub context_id: Option<Arc<str>>,
pub status: TaskStatus,
pub artifacts: Vec<Artifact>,
pub history: Vec<Message>,
pub metadata: BTreeMap<String, Value>,
}Expand description
A unit of work an A2A agent tracks.
Wire form:
{
"id": "task-123",
"contextId": "context-456",
"status": { "state": "working" },
"artifacts": [...],
"history": [...],
"metadata": {...}
}Fields§
§id: Arc<str>The task’s id. Required and unique within the agent.
context_id: Option<Arc<str>>An optional context id. A context groups related tasks (a multi-turn conversation is a context; each user turn is a task within that context). The spec does not require contexts; an agent that does not support them leaves the field off the wire.
status: TaskStatusThe task’s current status.
artifacts: Vec<Artifact>The task’s output. An empty list is a task that has not produced any output yet (or a task whose output is empty by design).
history: Vec<Message>The conversation history that produced
the task. A task created from a single
SendMessage request has a one-element
history; a task created from a streaming
interaction has more.
metadata: BTreeMap<String, Value>Per-task metadata. The spec leaves the
shape open; the conventional keys are
"trace_id", "session_id", and the
custom names a particular deployment
uses.
Implementations§
Source§impl Task
impl Task
Sourcepub fn new(id: impl Into<Arc<str>>) -> Self
pub fn new(id: impl Into<Arc<str>>) -> Self
Starts a new task in
Submitted state
with id. Use with_status
to advance the state, with_artifact
to attach an output, and so on.
Sourcepub fn with_status(self, status: TaskStatus) -> Self
pub fn with_status(self, status: TaskStatus) -> Self
Replaces the task’s status. The task is
consumed; chain
Task::new(id).with_status(...).with_artifact(...)
to build a task in one expression.
Sourcepub fn with_artifact(self, artifact: impl Into<Artifact>) -> Self
pub fn with_artifact(self, artifact: impl Into<Artifact>) -> Self
Appends an artifact to the task.
Sourcepub fn with_history_message(self, message: impl Into<Message>) -> Self
pub fn with_history_message(self, message: impl Into<Message>) -> Self
Appends a message to the history.