Lux.AgentHub (Lux v0.5.0)

View Source

A central hub for managing and discovering agents in the system. Provides functionality for registering agents, tracking their status, and discovering agents based on capabilities.

Multiple AgentHub instances can be started with different names:

{:ok, pid} = AgentHub.start_link(name: :my_hub)
{:ok, pid} = AgentHub.start_link(name: :another_hub)

Then interact with specific hubs:

AgentHub.register(hub, agent, pid, capabilities)
AgentHub.find_by_capability(hub, :research)

Summary

Functions

Child spec for starting under a supervisor.

Finds agents by capability.

Gets information about a specific agent.

Gets the default agent hub's pid.

Lists all registered agents.

Registers an agent in the hub.

Starts a new AgentHub process.

Updates the status of an agent.

Types

agent_info()

@type agent_info() :: %{
  agent: Lux.Agent.t(),
  pid: pid(),
  status: agent_status(),
  capabilities: [atom()],
  last_updated: DateTime.t()
}

agent_status()

@type agent_status() :: :available | :busy | :offline

hub()

@type hub() :: atom() | pid()

Functions

child_spec(init_arg)

Child spec for starting under a supervisor.

Example:

children = [
  {Lux.AgentHub, name: :my_hub}
]
Supervisor.start_link(children, strategy: :one_for_one)

find_by_capability(hub, capability)

@spec find_by_capability(hub(), atom()) :: [agent_info()]

Finds agents by capability.

get_agent_info(hub, agent_id)

@spec get_agent_info(hub(), String.t()) :: {:ok, agent_info()} | {:error, :not_found}

Gets information about a specific agent.

get_default()

@spec get_default() :: pid() | nil

Gets the default agent hub's pid.

list_agents(hub)

@spec list_agents(hub()) :: [agent_info()]

Lists all registered agents.

register(hub, agent, pid, capabilities \\ [])

Registers an agent in the hub.

start_link(opts \\ [])

Starts a new AgentHub process.

Options

  • :name - Registers the hub with the given name

update_status(hub, agent_id, status)

@spec update_status(hub(), String.t(), agent_status()) :: :ok | {:error, term()}

Updates the status of an agent.