LlmCore.Config.Loader (llm_core v0.3.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 defaultspriv/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.

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.

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 does the safe default => claude fallback get installed.