Record Class Task

java.lang.Object
java.lang.Record
org.a2aproject.sdk.spec.Task
Record Components:
id - the unique identifier for this task
contextId - the context identifier associating this task with a conversation or session
status - the current status of the task
artifacts - the list of artifacts produced by the agent during task execution
history - the conversation history for this task
metadata - arbitrary metadata associated with the task
All Implemented Interfaces:
Event, EventKind, StreamingEventKind

public record Task(String id, String contextId, TaskStatus status, @Nullable List<Artifact> artifacts, @Nullable List<Message> history, @Nullable Map<String,Object> metadata) extends Record implements EventKind, StreamingEventKind
Represents a single, stateful operation or conversation between a client and an agent in the A2A Protocol.

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.

See Also:
  • Field Details

    • STREAMING_EVENT_ID

      public static final String 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 identifier
      contextId - the context identifier
      status - the task status
      artifacts - the list of artifacts produced by the task
      history - the message history for this task
      metadata - additional metadata for the task
      Throws:
      IllegalArgumentException - if id, contextId, or status is null
  • Method Details

    • kind

      public String kind()
      Description copied from interface: EventKind
      Returns 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:
      kind in interface EventKind
      Specified by:
      kind in interface StreamingEventKind
      Returns:
      the event kind string (e.g., "task", "message")
    • builder

      public static Task.Builder builder()
      Creates a new Builder for constructing Task instances.
      Returns:
      a new Task.Builder instance
    • builder

      public static Task.Builder builder(Task task)
      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

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • id

      public String id()
      Returns the value of the id record component.
      Returns:
      the value of the id record component
    • contextId

      public String contextId()
      Returns the value of the contextId record component.
      Returns:
      the value of the contextId record component
    • status

      public TaskStatus status()
      Returns the value of the status record component.
      Returns:
      the value of the status record component
    • artifacts

      public @Nullable List<Artifact> artifacts()
      Returns the value of the artifacts record component.
      Returns:
      the value of the artifacts record component
    • history

      public @Nullable List<Message> history()
      Returns the value of the history record component.
      Returns:
      the value of the history record component
    • metadata

      public @Nullable Map<String,Object> metadata()
      Returns the value of the metadata record component.
      Returns:
      the value of the metadata record component