GenServer that resolves task types to full LLM agent configurations.
The Router maintains a RoutingTable loaded from TOML configuration and
resolves task strings (like "coding", "reasoning") to ResolvedRoute
structs containing the provider alias, execution mode, and agent metadata.
Configuration
Routing rules are defined in TOML under [routing]:
[routing]
default = "claude"
[routing.tasks.coding]
alias = "openai"
mode = "passthrough"
capabilities = { structured_output = true, tool_use = true }Usage
# Resolve a task type
{:ok, route} = LlmCore.Router.resolve(:coding)
route.alias #=> "openai"
route.mode #=> :passthrough
# Send a prompt through routing
{:ok, response} = LlmCore.Router.send("Write a function", :coding)
# Stream
{:ok, stream} = LlmCore.Router.stream("Explain this", :reasoning)Hot Reload
The Router listens for {:config_reloaded, :routing} messages and
refreshes its routing table from Config.Store. It also syncs
every 60 seconds as a safety net.
Summary
Functions
Returns a specification to start this module under a supervisor.
Returns the current routing table (debug/introspection).
Resolves a task type (e.g., "coding", "planning") to a full agent config.
Resolves a task type using a provided routing table (used for execution snapshots).
Sends a prompt through the router, automatically selecting the provider.
Sends a CommBus protocol packet through the router.
Pass :task_type via opts to override metadata-derived routing.
Starts the Router GenServer linked to the calling process.
Initiates a streaming prompt through the routed provider.
Streams a CommBus protocol packet through the routed provider.
Forces an immediate sync from the config store.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec get_routing_table() :: LlmCore.Router.RoutingTable.t() | nil
Returns the current routing table (debug/introspection).
@spec resolve(String.t() | atom()) :: {:ok, LlmCore.Router.ResolvedRoute.t()} | {:error, term()}
Resolves a task type (e.g., "coding", "planning") to a full agent config.
@spec resolve_from_table(String.t() | atom(), LlmCore.Router.RoutingTable.t()) :: {:ok, LlmCore.Router.ResolvedRoute.t()} | {:error, term()}
Resolves a task type using a provided routing table (used for execution snapshots).
@spec send(String.t(), String.t() | atom(), keyword()) :: {:ok, LlmCore.LLM.Response.t()} | {:error, term()}
Sends a prompt through the router, automatically selecting the provider.
@spec send_packet( map(), keyword() ) :: {:ok, LlmCore.LLM.Response.t()} | {:error, term()}
Sends a CommBus protocol packet through the router.
Pass :task_type via opts to override metadata-derived routing.
@spec start_link(keyword()) :: GenServer.on_start()
Starts the Router GenServer linked to the calling process.
@spec stream(String.t(), String.t() | atom(), keyword()) :: {:ok, Enumerable.t()} | {:error, term()}
Initiates a streaming prompt through the routed provider.
@spec stream_packet( map(), keyword() ) :: {:ok, Enumerable.t()} | {:error, term()}
Streams a CommBus protocol packet through the routed provider.
@spec sync() :: :ok
Forces an immediate sync from the config store.