A2UIAgent.A2A.Agent behaviour (A2UIAgent v0.1.1)

Copy Markdown View Source

An agent that A2UIAgent.A2A.Server and A2UIAgent.A2A.Plug serve.

defmodule MyAgent do
  @behaviour A2UIAgent.A2A.Agent

  alias A2UIAgent.A2A.Request

  @impl true
  def run(%Request{processor: nil, text: text}), do: {:ok, MyModel.reply(text)}

  def run(%Request{processor: processor, text: text}) do
    {:ok, prompt} = A2UIAgent.RequestProcessor.prompt(processor)
    {:ok, MyModel.stream(prompt, text)}
  end

  @impl true
  def options, do: [generator: MyAgent.Catalogs.generator()]

  @impl true
  def card do
    %{
      "name" => "My agent",
      "capabilities" => %{"extensions" => [A2UIAgent.A2A.agent_extension("1.0")]}
    }
  end
end

Summary

Callbacks

The agent's A2A agent card, which advertises its extensions and which A2UIAgent.A2A.Plug serves on GET.

The A2UIAgent.A2A.Server options for a request, such as :generator.

Answers a request: the model's output (a string or an enumerable of chunks) and optionally the state the task ends in, or an error.

Callbacks

card()

(since 0.1.0) (optional)
@callback card() :: map()

The agent's A2A agent card, which advertises its extensions and which A2UIAgent.A2A.Plug serves on GET.

options()

(since 0.1.0) (optional)
@callback options() :: keyword()

The A2UIAgent.A2A.Server options for a request, such as :generator.

run(t)

(since 0.1.0)

Answers a request: the model's output (a string or an enumerable of chunks) and optionally the state the task ends in, or an error.