fix(cli): hermes model offers reasoning effort when the model ID is unchanged
The post-pick effort step compared only model.default, so switching provider while keeping the same model ID (OpenRouter -> Nous Portal with anthropic/claude-opus-5.5) or re-picking the current model skipped the prompt entirely. Chat /model always offers the effort after a pick. Count _save_model_choice calls (every flow persists through it) and offer the effort whenever a flow saved a pick; cancel / "No change." still never prompts. Supersedes #110468, which found the same-model provider switch first. Co-authored-by: ehz0ah <haozhe4547@gmail.com>
This commit is contained in:
@@ -282,9 +282,18 @@ def _prompt_model_selection(
|
||||
return None
|
||||
|
||||
|
||||
_model_choice_saves = 0 # bumped per saved pick; `hermes model` reads it to know a pick landed
|
||||
|
||||
|
||||
def model_choice_save_count() -> int:
|
||||
return _model_choice_saves
|
||||
|
||||
|
||||
def _save_model_choice(model_id: str) -> None:
|
||||
"""Save the selected model to config.yaml only — NOT .env, which would stomp in multi-agent setups."""
|
||||
global _model_choice_saves
|
||||
from hermes_cli.config import save_config, load_config
|
||||
_model_choice_saves += 1
|
||||
config = load_config()
|
||||
# Always use dict format so provider/base_url can be stored alongside
|
||||
if isinstance(config.get("model"), dict):
|
||||
|
||||
@@ -828,6 +828,7 @@ from hermes_cli.main_provider_setup import (
|
||||
_build_provider_picker_rows,
|
||||
_clear_stale_openai_base_url,
|
||||
_is_profile_api_key_provider,
|
||||
_model_choice_save_count,
|
||||
_named_custom_provider_map,
|
||||
_offer_reasoning_after_pick,
|
||||
_prompt_main_reasoning_effort,
|
||||
@@ -2079,6 +2080,7 @@ def select_provider_and_model(args=None):
|
||||
# Provider-specific setup + model selection. Flows resolve the
|
||||
# _model_flow_* names at call time so test monkeypatches on
|
||||
# hermes_cli.main keep intercepting.
|
||||
saves_before = _model_choice_save_count()
|
||||
from hermes_cli.observability.shared_metrics_setup import cli_provider_setup
|
||||
with cli_provider_setup(selected_provider):
|
||||
flow = _PROVIDER_MODEL_FLOWS.get(selected_provider)
|
||||
@@ -2107,9 +2109,7 @@ def select_provider_and_model(args=None):
|
||||
):
|
||||
_model_flow_api_key_provider(config, selected_provider, current_model)
|
||||
|
||||
# Every flow persists through _save_model_choice; a changed model.default means a pick
|
||||
# landed, so offer its reasoning effort here once instead of inside each flow.
|
||||
_offer_reasoning_after_pick(current_model)
|
||||
_offer_reasoning_after_pick(current_model, saves_before)
|
||||
|
||||
# Post-switch cleanup: switching to a named provider (anything except
|
||||
# "custom") leaves a stale OPENAI_BASE_URL in ~/.hermes/.env that poisons
|
||||
|
||||
@@ -639,17 +639,25 @@ def _prompt_reasoning_effort_selection(efforts, current_effort="", *, default_la
|
||||
return tail_values[idx - n]
|
||||
|
||||
|
||||
def _offer_reasoning_after_pick(model_before: str) -> None:
|
||||
"""Post-flow effort step for ``select_provider_and_model``: when a flow saved a different
|
||||
``model.default`` (every flow persists through ``_save_model_choice``), offer the effort for
|
||||
the new model + provider. A flow that made no change (cancel, "No change.") never prompts."""
|
||||
def _model_choice_save_count() -> int:
|
||||
"""Snapshot taken by ``select_provider_and_model`` before a flow runs (see below)."""
|
||||
from hermes_cli.auth_model_picker import model_choice_save_count
|
||||
return model_choice_save_count()
|
||||
|
||||
|
||||
def _offer_reasoning_after_pick(model_before: str, saves_before: int) -> None:
|
||||
"""Post-flow effort step for ``select_provider_and_model``, like the chat ``/model`` picker:
|
||||
every flow persists through ``_save_model_choice``, so whenever one saved a pick (or
|
||||
``model.default`` changed) offer the effort for the saved model + provider, including a
|
||||
provider switch that keeps the same model ID or a re-pick of the current model. Cancel /
|
||||
"No change." never prompts."""
|
||||
from hermes_cli.config import load_config
|
||||
model_cfg = load_config().get("model")
|
||||
if not isinstance(model_cfg, dict):
|
||||
return
|
||||
model = str(model_cfg.get("default") or "").strip()
|
||||
if not model or model == model_before:
|
||||
return # same model re-picked or nothing saved: the "Reasoning effort" row covers that
|
||||
if not model or (model == model_before and _model_choice_save_count() == saves_before):
|
||||
return
|
||||
_prompt_main_reasoning_effort(model, str(model_cfg.get("provider") or ""))
|
||||
|
||||
|
||||
|
||||
@@ -32,3 +32,30 @@ def test_current_reasoning_effort_reads_dict_form():
|
||||
assert _current_reasoning_effort({"agent": {"reasoning_effort": {"enabled": True, "effort": "Thinking"}}}) == "thinking"
|
||||
assert _current_reasoning_effort({"agent": {"reasoning_effort": {"enabled": False}}}) == "none"
|
||||
assert _current_reasoning_effort({"agent": {"reasoning_effort": "high"}}) == "high"
|
||||
|
||||
|
||||
def test_hermes_model_offers_reasoning_whenever_a_pick_is_saved(tmp_path, monkeypatch):
|
||||
"""Same model ID on a new provider, or a re-pick of the current model, still gets the effort
|
||||
step (like chat /model); a flow that saves nothing does not."""
|
||||
import hermes_cli.main as main
|
||||
from hermes_cli.auth import _save_model_choice
|
||||
from hermes_cli.config import load_config, save_config
|
||||
|
||||
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
||||
save_config({**load_config(), "model": {"default": "m", "provider": "openrouter"}})
|
||||
prompted = []
|
||||
monkeypatch.setattr("hermes_cli.main_provider_setup._prompt_main_reasoning_effort",
|
||||
lambda model, provider: prompted.append((model, provider)))
|
||||
monkeypatch.setattr(main, "_clear_stale_openai_base_url", lambda: None)
|
||||
|
||||
def _pick_same_model_on_nous(config, current_model, args):
|
||||
_save_model_choice(current_model)
|
||||
save_config({**load_config(), "model": {"default": current_model, "provider": "nous"}})
|
||||
|
||||
for slug, flow, expected in (("nous", _pick_same_model_on_nous, [("m", "nous")]),
|
||||
("anthropic", lambda c, m, a: print("No change."), [])):
|
||||
prompted.clear()
|
||||
monkeypatch.setattr(main, "_pick_provider", lambda *a, _s=slug, **k: _s)
|
||||
monkeypatch.setitem(main._PROVIDER_MODEL_FLOWS, slug, flow)
|
||||
main.select_provider_and_model()
|
||||
assert prompted == expected
|
||||
|
||||
Reference in New Issue
Block a user