mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
fix(agent): default missing fallback chain on switch
This commit is contained in:
parent
46451528a5
commit
a9fd8d7c88
2 changed files with 16 additions and 3 deletions
|
|
@ -2119,12 +2119,14 @@ class AIAgent:
|
|||
# ("switched to anthropic, tui keeps trying openrouter").
|
||||
old_norm = (old_provider or "").strip().lower()
|
||||
new_norm = (new_provider or "").strip().lower()
|
||||
fallback_chain = list(getattr(self, "_fallback_chain", []) or [])
|
||||
if old_norm and new_norm and old_norm != new_norm:
|
||||
self._fallback_chain = [
|
||||
entry for entry in self._fallback_chain
|
||||
fallback_chain = [
|
||||
entry for entry in fallback_chain
|
||||
if (entry.get("provider") or "").strip().lower() not in {old_norm, new_norm}
|
||||
]
|
||||
self._fallback_model = self._fallback_chain[0] if self._fallback_chain else None
|
||||
self._fallback_chain = fallback_chain
|
||||
self._fallback_model = fallback_chain[0] if fallback_chain else None
|
||||
|
||||
logging.info(
|
||||
"Model switched in-place: %s (%s) -> %s (%s)",
|
||||
|
|
|
|||
|
|
@ -78,6 +78,17 @@ def test_switch_with_empty_chain_stays_empty():
|
|||
assert agent._fallback_model is None
|
||||
|
||||
|
||||
def test_switch_initializes_missing_fallback_attrs():
|
||||
agent = _make_agent([])
|
||||
del agent._fallback_chain
|
||||
del agent._fallback_model
|
||||
|
||||
_switch_to_anthropic(agent)
|
||||
|
||||
assert agent._fallback_chain == []
|
||||
assert agent._fallback_model is None
|
||||
|
||||
|
||||
def test_switch_within_same_provider_preserves_chain():
|
||||
chain = [{"provider": "openrouter", "model": "x-ai/grok-4"}]
|
||||
agent = _make_agent(chain)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue