a2a.utils.task module¶
Utility functions for creating A2A Task objects.
- a2a.utils.task.apply_history_length(task: Task, history_length: int | None) Task¶
Applies history_length parameter on task and returns a new task object.
- Parameters:
task – The original task object with complete history
history_length – History length configuration value
- Returns:
A new task object with limited history
- a2a.utils.task.completed_task(task_id: str, context_id: str, artifacts: list[Artifact], history: list[Message] | None = None) Task¶
Creates a Task object in the ‘completed’ state.
Useful for constructing a final Task representation when the agent finishes and produces artifacts.
- Parameters:
task_id – The ID of the task.
context_id – The context ID of the task.
artifacts – A list of Artifact objects produced by the task.
history – An optional list of Message objects representing the task history.
- Returns:
A Task object with status set to ‘completed’.
- a2a.utils.task.new_task(request: Message) Task¶
Creates a new Task object from an initial user message.
Generates task and context IDs if not provided in the message.
- Parameters:
request – The initial Message object from the user.
- Returns:
A new Task object initialized with ‘submitted’ status and the input message in history.
- Raises:
TypeError – If the message role is None.
ValueError – If the message parts are empty, if any part has empty content, or if the provided context_id is invalid.