context-length-fix.patch
Summary
When switching providers mid-session via /model, the top-level model.context_length from config.yaml is stored as _config_context_length at startup and never re-resolved. This causes the context window of the new provider to be silently shadowed by the old provider's value.
Steps to Reproduce
- Configure
config.yaml with a cloud provider as default:
model:
default: mimo-v2.5-pro
provider: custom
base_url: http://localhost:4000/v1
api_key: sk-xxx
context_length: 1000000
providers:
local:
name: local
base_url: http://localhost:8080/v1
api_key: "not-needed"
model: gemma-4-26b
context_length: 8192
- Start Hermes — context window shows 1M (correct for cloud).
- Switch to local provider:
/model gemma-4-26b --provider custom:local
- Check
/status — context window still shows 1M instead of 8192.
Expected Behavior
After switching to a provider with context_length: 8192, the context window should reflect 8192.
Actual Behavior
The context window remains at 1,000,000 — the stale _config_context_length from startup shadows the new provider's value.
Root Cause
In run_agent.py, _config_context_length is resolved once during __init__ from model.context_length (line ~2194) and stored as self._config_context_length. When switch_model() calls get_model_context_length() (line ~2679), it passes this stale value as config_context_length, which takes precedence over the new provider's context_length.
Fix
In switch_model(), re-resolve _config_context_length from the live config before updating the context compressor. If the new provider doesn't match the default provider, clear the stale value so the new provider's per-model/per-provider context_length takes effect.
Environment
- Hermes Agent v2026.4.x (Docker)
- WSL2 / Linux
- Multiple providers: cloud (LiteLLM proxy, 1M ctx) + local (llamacpp, 8K ctx)
context-length-fix.patch
Summary
When switching providers mid-session via
/model, the top-levelmodel.context_lengthfromconfig.yamlis stored as_config_context_lengthat startup and never re-resolved. This causes the context window of the new provider to be silently shadowed by the old provider's value.Steps to Reproduce
config.yamlwith a cloud provider as default:/model gemma-4-26b --provider custom:local/status— context window still shows 1M instead of 8192.Expected Behavior
After switching to a provider with
context_length: 8192, the context window should reflect 8192.Actual Behavior
The context window remains at 1,000,000 — the stale
_config_context_lengthfrom startup shadows the new provider's value.Root Cause
In
run_agent.py,_config_context_lengthis resolved once during__init__frommodel.context_length(line ~2194) and stored asself._config_context_length. Whenswitch_model()callsget_model_context_length()(line ~2679), it passes this stale value asconfig_context_length, which takes precedence over the new provider'scontext_length.Fix
In
switch_model(), re-resolve_config_context_lengthfrom the live config before updating the context compressor. If the new provider doesn't match the default provider, clear the stale value so the new provider's per-model/per-provider context_length takes effect.Environment