Raxol.Agent.Action behaviour (Raxol Agent v2.6.0)

Copy Markdown View Source

Behaviour for reusable, composable agent operations.

Actions are the unit of work in the agent framework. Each Action module declares its input/output schemas, implements a run/2 callback, and can be composed into pipelines or converted to LLM tool definitions.

Example

defmodule ReadFile do
  use Raxol.Agent.Action,
    name: "read_file",
    description: "Read a file from disk",
    schema: [
      input: [
        path: [type: :string, required: true, description: "File path"]
      ],
      output: [
        content: [type: :string],
        line_count: [type: :integer]
      ]
    ]

  @impl true
  def run(%{path: path}, _context) do
    case File.read(path) do
      {:ok, content} ->
        {:ok, %{content: content, line_count: length(String.split(content, "\n"))}}
      {:error, reason} ->
        {:error, {:file_read_failed, reason}}
    end
  end
end

Actions integrate with TEA agents via run_action/3 and run_action_async/3 helpers injected by use Raxol.Agent.

Summary

Callbacks

Optional: transform result after successful run.

Optional: transform params before validation.

Execute the action with validated params and context.

Types

context()

@type context() :: map()

effect()

@type effect() :: Raxol.Agent.Directive.t()

params()

@type params() :: map()

result()

@type result() :: {:ok, map()} | {:ok, map(), [effect()]} | {:error, term()}

Callbacks

after_run(map, context)

(optional)
@callback after_run(map(), context()) :: map()

Optional: transform result after successful run.

before_validate(params)

(optional)
@callback before_validate(params()) :: params()

Optional: transform params before validation.

run(params, context)

@callback run(params(), context()) :: result()

Execute the action with validated params and context.