mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-31 19:16:29 +00:00
fix(providers): scope route-owned runtime settings
This commit is contained in:
parent
f3f0135154
commit
63dd651b3d
21 changed files with 794 additions and 167 deletions
25
cli.py
25
cli.py
|
|
@ -8171,6 +8171,29 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin, CLIBillingMixin):
|
|||
scroll_offset = max(0, min(scroll_offset, n - visible))
|
||||
return scroll_offset, visible
|
||||
|
||||
def _clear_persisted_context_for_model_switch(self, result) -> None:
|
||||
"""Drop a global context pin when its configured owner changes."""
|
||||
try:
|
||||
from agent.agent_init import _context_route_mismatch
|
||||
from hermes_cli.config import load_config_readonly
|
||||
|
||||
config = load_config_readonly()
|
||||
model_cfg = config.get("model", {}) if isinstance(config, dict) else {}
|
||||
if not isinstance(model_cfg, dict) or "context_length" not in model_cfg:
|
||||
return
|
||||
configured_model = model_cfg.get("default") or model_cfg.get("model")
|
||||
if (
|
||||
configured_model and configured_model != result.new_model
|
||||
) or _context_route_mismatch(
|
||||
model_cfg.get("base_url"),
|
||||
result.base_url,
|
||||
model_cfg.get("provider"),
|
||||
result.target_provider,
|
||||
):
|
||||
save_config_value("model.context_length", None)
|
||||
except Exception:
|
||||
save_config_value("model.context_length", None)
|
||||
|
||||
def _apply_model_switch_result(self, result, persist_global: bool) -> None:
|
||||
if not result.success:
|
||||
_cprint(f" ✗ {result.error_message}")
|
||||
|
|
@ -8289,6 +8312,7 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin, CLIBillingMixin):
|
|||
if result.warning_message:
|
||||
_cprint(f" ⚠ {result.warning_message}")
|
||||
if persist_global:
|
||||
HermesCLI._clear_persisted_context_for_model_switch(self, result)
|
||||
save_config_value("model.default", result.new_model)
|
||||
if result.provider_changed:
|
||||
save_config_value("model.provider", result.target_provider)
|
||||
|
|
@ -8635,6 +8659,7 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin, CLIBillingMixin):
|
|||
|
||||
# Persistence
|
||||
if persist_global:
|
||||
HermesCLI._clear_persisted_context_for_model_switch(self, result)
|
||||
save_config_value("model.default", result.new_model)
|
||||
if result.provider_changed:
|
||||
save_config_value("model.provider", result.target_provider)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue