a2a.utils.task module

Utility functions for creating A2A Task objects.

class a2a.utils.task.HistoryLengthConfig(*args, **kwargs)

Bases: Protocol

Protocol for configuration arguments containing history_length field.

HasField(field_name: Literal['history_length']) bool

Checks if a field is set.

This method name matches the generated Protobuf code.

history_length: int
a2a.utils.task.apply_history_length(task: Task, config: HistoryLengthConfig | None) Task

Applies history_length parameter on task and returns a new task object.

Parameters:
  • task – The original task object with complete history

  • config – Configuration object containing ‘history_length’ field and HasField method.

Returns:

A new task object with limited history

a2a.utils.task.decode_page_token(page_token: str) str

Decodes page token for tasks pagination.

Parameters:

page_token – The encoded page token.

Returns:

The decoded task ID.

a2a.utils.task.encode_page_token(task_id: str) str

Encodes page token for tasks pagination.

Parameters:

task_id – The ID of the task.

Returns:

The encoded page token.

a2a.utils.task.validate_history_length(config: HistoryLengthConfig | None) None

Validates that history_length is non-negative.

a2a.utils.task.validate_page_size(page_size: int) None

Validates that page_size is in range [1, 100].