Entropic 2.14.3
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
75{
76 apply_env("ENTROPIC_MCP__EXTERNAL__ENABLED",
77 [&](const std::string& v) {
78 config.mcp.external.enabled = parse_bool(v);
79 });
80 apply_env("ENTROPIC_MCP__EXTERNAL__HTTP_PORT",
81 [&](const std::string& v) {
82 char* end = nullptr;
83 const long port = std::strtol(v.c_str(), &end, 10);
84 config.mcp.external.http_port =
85 (end != v.c_str() && *end == '\0') ? static_cast<int>(port)
86 : -1;
87 });
88}
89
97{
98 apply_env("ENTROPIC_LOG_LEVEL",
99 [&](const std::string& v) { config.log_level = v; });
100 apply_env("ENTROPIC_MODELS__DEFAULT",
101 [&](const std::string& v) { config.models.default_tier = v; });
102 apply_env("ENTROPIC_ROUTING__ENABLED",
103 [&](const std::string& v) {
104 config.routing.enabled = parse_bool(v);
105 });
106 apply_env("ENTROPIC_ROUTING__FALLBACK_TIER",
107 [&](const std::string& v) { config.routing.fallback_tier = v; });
108 apply_env("ENTROPIC_COMPACTION__THRESHOLD_PERCENT",
109 [&](const std::string& v) {
110 config.compaction.threshold_percent = std::stof(v);
111 });
112 apply_env("ENTROPIC_COMPACTION__ENABLED",
113 [&](const std::string& v) {
114 config.compaction.enabled = parse_bool(v);
115 });
116 apply_env("ENTROPIC_VRAM_RESERVE_MB",
117 [&](const std::string& v) {
118 config.vram_reserve_mb = std::stoi(v);
119 });
120 apply_env("ENTROPIC_CONFIG_DIR",
121 [&](const std::string& v) {
122 config.config_dir = std::filesystem::path(v);
123 });
124 apply_mcp_external_env(config); // gh#204 (v2.14.0)
125}
126
127} // 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_mcp_external_env(ParsedConfig &config)
The mcp.external overrides entropic serve sets (gh#204).
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
@ optional
optional: every escape asks the host's path approver
std::string port
–port N
Definition serve.cpp:39
std::string config
–config FILE
Definition serve.cpp:38
Full parsed configuration.
Definition config.h:1338