# `LlmCore.Router`
[🔗](https://github.com/fosferon/llm_core/blob/v0.3.0/lib/llm_core/router/router.ex#L1)

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.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `get_routing_table`

```elixir
@spec get_routing_table() :: LlmCore.Router.RoutingTable.t() | nil
```

Returns the current routing table (debug/introspection).

# `resolve`

```elixir
@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.

# `resolve_from_table`

```elixir
@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).

# `send`

```elixir
@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.

# `send_packet`

```elixir
@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.

# `start_link`

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

Starts the Router GenServer linked to the calling process.

# `stream`

```elixir
@spec stream(String.t(), String.t() | atom(), keyword()) ::
  {:ok, Enumerable.t()} | {:error, term()}
```

Initiates a streaming prompt through the routed provider.

# `stream_packet`

```elixir
@spec stream_packet(
  map(),
  keyword()
) :: {:ok, Enumerable.t()} | {:error, term()}
```

Streams a CommBus protocol packet through the routed provider.

# `sync`

```elixir
@spec sync() :: :ok
```

Forces an immediate sync from the config store.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
