Fixing Model Identity Desync When LM Studio Swaps Models Mid-Session

Hermes agent was reporting stale model information after users switched models in LM Studio during an active session. This fix re-syncs the cached model identity from each API response to reflect the currently loaded model.
What
The Hermes agent caches model identity information in system prompts at session start. When LM Studio users swapped to a different model mid-session, Hermes continued reporting the original model name instead of the new one. The fix detects model changes from LM Studio responses and updates the cached identity using the existing rewrite_prompt_model_identity helper function. Five new tests validate the re-sync behavior across different model swap scenarios.
Why it matters
Users expect accurate model reporting when they actively switch models during a session. Stale model identity in responses creates confusion about which model is actually processing requests. This matters for debugging, logging, and user transparency in multi-model workflows. The fix ensures the agent's reported state stays synchronized with LM Studio's actual state.
Who it's for
Developers using Hermes with LM Studio who switch between different models during long-running sessions. This includes researchers testing multiple model variants and users comparing model outputs in real time.
When & where
This issue appears in the lmstudio integration path when session duration spans multiple model swaps. The fix is currently in draft PR status at NousResearch/hermes-agent pull request 58880 and has not yet been merged to main.
How
The solution hooks into the response handling pipeline to detect when LM Studio has loaded a different model. Each response from LM Studio includes the current model identifier. The fix compares this against the cached identity and calls rewrite_prompt_model_identity to update the session cache when a mismatch is detected. This reuses existing utility code rather than introducing new logic.
Takeaway
Session state caching is powerful for performance but needs active invalidation when external systems change. The fix demonstrates how to bridge the gap between cached assumptions and live external state by leveraging existing helper functions. This pattern applies broadly to any agent that maintains cached state about external services.
Draft PR: https://github.com/NousResearch/hermes-agent/pull/58880
Building an AI agent?
I'm packaging how I ship them into one kit. Early access:
AI Agent Starter Kit →