View Source SwarmEx.Client (SwarmEx v0.1.0)

Main supervisor for agent networks. Manages agent lifecycles, message passing, error recovery and context variables.

The Client acts as a coordinator for a network of AI agents, handling:

  • Agent lifecycle management (creation, termination)
  • Message routing between agents
  • Network state and context maintenance
  • Error handling and recovery

Summary

Functions

Returns a specification to start this module under a supervisor.

Creates a new agent in the network.

Lists all active agents in the network.

Sends a message to a specific agent in the network.

Starts a new agent network with the given options.

Updates the network context with new values.

Types

@type t() :: %SwarmEx.Client{
  active_agents: %{optional(String.t()) => pid()},
  context: map(),
  network_id: String.t(),
  options: keyword()
}

Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

create_agent(client, agent_module, opts \\ [])

View Source
@spec create_agent(GenServer.server(), module(), keyword()) ::
  {:ok, pid()} | {:error, term()}

Creates a new agent in the network.

Options

All options are passed to the agent's init function.

@spec list_agents(GenServer.server()) :: {:ok, [String.t()]} | {:error, term()}

Lists all active agents in the network.

Link to this function

send_message(client, agent_id, message)

View Source
@spec send_message(GenServer.server(), String.t(), term()) ::
  {:ok, term()} | {:error, term()}

Sends a message to a specific agent in the network.

@spec start_link(keyword()) :: GenServer.on_start()

Starts a new agent network with the given options.

Options

  • :network_id - Custom identifier for the network (optional)
  • :context - Initial context map (default: %{})
  • :registry - Custom registry for agent processes (optional)
Link to this function

update_context(client, context)

View Source
@spec update_context(GenServer.server(), map()) :: :ok | {:error, term()}

Updates the network context with new values.