Record Class Task
- Record Components:
id- the unique identifier for this taskcontextId- the context identifier associating this task with a conversation or sessionstatus- the current status of the taskartifacts- the list of artifacts produced by the agent during task executionhistory- the conversation history for this taskmetadata- arbitrary metadata associated with the task
- All Implemented Interfaces:
Event,EventKind,StreamingEventKind
A Task encapsulates the complete lifecycle of an agent interaction, from submission through completion, cancellation, or failure. It maintains the current state, accumulated artifacts (responses), conversation history, and metadata associated with the operation.
Tasks are the fundamental unit of work in the A2A Protocol. When a client sends a message to an agent, a Task is created to track the operation. The agent updates the Task's state as it processes the request, and may add artifacts containing partial or final responses. The Task's status transitions through various states (SUBMITTED, WORKING, COMPLETED, etc.) until reaching a final state.
Tasks support both blocking and streaming patterns:
- Blocking: Client sends a message and waits for the Task to reach a final state
- Streaming: Client subscribes to Task updates and receives incremental artifacts as they are produced
Tasks are immutable once created (including their history, artifacts and metadata attributes). They use the Builder pattern for construction. Updates to a Task's state are communicated via new Task instances or TaskStatusUpdateEvent/TaskArtifactUpdateEvent objects.
This class implements EventKind and StreamingEventKind, allowing Task instances to
be transmitted as events in both blocking and streaming scenarios.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe identifier when used in streaming responses -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theartifactsrecord component.static Task.Builderbuilder()Creates a new Builder for constructing Task instances.static Task.BuilderCreates a new Builder initialized with values from an existing Task.Returns the value of thecontextIdrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.history()Returns the value of thehistoryrecord component.id()Returns the value of theidrecord component.kind()Returns the type identifier for this event.metadata()Returns the value of themetadatarecord component.status()Returns the value of thestatusrecord component.final StringtoString()Returns a string representation of this record class.
-
Field Details
-
STREAMING_EVENT_ID
The identifier when used in streaming responses- See Also:
-
-
Constructor Details
-
Task
public Task(String id, String contextId, TaskStatus status, @Nullable List<Artifact> artifacts, @Nullable List<Message> history, @Nullable Map<String, Object> metadata) Compact constructor with validation and defensive copying.- Parameters:
id- the task identifiercontextId- the context identifierstatus- the task statusartifacts- the list of artifacts produced by the taskhistory- the message history for this taskmetadata- additional metadata for the task- Throws:
IllegalArgumentException- if id, contextId, or status is null
-
-
Method Details
-
kind
Description copied from interface:EventKindReturns the type identifier for this event.This method provides programmatic type discrimination for routing, logging, and debugging. NOTE: This value is NOT serialized to JSON in protocol v1.0+.
- Specified by:
kindin interfaceEventKind- Specified by:
kindin interfaceStreamingEventKind- Returns:
- the event kind string (e.g., "task", "message")
-
builder
Creates a new Builder for constructing Task instances.- Returns:
- a new Task.Builder instance
-
builder
Creates a new Builder initialized with values from an existing Task.This constructor allows for creating a modified copy of an existing Task by copying all fields and then selectively updating specific values.
- Parameters:
task- the Task to copy values from- Returns:
- a new Builder instance initialized with the task's values
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
id
Returns the value of theidrecord component.- Returns:
- the value of the
idrecord component
-
contextId
Returns the value of thecontextIdrecord component.- Returns:
- the value of the
contextIdrecord component
-
status
Returns the value of thestatusrecord component.- Returns:
- the value of the
statusrecord component
-
artifacts
Returns the value of theartifactsrecord component.- Returns:
- the value of the
artifactsrecord component
-
history
Returns the value of thehistoryrecord component.- Returns:
- the value of the
historyrecord component
-
metadata
Returns the value of themetadatarecord component.- Returns:
- the value of the
metadatarecord component
-