LlmCore.Config.Loader (llm_core v0.7.0)

Copy Markdown View Source

Loads llm_core configuration files (routing, providers, etc.) from disk and updates the store.

Handles the full TOML loading pipeline: reading multiple config layers, deep-merging, resolving environment variable placeholders, normalizing provider definitions, and broadcasting change notifications to dependent processes.

Configuration Layers (later overrides earlier)

  1. Compiled defaults — priv/config/llm_core.toml (bundled with the library)
  2. Global override — ~/.llm_core/config/llm_core.toml
  3. Project override — <project>/.llm_core/llm_core.toml
  4. Environment variable — path in LLM_CORE_CONFIG
  5. Custom path — explicit :path option

Environment Variable Interpolation

TOML values like "${ANTHROPIC_API_KEY}" are resolved at load time. Supports defaults: "${OLLAMA_URL:http://localhost:11434}".

Key Functions

Summary

Functions

Returns the merged TOML configuration without mutating runtime state.

Loads the routing configuration from disk without mutating the store.

Loads TOML configuration (providers, memory, routing defaults) and writes the normalized provider metadata to the runtime store.

Loads the routing configuration and writes it to the runtime store. Broadcasts change notifications so dependent processes can refresh.

Builds a routing table from the merged TOML layers (bundled base, home, project, LLM_CORE_CONFIG, :path) without mutating the store.

Functions

load_config(opts \\ [])

@spec load_config(keyword()) :: {:ok, map()}

Returns the merged TOML configuration without mutating runtime state.

load_routing(opts \\ [])

@spec load_routing(keyword()) ::
  {:ok, LlmCore.Router.RoutingTable.t()} | {:error, term()}

Loads the routing configuration from disk without mutating the store.

reload_providers(opts \\ [])

@spec reload_providers(keyword()) ::
  {:ok, %{optional(String.t()) => LlmCore.Provider.Definition.t()}}
  | {:error, term()}

Loads TOML configuration (providers, memory, routing defaults) and writes the normalized provider metadata to the runtime store.

reload_routing(opts \\ [])

@spec reload_routing(keyword()) ::
  {:ok, LlmCore.Router.RoutingTable.t()} | {:error, term()}

Loads the routing configuration and writes it to the runtime store. Broadcasts change notifications so dependent processes can refresh.

A routing.yml that omits default inherits the default from the merged config layers; its explicit task rules win.

When routing.yml is missing, the existing Store routing is preserved (e.g. a table already installed from TOML via reload_providers/1). Only when the Store has no routing at all is the table built from the merged config layers (routing_from_layers/1); no provider alias is ever hardcoded, so with no default in any layer the table has none and routing fails with :no_routing_default.

routing_from_layers(opts \\ [])

@spec routing_from_layers(keyword()) :: {:ok, LlmCore.Router.RoutingTable.t()}

Builds a routing table from the merged TOML layers (bundled base, home, project, LLM_CORE_CONFIG, :path) without mutating the store.

Always returns {:ok, table}. The table's default is nil when no layer supplies [routing] default, or when the routing section is invalid.