Bug Description
model.context_length in config.yaml is read once at agent initialization in agent/agent_init.py (line 1314) and stored as agent._config_context_length. When the user switches models via /model, switch_model() in agent/agent_runtime_helpers.py (line 1426) sets agent._config_context_length = None to clear the old value, but never re-reads the config file to restore the global model.context_length override.
Resolution chain after switch:
get_model_context_length(
config_context_length=None, # step 0: global override LOST
custom_providers=custom_providers_list, # step 0b: per-model override works
)
- Step 0 (
config_context_length): Always None after switch, so the global model.context_length is lost.
- Step 0b (
custom_providers per-model): Works correctly — the config file is re-read and custom_providers[i].models.<model>.context_length is honored.
- If the user only set the global
model.context_length (not per-model in custom_providers) and the custom endpoint can't auto-detect via /models -> falls through to 256K default.
This creates an inconsistent experience: the global model.context_length works at startup but silently disappears after any /model command, even when switching back to the same model.
Steps to Reproduce
- Configure in
~/.hermes/config.yaml:
model:
provider: custom:my-api
model: deepseek-v4-pro
context_length: 128000
- Start a session — context length correctly shows 128K.
- Run
/model mini-max-m2.7 then /model deepseek-v4-pro (back to original).
- Now context length shows auto-detected value (e.g. 256K), not 128K.
Expected Behavior
The global model.context_length should be re-read from config.yaml after every /model switch, so it stays effective for any model that doesn't have a per-model override.
Alternatively, if the per-model custom_providers override is the intended approach, the docs should clarify that the global model.context_length is a one-time init-only setting and per-model overrides in custom_providers.models.<name>.context_length are required for persistence across model switches.
Additional Context
Bug Description
model.context_lengthin config.yaml is read once at agent initialization inagent/agent_init.py(line 1314) and stored asagent._config_context_length. When the user switches models via/model,switch_model()inagent/agent_runtime_helpers.py(line 1426) setsagent._config_context_length = Noneto clear the old value, but never re-reads the config file to restore the globalmodel.context_lengthoverride.Resolution chain after switch:
config_context_length): AlwaysNoneafter switch, so the globalmodel.context_lengthis lost.custom_providersper-model): Works correctly — the config file is re-read andcustom_providers[i].models.<model>.context_lengthis honored.model.context_length(not per-model in custom_providers) and the custom endpoint can't auto-detect via /models -> falls through to 256K default.This creates an inconsistent experience: the global
model.context_lengthworks at startup but silently disappears after any/modelcommand, even when switching back to the same model.Steps to Reproduce
~/.hermes/config.yaml:/model mini-max-m2.7then/model deepseek-v4-pro(back to original).Expected Behavior
The global
model.context_lengthshould be re-read from config.yaml after every/modelswitch, so it stays effective for any model that doesn't have a per-model override.Alternatively, if the per-model custom_providers override is the intended approach, the docs should clarify that the global
model.context_lengthis a one-time init-only setting and per-model overrides incustom_providers.models.<name>.context_lengthare required for persistence across model switches.Additional Context
custom_providersoverride (step 0b) already works in both init and switch_model paths (fix Bug: /model switch to named custom provider ignores custom_providers model context_length #15779).get_custom_provider_context_length()inhermes_cli/config.py:3896is the shared helper used by both paths.