Raxol.Agent (Raxol Agent v2.6.0)

Copy Markdown View Source

Thin layer over Raxol.Core.Runtime.Application for building AI agents.

Agents implement the same TEA callbacks (init/1, update/2, view/1) as any Raxol app. Input comes from LLMs, tools, or other agents instead of a keyboard. OTP provides supervision, crash isolation, and hot reload.

view/1 is optional -- headless agents skip rendering entirely.

Example

defmodule MyAgent do
  use Raxol.Agent

  def init(_context) do
    %{findings: [], status: :idle}
  end

  def update({:agent_message, _from, {:analyze, file}}, model) do
    {%{model | status: :working}, Directive.async(fn sender ->
      result = do_analysis(file)
      sender.({:analysis_done, result})
    end)}
  end

  def update({:command_result, {:analysis_done, result}}, model) do
    {%{model | findings: [result | model.findings], status: :idle}, []}
  end
end

Summary

Functions

Return the effective hook chain for agent_module: prepends Raxol.Agent.SandboxHook to agent_module.command_hooks/0 when the agent declares a non-empty sandbox/0.

Return the normalized Raxol.Agent.ThreadLog adapter tuple from agent_module.thread_log/0, or nil when the agent doesn't declare one. Useful for Raxol.Agent.ThreadLogRouter.attach/3.

Functions

effective_hooks(agent_module)

@spec effective_hooks(module()) :: [module()]

Return the effective hook chain for agent_module: prepends Raxol.Agent.SandboxHook to agent_module.command_hooks/0 when the agent declares a non-empty sandbox/0.

Consumers wiring an agent into a runtime (Symphony's Runners.RaxolAgent, the Agent.Session helper, etc) should pass the result here as the hook list rather than reading command_hooks/0 directly.

Falls back to [] when agent_module doesn't export either callback (e.g. an agent built without use Raxol.Agent).

thread_log_adapter(agent_module)

@spec thread_log_adapter(module()) :: {module(), map()} | nil

Return the normalized Raxol.Agent.ThreadLog adapter tuple from agent_module.thread_log/0, or nil when the agent doesn't declare one. Useful for Raxol.Agent.ThreadLogRouter.attach/3.