Bug Description
When running Hermes in CLI mode (not gateway), changing the model's context length on the provider side (e.g., adjusting it in LM Studio) and then typing /new leaves the old context_length value active. The TUI status bar continues displaying the stale context window size until you restart the Hermes process.
Gateway mode does not have this bug — it evicts the cached agent entirely on /new, so a fresh ContextCompressor is created on the next message with the correct value from the provider.
What happened
The context window size displayed in the TUI status bar comes from agent.context_compressor.context_length, which is populated by calling get_model_context_length() at ContextCompressor construction time (probe + fallback chain). This probes the model metadata for the configured model/provider to determine the actual context length.
In gateway mode, /new calls _evict_cached_agent() which removes the old agent from the cache. The next incoming message creates a brand-new AIAgent with a fresh ContextCompressor, so the new context length is picked up immediately.
In CLI mode, /new calls self.agent.reset_session_state() (cli.py:6288) which resets token counters, session ID, and conversation history — but it does not recreate or reinitialize the context_compressor. The existing agent object is reused, so the stale context_length from the previous session persists.
Steps to Reproduce
- Start Hermes CLI connected to a local provider (e.g., LM Studio at http://127.0.0.1:1234/v1)
- Note the context window size shown in the TUI status bar (e.g., 8192 — the default for an unknown model)
- In LM Studio, change the context length setting for your model to a larger value (e.g., 134400)
- Type /new in Hermes CLI to start a fresh session
- Observe the status bar — it still shows the old value (8192) instead of the updated 134400
- Restart the Hermes process entirely
- Observe that the status bar now correctly displays the updated context window size
Expected Behavior
The status bar should immediately reflect the new context length after /new.
Actual Behavior
The status bar continues showing the old context length until Hermes is restarted.
Affected Component
CLI (interactive chat)
Messaging Platform (if gateway-related)
No response
Debug Report
Do not want to share: not needed for fixing the issue.
Operating System
Ubuntu 24.04.4 via WSL on Windows 11
Python Version
3.11.15
Hermes Version
0.14.0
Additional Logs / Traceback (optional)
Root Cause Analysis (optional)
Root cause code paths
- Where context length is read: agent/context_compressor.py:544 — ContextCompressor.init calls get_model_context_length()
- Where CLI /new resets state: cli.py:6288 — self.agent.reset_session_state() (resets counters only, does not touch compressor)
- Where gateway correctly handles this: gateway/run.py:9094 — _evict_cached_agent(session_key) evicts the agent entirely
Environment
- Hermes Agent version: 0.14.0
- Platform: CLI (not gateway)
- Provider: LM Studio (local)
- OS: WSL2
Proposed Fix (optional)
The fix is in cli.py in the new_session() method (around line 6288). After calling self.agent.reset_session_state(), add logic to reinitialize the context compressor so it re-reads the context length:
python
In cli.py, inside new_session(), after self.agent.reset_session_state():
if hasattr(self.agent, "context_compressor") and self.agent.context_compressor is not None:
# Re-probe the context length from the provider in case it changed.
# Create a fresh ContextCompressor with the same parameters.
from agent.context_compressor import ContextCompressor
comp = self.agent.context_compressor
self.agent.context_compressor = ContextCompressor(
model=self.model,
threshold_percent=comp.threshold_percent,
protect_first_n=comp.protect_first_n,
protect_last_n=comp.protect_last_n,
summary_target_ratio=comp.summary_target_ratio,
quiet_mode=True,
base_url=getattr(self.agent, "base_url", "") or "",
api_key=getattr(self.agent, "api_key", ""),
config_context_length=None, # Let it probe from provider
provider=getattr(self.agent, "provider", ""),
api_mode=getattr(self.agent, "api_mode", ""),
)
Alternative (simpler) approach: add a method like reset_context_length() to the agent class that recreates just the compressor without losing other state.
Reproduction steps
1. Start Hermes CLI with a local provider (e.g., LM Studio at http://127.0.0.1:1234/v1)
2. Note the context window size in the status bar (e.g., 8192 — the default for an unknown model)
3. In LM Studio, change the context length setting for your model to 134400
4. Type /new in Hermes CLI
5. Observe that the status bar still shows the old value (8192) instead of 134400
6. Restart Hermes — the correct value now appears
Are you willing to submit a PR for this?
Bug Description
When running Hermes in CLI mode (not gateway), changing the model's context length on the provider side (e.g., adjusting it in LM Studio) and then typing /new leaves the old context_length value active. The TUI status bar continues displaying the stale context window size until you restart the Hermes process.
Steps to Reproduce
Expected Behavior
The status bar should immediately reflect the new context length after /new.
Actual Behavior
The status bar continues showing the old context length until Hermes is restarted.
Affected Component
CLI (interactive chat)
Messaging Platform (if gateway-related)
No response
Debug Report
Do not want to share: not needed for fixing the issue.Operating System
Ubuntu 24.04.4 via WSL on Windows 11
Python Version
3.11.15
Hermes Version
0.14.0
Additional Logs / Traceback (optional)
Root Cause Analysis (optional)
Root cause code paths
Proposed Fix (optional)
The fix is in cli.py in the new_session() method (around line 6288). After calling self.agent.reset_session_state(), add logic to reinitialize the context compressor so it re-reads the context length:
Are you willing to submit a PR for this?