View Source SwarmEx.Agent behaviour (SwarmEx v0.2.0)

Defines the behavior and implementation for SwarmEx agents.

Each agent in the SwarmEx system is a process that can:

  • Process messages from other agents or clients
  • Maintain internal state
  • Participate in agent networks
  • Execute functions from tool modules
  • Perform self-health checks and recovery

Summary

Functions

Creates a new agent process with the given module and options.

Stops an agent process.

Validates the agent implementation to ensure all required callbacks are implemented correctly.

Types

@type error() :: {:error, term()}
@type health_status() :: :healthy | :degraded | :unhealthy
@type message() :: term()
@type response() :: {:ok, term(), state()} | {:error, term()}
@type state() :: term()

Callbacks

Link to this callback

handle_handoff(target, state)

View Source (optional)
@callback handle_handoff(target :: pid(), state()) :: {:ok, state()} | error()
Link to this callback

handle_message(message, state)

View Source
@callback handle_message(message(), state()) :: response()
Link to this callback

handle_recovery(reason, state)

View Source (optional)
@callback handle_recovery(reason :: term(), state()) :: {:ok, state()} | {:error, term()}
Link to this callback

health_check(state)

View Source (optional)
@callback health_check(state()) :: {:ok, health_status(), state()} | {:error, term()}

Functions

Link to this function

create(module, opts \\ [])

View Source
@spec create(
  module(),
  keyword()
) :: {:ok, pid()} | {:error, term()}

Creates a new agent process with the given module and options.

Link to this function

stop(agent, reason \\ :normal)

View Source
@spec stop(pid() | atom() | binary(), term()) :: :ok | {:error, term()}

Stops an agent process.

@spec validate_agent(module()) :: :ok | {:error, term()}

Validates the agent implementation to ensure all required callbacks are implemented correctly.