pub struct Task {
pub id: String,
pub context_id: String,
pub status: TaskStatus,
pub artifacts: Option<Vec<Artifact>>,
pub history: Option<Vec<Message>>,
pub metadata: Option<Map<String, Value>>,
pub kind: String,
}
Expand description
A task in the A2A protocol with status, history, and artifacts.
Tasks represent units of work that agents process. Each task has:
- A unique ID and context ID for tracking
- Current status including state and optional message
- Optional artifacts produced during processing
- Optional message history for the conversation
- Optional metadata for additional context
§Example
use a2a_rs::{Task, TaskStatus, TaskState};
let task = Task::builder()
.id("task-123".to_string())
.context_id("ctx-456".to_string())
.status(TaskStatus {
state: TaskState::Working,
message: None,
timestamp: None,
})
.build();
Fields§
§id: String
§context_id: String
§status: TaskStatus
§artifacts: Option<Vec<Artifact>>
§history: Option<Vec<Message>>
§metadata: Option<Map<String, Value>>
§kind: String
Implementations§
Source§impl Task
impl Task
Sourcepub fn builder() -> TaskBuilder
pub fn builder() -> TaskBuilder
Create an instance of Task
using the builder syntax
Source§impl Task
impl Task
Sourcepub fn new(id: String, context_id: String) -> Self
pub fn new(id: String, context_id: String) -> Self
Create a new task with the given ID in the submitted state
Sourcepub fn with_context(id: String, context_id: String) -> Self
pub fn with_context(id: String, context_id: String) -> Self
Create a new task with the given ID and context ID in the submitted state
Sourcepub fn update_status(&mut self, state: TaskState, message: Option<Message>)
pub fn update_status(&mut self, state: TaskState, message: Option<Message>)
Update the task status
Sourcepub fn with_limited_history(&self, history_length: Option<u32>) -> Self
pub fn with_limited_history(&self, history_length: Option<u32>) -> Self
Get a copy of this task with history limited to the specified length
This method follows the A2A spec for history truncation:
- If no history_length is provided, returns the full history
- If history_length is 0, removes history entirely
- If history_length is less than the current history size, keeps only the most recent messages (truncates from the beginning)
Sourcepub fn add_artifact(&mut self, artifact: Artifact)
pub fn add_artifact(&mut self, artifact: Artifact)
Add an artifact to the task
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Task
impl<'de> Deserialize<'de> for Task
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Task
impl RefUnwindSafe for Task
impl Send for Task
impl Sync for Task
impl Unpin for Task
impl UnwindSafe for Task
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more