mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-24 10:52:21 +00:00
fix(cli): warn when in-session model switch will preflight-compress
Adds hermes_cli/context_switch_guard.py mirroring the model_cost_guard pattern. When a user switches models mid-session (Herm TUI picker, CLI, or /model on Telegram/Discord), the warning surfaces on the existing ModelSwitchResult.warning_message path used by the expensive-model guard if the new model's compression threshold is below the current session size. Partial fix for #23767 — addresses only the 'user-facing guardrail when switching from a high-context provider to a substantially lower-context provider' slice. The other proposed fixes from that issue (hard preflight token guard, metadata cache invalidation on switch, compression safety invariant, oversized tool-output handling) are out of scope for this PR.
This commit is contained in:
parent
7b9a0b315b
commit
04730f32e7
6 changed files with 361 additions and 1 deletions
26
cli.py
26
cli.py
|
|
@ -6936,6 +6936,19 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin):
|
|||
_cprint(f" ✗ {result.error_message}")
|
||||
return
|
||||
|
||||
if self.agent is not None:
|
||||
try:
|
||||
from hermes_cli.context_switch_guard import merge_preflight_compression_warning
|
||||
|
||||
merge_preflight_compression_warning(
|
||||
result,
|
||||
agent=self.agent,
|
||||
messages=list(self.conversation_history or []),
|
||||
config_context_length=getattr(self.agent, "_config_context_length", None),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
old_model = self.model
|
||||
self.model = result.new_model
|
||||
self.provider = result.target_provider
|
||||
|
|
@ -7202,6 +7215,19 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin):
|
|||
_cprint(f" ✗ {result.error_message}")
|
||||
return
|
||||
|
||||
if self.agent is not None:
|
||||
try:
|
||||
from hermes_cli.context_switch_guard import merge_preflight_compression_warning
|
||||
|
||||
merge_preflight_compression_warning(
|
||||
result,
|
||||
agent=self.agent,
|
||||
messages=list(self.conversation_history or []),
|
||||
config_context_length=getattr(self.agent, "_config_context_length", None),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if not self._confirm_expensive_model_switch(result):
|
||||
_cprint(" Model switch cancelled.")
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue