Class TaskUpdateEvent

java.lang.Object
org.a2aproject.sdk.client.TaskUpdateEvent
All Implemented Interfaces:
ClientEvent

public final class TaskUpdateEvent extends Object implements ClientEvent
A client event containing an incremental update to a task.

TaskUpdateEvent represents a change to a task's state during execution. It provides both the current complete task state and the specific update that triggered this event. This event type is the primary mechanism for tracking task progress in streaming scenarios.

Two types of updates:

Streaming task lifecycle example:


 client.sendMessage(A2A.toUserMessage("Summarize this document"));

 // Client receives sequence of TaskUpdateEvents:
 1. TaskUpdateEvent(task=Task[status=SUBMITTED], updateEvent=TaskStatusUpdateEvent)
 2. TaskUpdateEvent(task=Task[status=WORKING], updateEvent=TaskStatusUpdateEvent)
 3. TaskUpdateEvent(task=Task[status=WORKING, artifact=[partial]], updateEvent=TaskArtifactUpdateEvent)
 4. TaskUpdateEvent(task=Task[status=WORKING, artifact=[more content]], updateEvent=TaskArtifactUpdateEvent)
 5. TaskUpdateEvent(task=Task[status=COMPLETED, artifact=[final]], updateEvent=TaskStatusUpdateEvent)
 

Example usage - tracking progress:


 client.addConsumer((event, agentCard) -> {
     if (event instanceof TaskUpdateEvent tue) {
         Task currentTask = tue.getTask();
         UpdateEvent update = tue.getUpdateEvent();
         
         // Handle status changes
         if (update instanceof TaskStatusUpdateEvent statusUpdate) {
             TaskState newState = currentTask.status().state();
             System.out.println("Task " + currentTask.id() + " → " + newState);
             
             if (newState == TaskState.COMPLETED) {
                 System.out.println("Final result: " +
                     currentTask.artifact().parts());
             } else if (newState == TaskState.FAILED) {
                 System.err.println("Error: " +
                     currentTask.status().message());
             }
         }
         
         // Handle new content
         if (update instanceof TaskArtifactUpdateEvent artifactUpdate) {
             Artifact newContent = artifactUpdate.artifact();
             System.out.println("New content received: " + newContent.parts());
             
             // For streaming text generation
             newContent.parts().stream()
                 .filter(p -> p instanceof TextPart)
                 .map(p -> ((TextPart) p).text())
                 .forEach(System.out::print);  // Print incrementally
         }
     }
 });
 

Reconstructing complete state: The getTask() method returns the task with all updates applied up to this point. The client automatically maintains the complete task state by merging updates, so consumers don't need to manually track changes:


 // Each TaskUpdateEvent contains the fully updated task
 TaskUpdateEvent event1 // task has status=WORKING, artifact=null
 TaskUpdateEvent event2 // task has status=WORKING, artifact=[chunk1]
 TaskUpdateEvent event3 // task has status=WORKING, artifact=[chunk1, chunk2]
 TaskUpdateEvent event4 // task has status=COMPLETED, artifact=[chunk1, chunk2, final]
 

Artifact updates: When TaskArtifactUpdateEvent is received, the artifact may be:

  • Incremental: New parts appended to existing artifact (common for streaming text)
  • Replacement: Entire artifact replaced (less common)
The getTask() always reflects the current complete artifact state.

Status transitions: Common task state transitions:

 SUBMITTED → WORKING → COMPLETED
 SUBMITTED → WORKING → FAILED
 SUBMITTED → WORKING → CANCELED
 SUBMITTED → AUTH_REQUIRED → (waiting for auth) → WORKING → COMPLETED
 
See Also:
  • Constructor Details

    • TaskUpdateEvent

      public TaskUpdateEvent(Task task, UpdateEvent updateEvent)
      Create a task update event.

      This constructor is typically called internally by the client framework when processing update events from the agent. The task parameter contains the complete current state with all updates applied, while updateEvent contains the specific change that triggered this event.

      Parameters:
      task - the current complete task state with all updates applied (required)
      updateEvent - the specific update that triggered this event (required)
  • Method Details

    • getTask

      public Task getTask()
      Get the current complete task state.

      The returned task reflects all updates received up to this point, including the update contained in this event. Consumers can use this method to access the complete current state without manually tracking changes.

      Returns:
      the task with all updates applied
    • getUpdateEvent

      public UpdateEvent getUpdateEvent()
      Get the specific update that triggered this event.

      This will be either:

      Returns:
      the update event