A2A.Task (A2A v0.2.0)

Copy Markdown View Source

A unit of work managed by an agent runtime.

Tasks track lifecycle state, message history, and produced artifacts.

Summary

Functions

Creates a new task in the :submitted state.

Strips the internal :stream key from task metadata.

Returns true if the task is in a terminal state.

Truncates the task history to the last n entries.

Types

state()

@type state() :: A2A.Task.Status.state()

t()

@type t() :: %A2A.Task{
  artifacts: [A2A.Artifact.t()],
  context_id: String.t() | nil,
  history: [A2A.Message.t()],
  id: String.t(),
  metadata: map(),
  status: A2A.Task.Status.t()
}

Functions

new(opts \\ [])

@spec new(keyword()) :: t()

Creates a new task in the :submitted state.

strip_stream_metadata(task)

@spec strip_stream_metadata(t()) :: t()

Strips the internal :stream key from task metadata.

The :stream key holds a raw enumerable/function ref used by the SSE path and must be removed before JSON encoding.

terminal?(task)

@spec terminal?(t()) :: boolean()

Returns true if the task is in a terminal state.

truncate_history(task, n)

@spec truncate_history(t(), non_neg_integer() | nil) :: t()

Truncates the task history to the last n entries.

Returns the task unchanged when n is nil. A value of 0 clears the history entirely.