AgentSessionManager.Routing.ProviderRouter (AgentSessionManager v0.8.0)

Copy Markdown View Source

Provider router that implements the ProviderAdapter behaviour.

The router selects a registered adapter by capability requirements, routing policy, and simple in-router health state. It supports retryable failover and run-to-adapter cancellation routing.

Phase 2 Additions

  • Weighted scoring — when strategy: :weighted, candidates are ordered by score (static weight minus health penalty).
  • Session stickiness — pass routing: [sticky_session_id: id] to pin a session to a provider for continuity. The mapping expires after sticky_ttl_ms (default: 300 000 ms).
  • Routing telemetry — emits [:agent_session_manager, :router, :attempt, ...] events for each routing attempt.
  • Circuit breaker — optional per-adapter circuit breaker behind circuit_breaker: true configuration.

Summary

Types

adapter_entry()

@type adapter_entry() :: %{
  id: adapter_id(),
  adapter: AgentSessionManager.Ports.ProviderAdapter.adapter(),
  opts: keyword()
}

adapter_id()

@type adapter_id() :: String.t()

health_entry()

@type health_entry() :: %{
  failure_count: non_neg_integer(),
  last_failure_at: DateTime.t() | nil
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

register_adapter(server, id, adapter, opts \\ [])

start_link(opts \\ [])

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

status(server)

@spec status(GenServer.server()) :: map()

unregister_adapter(server, id)

@spec unregister_adapter(GenServer.server(), adapter_id()) :: :ok