BeamAgent.Routing (beam_agent_ex v0.1.0)

Copy Markdown View Source

Elixir facade for canonical BeamAgent backend routing.

This module chooses a backend according to reusable routing policy instead of forcing callers to hard-code backend choice on every session start.

Supported policies are :explicit, :sticky, :round_robin, :failover, :capability_first, and :preferred_then_fallback. Sticky affinity and round-robin cursors are stored as canonical BeamAgent state, but the module itself stays process-free.

Summary

Types

Fallback behavior after preferred candidates are exhausted.

Backend health override for routing.

Routing decision map.

Routing policy name.

Routing request map.

Functions

Clear sticky affinity and round-robin routing state.

Ensure routing state tables exist.

Select a backend using a normalized routing request.

Select a backend after deriving defaults from a session identity or session opts.

Types

fallback_policy()

@type fallback_policy() :: :beam_agent_routing.fallback_policy()

Fallback behavior after preferred candidates are exhausted.

Supported values are :none and :available.

health_status()

@type health_status() :: :beam_agent_routing.health_status()

Backend health override for routing.

Supported values are :healthy, :degraded, :unhealthy, and :down.

route_decision()

@type route_decision() :: :beam_agent_routing.route_decision()

Routing decision map.

route_policy()

@type route_policy() :: :beam_agent_routing.route_policy()

Routing policy name.

Supported values are :explicit, :sticky, :round_robin, :failover, :capability_first, and :preferred_then_fallback.

route_request()

@type route_request() :: :beam_agent_routing.route_request()

Routing request map.

Functions

clear()

@spec clear() :: :ok

Clear sticky affinity and round-robin routing state.

ensure_tables()

@spec ensure_tables() :: :ok

Ensure routing state tables exist.

select_backend(route_request)

@spec select_backend(route_request()) :: {:ok, route_decision()} | {:error, term()}

Select a backend using a normalized routing request.

select_backend(session_or_opts, route_request)

@spec select_backend(pid() | binary() | map(), route_request()) ::
  {:ok, route_decision()} | {:error, term()}

Select a backend after deriving defaults from a session identity or session opts.