Agentic.ModelRouter (agentic v0.2.2)

Copy Markdown

Smart model routing for Agentic with two selection modes.

Modes

  • :manual — the caller picks a tier (:primary, :lightweight) and the router resolves the best route from the catalog. This is the legacy behaviour and the default.
  • :auto — the router analyses the request using a fast/free model, determines complexity and required capabilities, then selects the best model based on user preference (:optimize_price or :optimize_speed).

Auto mode flow

1. `Analyzer.analyze/2` classifies the request (complexity, capabilities)
2. `Selector.select/3` scores all catalog models using the analysis
   and user preference
3. The best-scoring model is returned as a route

Manual mode flow

1. Caller provides a `tier` (`:primary`, `:lightweight`, `:any`)
2. Router queries the catalog, sorts by priority, returns healthy routes

Summary

Functions

Auto-select the best model for a request given a user preference.

Returns a specification to start this module under a supervisor.

Clear workspace tier overrides.

Report a successful call for a route.

Resolve the best route for a tier (manual mode).

Get all available routes for a tier (manual mode).

Resolve routes for a context — dispatches to auto or manual based on ctx.model_selection_mode.

Legacy compat: set routes for a tier (replaced by Catalog, kept for backward compat).

Configure workspace tier overrides.

Get current routing status.

Types

selection_mode()

@type selection_mode() :: :manual | :auto

Functions

auto_select(request, preference \\ Preference.default(), opts \\ [])

Auto-select the best model for a request given a user preference.

Returns {:ok, route, analysis} or {:error, reason}.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear_tier_overrides()

Clear workspace tier overrides.

report_error(provider_name, model_id, failure_type \\ :other, opts \\ [])

Report a failed call for a route.

report_success(provider_name, model_id)

Report a successful call for a route.

resolve(tier)

Resolve the best route for a tier (manual mode).

resolve_all(tier)

Get all available routes for a tier (manual mode).

resolve_for_context(ctx)

Resolve routes for a context — dispatches to auto or manual based on ctx.model_selection_mode.

set_routes(tier, routes)

Legacy compat: set routes for a tier (replaced by Catalog, kept for backward compat).

set_tier_overrides(tiers)

Configure workspace tier overrides.

start_link(opts \\ [])

status()

Get current routing status.