The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
perf: use load_config_readonly() at read-only call sites in agent/
Gabriel Stoltemberg59ee85ed50d2
diff --git a/agent/agent_init.py b/agent/agent_init.pyindex d8eee9497ca..0b2ced0d327 100644--- a/agent/agent_init.py+++ b/agent/agent_init.py@@ -840,7 +840,7 @@ def init_agent(# sessions with >5-minute pauses between turns (#14971).agent._cache_ttl = "5m"try:- from hermes_cli.config import load_config as _load_pc_cfg+ from hermes_cli.config import load_config_readonly as _load_pc_cfg_pc_cfg = _load_pc_cfg().get("prompt_caching", {}) or {}_ttl = _pc_cfg.get("cache_ttl", "5m")@@ -1090,7 +1090,7 @@ def init_agent(# Guardrail config — read from config.yaml at init time.agent._bedrock_guardrail_config = Nonetry:- from hermes_cli.config import load_config as _load_br_cfg+ from hermes_cli.config import load_config_readonly as _load_br_cfg_gr = _load_br_cfg().get("bedrock", {}).get("guardrail", {})if _gr.get("guardrail_identifier") and _gr.get("guardrail_version"):agent._bedrock_guardrail_config = {@@ -1477,7 +1477,7 @@ def init_agent(# reads the JSON files directly. See run_agent._save_session_log.agent._session_json_enabled = Falsetry:- from hermes_cli.config import load_config as _load_sess_cfg+ from hermes_cli.config import load_config_readonly as _load_sess_cfg_sess_cfg = (_load_sess_cfg().get("sessions") or {})agent._session_json_enabled = bool(_sess_cfg.get("write_json_snapshots", False))except Exception:@@ -1548,7 +1548,7 @@ def init_agent(# Load config once for memory, skills, and compression sectionstry:- from hermes_cli.config import load_config as _load_agent_config+ from hermes_cli.config import load_config_readonly as _load_agent_config_agent_cfg = _load_agent_config()except Exception:_agent_cfg = {}diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.pyindex 42647956042..2dc845b69c1 100644--- a/agent/auxiliary_client.py+++ b/agent/auxiliary_client.py@@ -676,15 +676,15 @@ def build_or_headers(or_config: dict | None = None) -> dict:Overrides ``openrouter.response_cache_ttl`` in config.yaml.*or_config* is the ``openrouter`` section from config.yaml. When *None*,- falls back to reading config from disk via ``load_config()``.+ falls back to reading config from disk via ``load_config_readonly()``."""headers = dict(_OR_HEADERS_BASE)# Resolve config from disk if not provided.if or_config is None:try:- from hermes_cli.config import load_config- or_config = load_config().get("openrouter", {})+ from hermes_cli.config import load_config_readonly+ or_config = load_config_readonly().get("openrouter", {})except Exception:or_config = {}@@ -2317,8 +2317,8 @@ def _read_main_model() -> str:if isinstance(override, str) and override.strip():return override.strip()try:- from hermes_cli.config import load_config- cfg = load_config()+ from hermes_cli.config import load_config_readonly+ cfg = load_config_readonly()model_cfg = cfg.get("model", {})if isinstance(model_cfg, str) and model_cfg.strip():return model_cfg.strip()@@ -2344,8 +2344,8 @@ def _read_main_provider() -> str:if isinstance(override, str) and override.strip():return override.strip().lower()try:- from hermes_cli.config import load_config- cfg = load_config()+ from hermes_cli.config import load_config_readonly+ cfg = load_config_readonly()model_cfg = cfg.get("model", {})if isinstance(model_cfg, dict):provider = model_cfg.get("provider", "")@@ -3040,12 +3040,12 @@ def _try_azure_foundry(try:from hermes_cli.runtime_provider import _resolve_azure_foundry_runtimefrom hermes_cli.auth import AuthError- from hermes_cli.config import load_config+ from hermes_cli.config import load_config_readonlyexcept ImportError:return None, Nonetry:- cfg = load_config()+ cfg = load_config_readonly()model_cfg = cfg.get("model") if isinstance(cfg, dict) else {}if not isinstance(model_cfg, dict):model_cfg = {}@@ -3159,8 +3159,8 @@ def _try_anthropic(explicit_api_key: str = None) -> Tuple[Optional[Any], Optiona# see issue #52608.base_url = _pool_runtime_base_url(entry, _ANTHROPIC_DEFAULT_BASE_URL) if pool_present else _ANTHROPIC_DEFAULT_BASE_URLtry:- from hermes_cli.config import load_config- cfg = load_config()+ from hermes_cli.config import load_config_readonly+ cfg = load_config_readonly()model_cfg = cfg.get("model")if isinstance(model_cfg, dict):cfg_provider = str(model_cfg.get("provider") or "").strip().lower()@@ -4764,10 +4764,10 @@ def _try_main_fallback_chain(participate in the same order as the main agent."""try:- from hermes_cli.config import load_config+ from hermes_cli.config import load_config_readonlyfrom hermes_cli.fallback_config import get_fallback_chain- chain = get_fallback_chain(load_config())+ chain = get_fallback_chain(load_config_readonly())except Exception as exc:logger.debug("Auxiliary %s: could not load main fallback chain: %s", task or "call", exc)return None, None, ""@@ -5986,11 +5986,11 @@ def _main_model_supports_vision(provider: str, model: Optional[str]) -> bool:"""try:from agent.image_routing import _lookup_supports_vision- from hermes_cli.config import load_config+ from hermes_cli.config import load_config_readonlyexcept ImportError:return Truetry:- supports = _lookup_supports_vision(provider, model, load_config())+ supports = _lookup_supports_vision(provider, model, load_config_readonly())except Exception: # pragma: no cover - defensivereturn Trueif supports is None:@@ -6959,8 +6959,8 @@ def _get_auxiliary_task_config(task: str) -> Dict[str, Any]:if not task:return {}try:- from hermes_cli.config import load_config- config = load_config()+ from hermes_cli.config import load_config_readonly+ config = load_config_readonly()except ImportError:return {}aux = config.get("auxiliary", {}) if isinstance(config, dict) else {}diff --git a/agent/background_review.py b/agent/background_review.pyindex a0dbd4a99e2..bc58ac59d99 100644--- a/agent/background_review.py+++ b/agent/background_review.py@@ -70,8 +70,8 @@ def _resolve_review_runtime(agent: Any) -> Dict[str, Any]:"routed": False,}try:- from hermes_cli.config import load_config- cfg = load_config()+ from hermes_cli.config import load_config_readonly+ cfg = load_config_readonly()except Exception:return parentaux = cfg.get("auxiliary", {}) if isinstance(cfg.get("auxiliary"), dict) else {}diff --git a/agent/coding_context.py b/agent/coding_context.pyindex fabbdb48e07..aa38305e016 100644--- a/agent/coding_context.py+++ b/agent/coding_context.py@@ -337,9 +337,9 @@ def _coding_mode(config: Optional[dict[str, Any]]) -> str:"""Return the normalized ``agent.coding_context`` mode (auto/focus/on/off)."""if config is None:try:- from hermes_cli.config import load_config+ from hermes_cli.config import load_config_readonly- config = load_config()+ config = load_config_readonly()except Exception:config = {}raw = ((config or {}).get("agent", {}) or {}).get("coding_context", "auto")diff --git a/agent/curator.py b/agent/curator.pyindex 21827bec484..750dd7c2eba 100644--- a/agent/curator.py+++ b/agent/curator.py@@ -138,8 +138,8 @@ def is_paused() -> bool:def _load_config() -> Dict[str, Any]:"""Read curator.* config from ~/.hermes/config.yaml. Tolerates missing file."""try:- from hermes_cli.config import load_config- cfg = load_config()+ from hermes_cli.config import load_config_readonly+ cfg = load_config_readonly()except Exception as e:logger.debug("Failed to load config for curator: %s", e)return {}@@ -1875,9 +1875,9 @@ def _run_llm_review(prompt: str) -> Dict[str, Any]:_acp_args = None_model_name = ""try:- from hermes_cli.config import load_config+ from hermes_cli.config import load_config_readonlyfrom hermes_cli.runtime_provider import resolve_runtime_provider- _cfg = load_config()+ _cfg = load_config_readonly()_binding = _resolve_review_runtime(_cfg)_provider, _model_name = _binding.provider, _binding.model_rp = resolve_runtime_provider(diff --git a/agent/curator_backup.py b/agent/curator_backup.pyindex 5b95f9e3e70..ca0cc763625 100644--- a/agent/curator_backup.py+++ b/agent/curator_backup.py@@ -147,8 +147,8 @@ def _utc_id(now: Optional[datetime] = None) -> str:def _load_config() -> Dict[str, Any]:try:- from hermes_cli.config import load_config- cfg = load_config()+ from hermes_cli.config import load_config_readonly+ cfg = load_config_readonly()except Exception as e:logger.debug("Failed to load config for curator backup: %s", e)return {}diff --git a/agent/i18n.py b/agent/i18n.pyindex 24f8ab0a023..7c0dcf5c87e 100644--- a/agent/i18n.py+++ b/agent/i18n.py@@ -197,8 +197,8 @@ def _config_language_cached() -> str | None:(e.g. after the setup wizard)."""try:- from hermes_cli.config import load_config- cfg = load_config()+ from hermes_cli.config import load_config_readonly+ cfg = load_config_readonly()lang = (cfg.get("display") or {}).get("language")if lang:return _normalize_lang(lang)diff --git a/agent/image_gen_registry.py b/agent/image_gen_registry.pyindex 5d14a6f1ece..47538c8cf25 100644--- a/agent/image_gen_registry.py+++ b/agent/image_gen_registry.py@@ -91,9 +91,9 @@ def get_active_provider() -> Optional[ImageGenProvider]:"""configured: Optional[str] = Nonetry:- from hermes_cli.config import load_config+ from hermes_cli.config import load_config_readonly- cfg = load_config()+ cfg = load_config_readonly()section = cfg.get("image_gen") if isinstance(cfg, dict) else Noneif isinstance(section, dict):raw = section.get("provider")diff --git a/agent/lsp/manager.py b/agent/lsp/manager.pyindex 757f7ebc7b9..7ba1b914f74 100644--- a/agent/lsp/manager.py+++ b/agent/lsp/manager.py@@ -196,8 +196,8 @@ class LSPService:itself returns ``is_active()`` False when LSP is disabled."""try:- from hermes_cli.config import load_config- cfg = load_config()+ from hermes_cli.config import load_config_readonly+ cfg = load_config_readonly()except Exception as e: # noqa: BLE001logger.debug("LSP config load failed: %s", e)return Nonediff --git a/agent/plugin_llm.py b/agent/plugin_llm.pyindex e9c2a869dd7..8fcd3364b1c 100644--- a/agent/plugin_llm.py+++ b/agent/plugin_llm.py@@ -210,8 +210,8 @@ def _resolve_trust_policy(plugin_id: str) -> _TrustPolicy:return _TrustPolicy(plugin_id="")try:- from hermes_cli.config import load_config- config = load_config() or {}+ from hermes_cli.config import load_config_readonly+ config = load_config_readonly() or {}except Exception: # pragma: no cover — config IO failurereturn _TrustPolicy(plugin_id=plugin_id)diff --git a/agent/prompt_builder.py b/agent/prompt_builder.pyindex f4766141a39..e6f1f96adf8 100644--- a/agent/prompt_builder.py+++ b/agent/prompt_builder.py@@ -1246,10 +1246,10 @@ def build_environment_hints() -> str:extra = (os.getenv("HERMES_ENVIRONMENT_HINT") or "").strip()if not extra:try:- from hermes_cli.config import load_config+ from hermes_cli.config import load_config_readonlyextra = str(- (load_config().get("agent", {}) or {}).get("environment_hint", "")+ (load_config_readonly().get("agent", {}) or {}).get("environment_hint", "")).strip()except Exception as e:logger.debug("Could not read agent.environment_hint from config: %s", e)@@ -1300,9 +1300,9 @@ def _get_context_file_max_chars(context_length: Optional[int] = None) -> int:3. ``CONTEXT_FILE_MAX_CHARS`` (20K) as the upstream-compatible fallback."""try:- from hermes_cli.config import load_config+ from hermes_cli.config import load_config_readonly- val = load_config().get("context_file_max_chars")+ val = load_config_readonly().get("context_file_max_chars")if isinstance(val, (int, float)) and val > 0:return int(val)except Exception as e:diff --git a/agent/skill_preprocessing.py b/agent/skill_preprocessing.pyindex 19c6eeb80fb..44c5714b9b3 100644--- a/agent/skill_preprocessing.py+++ b/agent/skill_preprocessing.py@@ -25,9 +25,9 @@ _INLINE_SHELL_MAX_OUTPUT = 4000def load_skills_config() -> dict:"""Load the ``skills`` section of config.yaml (best-effort)."""try:- from hermes_cli.config import load_config+ from hermes_cli.config import load_config_readonly- cfg = load_config() or {}+ cfg = load_config_readonly() or {}skills_cfg = cfg.get("skills")if isinstance(skills_cfg, dict):return skills_cfgdiff --git a/agent/title_generator.py b/agent/title_generator.pyindex bb44da276ec..80dcdd10c72 100644--- a/agent/title_generator.py+++ b/agent/title_generator.py@@ -43,10 +43,10 @@ _TITLE_PROMPT_PINNED_LANGUAGE = (def _title_language() -> str:"""Return configured title language, or empty string to match the user."""try:- from hermes_cli.config import load_config+ from hermes_cli.config import load_config_readonlyreturn str(- ((load_config() or {}).get("auxiliary") or {})+ ((load_config_readonly() or {}).get("auxiliary") or {}).get("title_generation", {}).get("language", "")).strip()diff --git a/agent/verification_stop.py b/agent/verification_stop.pyindex 1f68b1aace5..ac5bc852d0b 100644--- a/agent/verification_stop.py+++ b/agent/verification_stop.py@@ -149,9 +149,9 @@ def verify_on_stop_enabled(config: dict[str, Any] | None = None) -> bool:return env.strip().lower() not in {"0", "false", "no", "off"}if config is None:try:- from hermes_cli.config import load_config+ from hermes_cli.config import load_config_readonly- config = load_config()+ config = load_config_readonly()except Exception:config = {}agent_cfg = (config or {}).get("agent") if isinstance(config, dict) else Nonediff --git a/agent/video_gen_registry.py b/agent/video_gen_registry.pyindex c4d28e39ed4..d78babfc9bb 100644--- a/agent/video_gen_registry.py+++ b/agent/video_gen_registry.py@@ -84,9 +84,9 @@ def get_active_provider() -> Optional[VideoGenProvider]:"""configured: Optional[str] = Nonetry:- from hermes_cli.config import load_config+ from hermes_cli.config import load_config_readonly- cfg = load_config()+ cfg = load_config_readonly()section = cfg.get("video_gen") if isinstance(cfg, dict) else Noneif isinstance(section, dict):raw = section.get("provider")diff --git a/agent/web_search_registry.py b/agent/web_search_registry.pyindex 45832cb5488..dd46eb68118 100644--- a/agent/web_search_registry.py+++ b/agent/web_search_registry.py@@ -98,9 +98,9 @@ def get_provider(name: str) -> Optional[WebSearchProvider]:def _read_config_key(*path: str) -> Optional[str]:"""Resolve a dotted config key from ``config.yaml``. Returns None on miss."""try:- from hermes_cli.config import load_config+ from hermes_cli.config import load_config_readonly- cfg = load_config()+ cfg = load_config_readonly()cur = cfgfor segment in path:if not isinstance(cur, dict):