Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
env_overrides.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
10#include <cstdlib>
11
12static auto s_log = entropic::log::get("config");
13
14namespace entropic::config {
15
23static std::string get_env(const char* name)
24{
25 const char* val = std::getenv(name);
26 return val != nullptr ? std::string(val) : "";
27}
28
36static bool parse_bool(const std::string& val)
37{
38 return val == "true" || val == "True" || val == "TRUE"
39 || val == "yes" || val == "1";
40}
41
54template <typename Setter>
55static void apply_env(const char* key, Setter setter) {
56 auto val = get_env(key);
57 if (val.empty()) { return; }
58 s_log->info("Env override: {}={}", key, val);
59 setter(val);
60}
61
69{
70 apply_env("ENTROPIC_LOG_LEVEL",
71 [&](const std::string& v) { config.log_level = v; });
72 apply_env("ENTROPIC_MODELS__DEFAULT",
73 [&](const std::string& v) { config.models.default_tier = v; });
74 apply_env("ENTROPIC_ROUTING__ENABLED",
75 [&](const std::string& v) {
76 config.routing.enabled = parse_bool(v);
77 });
78 apply_env("ENTROPIC_ROUTING__FALLBACK_TIER",
79 [&](const std::string& v) { config.routing.fallback_tier = v; });
80 apply_env("ENTROPIC_COMPACTION__THRESHOLD_PERCENT",
81 [&](const std::string& v) {
82 config.compaction.threshold_percent = std::stof(v);
83 });
84 apply_env("ENTROPIC_COMPACTION__ENABLED",
85 [&](const std::string& v) {
86 config.compaction.enabled = parse_bool(v);
87 });
88 apply_env("ENTROPIC_VRAM_RESERVE_MB",
89 [&](const std::string& v) {
90 config.vram_reserve_mb = std::stoi(v);
91 });
92 apply_env("ENTROPIC_CONFIG_DIR",
93 [&](const std::string& v) {
94 config.config_dir = std::filesystem::path(v);
95 });
96}
97
98} // namespace entropic::config
static bool parse_bool(const std::string &val)
Parse a boolean from string (true/false/yes/no/1/0).
static void apply_env(const char *key, Setter setter)
Apply one ENTROPIC_* override if the env var is set.
static std::string get_env(const char *name)
Get environment variable value or empty string.
Config loader — YAML to C++ structs with validation.
ENTROPIC_EXPORT void apply_env_overrides(ParsedConfig &config)
Apply ENTROPIC_* environment variable overrides.
spdlog initialization and logger access.
ENTROPIC_EXPORT std::shared_ptr< spdlog::logger > get(const std::string &name)
Get or create a named logger.
Definition logging.cpp:211
float threshold_percent
Compaction trigger (0.5–0.99)
Definition config.h:510
bool enabled
Enable auto-compaction.
Definition config.h:509
std::string default_tier
Default tier name.
Definition config.h:359
Full parsed configuration.
Definition config.h:714
int vram_reserve_mb
Reserved VRAM headroom (MB, 0–65536)
Definition config.h:735
CompactionConfig compaction
Auto-compaction settings.
Definition config.h:720
RoutingConfig routing
Routing rules.
Definition config.h:716
ModelsConfig models
Tiers + router.
Definition config.h:715
std::string log_level
Log level string.
Definition config.h:724
std::filesystem::path config_dir
Config dir — base for bundled data discovery.
Definition config.h:738
std::string fallback_tier
Fallback when routing fails.
Definition config.h:390
bool enabled
Enable routing.
Definition config.h:389