A2A.TaskStore behaviour (A2A v0.2.0)

Copy Markdown View Source

Behaviour for pluggable task persistence.

Implementations store and retrieve A2A.Task structs. Each callback receives a store reference (opaque term) that the implementation uses to locate its storage — e.g., an ETS table name or a connection PID.

Implementing a Custom Store

defmodule MyApp.RedisTaskStore do
  @behaviour A2A.TaskStore

  @impl true
  def get(conn, task_id) do
    # ...
  end

  # ... other callbacks
end

Configuring an Agent with a Store

MyAgent.start_link(task_store: {A2A.TaskStore.ETS, :my_tasks})

Summary

Callbacks

Deletes a task by ID.

Retrieves a task by ID.

Lists all tasks for a given context ID.

Lists tasks with filtering and pagination options.

Stores or updates a task.

Types

ref()

@type ref() :: term()

Callbacks

delete(ref, task_id)

@callback delete(ref(), task_id :: String.t()) :: :ok | {:error, term()}

Deletes a task by ID.

get(ref, task_id)

@callback get(ref(), task_id :: String.t()) :: {:ok, A2A.Task.t()} | {:error, :not_found}

Retrieves a task by ID.

list(ref, context_id)

@callback list(ref(), context_id :: String.t()) :: {:ok, [A2A.Task.t()]}

Lists all tasks for a given context ID.

list_all(ref, opts)

(optional)
@callback list_all(ref(), opts :: keyword()) :: {:ok, map()}

Lists tasks with filtering and pagination options.

Options

  • :context_id — filter by context ID
  • :status — filter by task state atom
  • :status_timestamp_after — filter to tasks updated after this DateTime
  • :page_size — max results to return (default 50)
  • :page_token — opaque cursor for pagination
  • :history_length — number of history entries to include (default 0)
  • :include_artifacts — whether to include artifacts (default false)

put(ref, t)

@callback put(ref(), A2A.Task.t()) :: :ok | {:error, term()}

Stores or updates a task.