refactor: extract duplicated load_config_readonly try/except into helper

The identical 6-line try/except block for reading model.reasoning_echo
from config appeared in both agent_init.py (init) and
agent_runtime_helpers.py (switch_model). Extracted into
AIAgent._read_reasoning_echo_from_config() static method — net -1 LOC.
This commit is contained in:
kshitij kapoor
2026-08-19 23:48:08 +05:30
committed by kshitij
parent 7e3775de2e
commit b2057c1685
3 changed files with 13 additions and 14 deletions
+1 -7
View File
@@ -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
+1 -7
View File
@@ -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
+11
View File
@@ -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.