Raxol.Agent.UseProcess (Raxol Agent v2.6.0)

Copy Markdown View Source

Convenience macro for agents running in the observe/think/act loop.

Similar to use Raxol.Agent for TEA agents, this provides defaults and the @behaviour annotation for Process-based agents.

Example

defmodule MyProcessAgent do
  use Raxol.Agent.UseProcess

  @impl true
  def init(_opts), do: {:ok, %{count: 0}}

  @impl true
  def observe(events, state) do
    {:ok, %{event_count: length(events)}, state}
  end

  @impl true
  def think(%{event_count: n}, state) when n > 0 do
    {:act, :process_events, state}
  end

  def think(_obs, state), do: {:wait, state}

  @impl true
  def act(:process_events, state) do
    {:ok, %{state | count: state.count + 1}}
  end
end