a2a.client.client_task_manager module

class a2a.client.client_task_manager.ClientTaskManager

Bases: object

Helps manage a task’s lifecycle during execution of a request.

Responsible for retrieving, saving, and updating the Task object based on events received from the agent.

get_task() Task | None

Retrieves the current task object, either from memory.

If task_id is set, it returns _current_task otherwise None.

Returns:

The Task object if found, otherwise None.

get_task_or_raise() Task

Retrieves the current task object.

Returns:

The Task object.

Raises:

A2AClientInvalidStateError – If there is no current known Task.

async process(event: Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent) Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent

Processes an event, updates the task state if applicable, stores it, and returns the event.

If the event is task-related (Task, TaskStatusUpdateEvent, TaskArtifactUpdateEvent), the internal task state is updated and persisted.

Parameters:

event – The event object received from the agent.

Returns:

The same event object that was processed.

async save_task_event(event: Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent) Task | None

Processes a task-related event (Task, Status, Artifact) and saves the updated task state.

Ensures task and context IDs match or are set from the event.

Parameters:

event – The task-related event (Task, TaskStatusUpdateEvent, or TaskArtifactUpdateEvent).

Returns:

The updated Task object after processing the event.

Raises:

ClientError – If the task ID in the event conflicts with the TaskManager’s ID when the TaskManager’s ID is already set.

update_with_message(message: Message, task: Task) Task

Updates a task object adding a new message to its history.

If the task has a message in its current status, that message is moved to the history first.

Parameters:
  • message – The new Message to add to the history.

  • task – The Task object to update.

Returns:

The updated Task object (updated in-place).