Bug Description
When smart_model_routing is enabled, the background memory review (_spawn_background_review) never triggers in gateway mode. The _turns_since_memory counter resets to 0 on every message because smart routing causes agent cache misses.
Root Cause
The turn counter _turns_since_memory lives on the AIAgent instance. In gateway mode, smart routing alternates between cheap and strong models, changing the config signature each time. This causes the agent cache to miss (_agent_config_signature differs), creating a fresh AIAgent whose __init__ resets _turns_since_memory = 0.
With nudge_interval: 3, the counter goes: 0→1, 0→1, 0→1, ... instead of 0→1→2→3 (trigger!).
Call Chain
Message 1 (simple → cheap model, sig=A):
new AIAgent → _turns_since_memory = 0 → run_conversation → += 1 → saved as 1
Message 2 (complex → strong model, sig=B):
cache miss → new AIAgent → _turns_since_memory = 0 ← RESET!
→ run_conversation → += 1 → saved as 1 (should be 2)
Impact
- Memory nudge never fires →
_spawn_background_review never runs
- Agent says "记得了" (remembered) but never calls the memory tool
- User information is lost across sessions
Reproduction
- Enable
smart_model_routing with a cheap local model and a strong cloud model
- Set
memory.nudge_interval: 3
- Send 10+ messages alternating simple ("你好") and complex ("帮我查天气")
- Check
~/.hermes/memories/USER.md — never updated
- Check logs — no
_spawn_background_review activity
Environment
- Hermes Agent v0.8.0
- Gateway mode with BlueBubbles (iMessage)
- Smart routing: local Qwen 9B (cheap) + SiliconFlow MiniMax-M2.5 (strong)
nudge_interval: 3
Suggested Fix
Persist _turns_since_memory at the GatewayRunner level (per session_key) so it survives agent cache misses. Restore on agent creation, save after run_conversation completes.
Bug Description
When
smart_model_routingis enabled, the background memory review (_spawn_background_review) never triggers in gateway mode. The_turns_since_memorycounter resets to 0 on every message because smart routing causes agent cache misses.Root Cause
The turn counter
_turns_since_memorylives on theAIAgentinstance. In gateway mode, smart routing alternates between cheap and strong models, changing the config signature each time. This causes the agent cache to miss (_agent_config_signaturediffers), creating a freshAIAgentwhose__init__resets_turns_since_memory = 0.With
nudge_interval: 3, the counter goes:0→1, 0→1, 0→1, ...instead of0→1→2→3 (trigger!).Call Chain
Impact
_spawn_background_reviewnever runsReproduction
smart_model_routingwith a cheap local model and a strong cloud modelmemory.nudge_interval: 3~/.hermes/memories/USER.md— never updated_spawn_background_reviewactivityEnvironment
nudge_interval: 3Suggested Fix
Persist
_turns_since_memoryat theGatewayRunnerlevel (per session_key) so it survives agent cache misses. Restore on agent creation, save afterrun_conversationcompletes.