pub struct Task {
pub id: TaskId,
pub thread_id: String,
pub status: TaskStatus,
pub message: Message,
pub messages: Vec<Message>,
pub artifacts: Vec<Artifact>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub error: Option<String>,
pub metadata: Option<Value>,
}Expand description
A task in the A2A protocol.
Tasks are the primary unit of work in A2A. They are submitted by clients and processed by agents.
Fields§
§id: TaskIdUnique identifier for this task.
thread_id: StringThread ID for grouping related tasks.
status: TaskStatusCurrent status of the task.
message: MessageThe original message that created this task.
messages: Vec<Message>Messages in the conversation.
artifacts: Vec<Artifact>Artifacts produced by the task.
created_at: DateTime<Utc>When the task was created.
updated_at: DateTime<Utc>When the task was last updated.
error: Option<String>Optional error message if the task failed.
metadata: Option<Value>Optional metadata.
Implementations§
Source§impl Task
impl Task
Sourcepub fn new(thread_id: impl Into<String>, message: Message) -> Self
pub fn new(thread_id: impl Into<String>, message: Message) -> Self
Create a new task.
The original message is automatically added to the messages list.
Sourcepub fn with_id(
id: impl Into<String>,
thread_id: impl Into<String>,
message: Message,
) -> Self
pub fn with_id( id: impl Into<String>, thread_id: impl Into<String>, message: Message, ) -> Self
Create a new task with a specific ID.
The original message is automatically added to the messages list.
Sourcepub fn is_pending(&self) -> bool
pub fn is_pending(&self) -> bool
Check if the task is pending.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Check if the task is running.
Sourcepub fn is_completed(&self) -> bool
pub fn is_completed(&self) -> bool
Check if the task is completed (success or failure).
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Check if the task succeeded.
Sourcepub fn start(&mut self) -> Result<(), TaskError>
pub fn start(&mut self) -> Result<(), TaskError>
Mark the task as running.
§Errors
Returns TaskError::InvalidStateTransition if the task is not pending.
Sourcepub fn complete(&mut self) -> Result<(), TaskError>
pub fn complete(&mut self) -> Result<(), TaskError>
Mark the task as completed.
§Errors
Returns TaskError::InvalidStateTransition if the task is not running.
Sourcepub fn fail(&mut self, error: impl Into<String>) -> Result<(), TaskError>
pub fn fail(&mut self, error: impl Into<String>) -> Result<(), TaskError>
Mark the task as failed.
§Errors
Returns TaskError::InvalidStateTransition if the task is not running.
Sourcepub fn cancel(&mut self) -> Result<(), TaskError>
pub fn cancel(&mut self) -> Result<(), TaskError>
Mark the task as cancelled.
Cancellation is allowed from pending or running states.
§Errors
Returns TaskError::InvalidStateTransition if the task is already completed.
Sourcepub fn force_status(&mut self, status: TaskStatus)
pub fn force_status(&mut self, status: TaskStatus)
Force set status without validation (for internal/recovery use).
Use with caution - this bypasses state transition validation.
Sourcepub fn add_message(&mut self, message: Message)
pub fn add_message(&mut self, message: Message)
Add a message to the task.
Sourcepub fn add_artifact(&mut self, artifact: Artifact)
pub fn add_artifact(&mut self, artifact: Artifact)
Add an artifact to the task.
Sourcepub fn set_metadata(&mut self, metadata: Value)
pub fn set_metadata(&mut self, metadata: Value)
Set metadata on the task.