Skip to content

The agent that grows with you

refactor: extract duplicated load_config_readonly try/except into helper

kshitij kapoorb2057c16856f
diff --git a/agent/agent_init.py b/agent/agent_init.py
index da92e6f8812..20e44607bbd 100644
--- a/agent/agent_init.py
+++ b/agent/agent_init.py
@@ -916,13 +916,7 @@ def init_agent(
# Per-provider reasoning_content echo opt-in (see _reasoning_echo_opt_in).
# Read once at init; switch_model / try_activate_fallback / restore
# keep it in sync with the active provider.
- try:
- from hermes_cli.config import load_config_readonly
- agent._reasoning_echo_flag = bool(
- (load_config_readonly().get("model") or {}).get("reasoning_echo")
- )
- except Exception:
- agent._reasoning_echo_flag = False
+ agent._reasoning_echo_flag = agent._read_reasoning_echo_from_config()
agent.service_tier = service_tier
agent.request_overrides = dict(request_overrides or {})
agent.prefill_messages = prefill_messages or [] # Prefilled conversation turns
diff --git a/agent/agent_runtime_helpers.py b/agent/agent_runtime_helpers.py
index bcb1cc3a04e..dbbb0d11e9c 100644
--- a/agent/agent_runtime_helpers.py
+++ b/agent/agent_runtime_helpers.py
@@ -2690,13 +2690,7 @@ def switch_model(agent, new_model, new_provider, api_key='', base_url='', api_mo
agent.requested_provider = new_provider
# Re-read reasoning_echo from config so the flag reflects the new
# primary model's setting (see _reasoning_echo_opt_in).
- try:
- from hermes_cli.config import load_config_readonly
- agent._reasoning_echo_flag = bool(
- (load_config_readonly().get("model") or {}).get("reasoning_echo")
- )
- except Exception:
- agent._reasoning_echo_flag = False
+ agent._reasoning_echo_flag = agent._read_reasoning_echo_from_config()
# Use the new base_url when provided. When it's empty AND the
# provider is actually changing, do NOT fall back to the current
# (old provider's) URL — that silently pairs the new provider label
diff --git a/run_agent.py b/run_agent.py
index 548c9953d83..ad8dc8d65d2 100644
--- a/run_agent.py
+++ b/run_agent.py
@@ -7790,6 +7790,17 @@ class AIAgent:
"""
return bool(getattr(self, "_reasoning_echo_flag", False))
+ @staticmethod
+ def _read_reasoning_echo_from_config() -> bool:
+ """Read ``model.reasoning_echo`` from config; False on any error."""
+ try:
+ from hermes_cli.config import load_config_readonly
+ return bool(
+ (load_config_readonly().get("model") or {}).get("reasoning_echo")
+ )
+ except Exception:
+ return False
+
def _needs_kimi_tool_reasoning(self) -> bool:
"""Return True when the current provider is Kimi / Moonshot thinking mode.