Skip to content

fix: preserve config_context_length when switching models - #6844

Closed
rarf wants to merge 2 commits into
NousResearch:mainfrom
rarf:fix/switch-model-context-length
Closed

fix: preserve config_context_length when switching models#6844
rarf wants to merge 2 commits into
NousResearch:mainfrom
rarf:fix/switch-model-context-length

Conversation

@rarf

@rarf rarf commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Problem

When switching models at runtime via /model <new-model>, the custom config_context_length override from config.yaml was not being passed to the new ContextCompressor instance. This caused the user-specified context length to be lost after a model switch.

Fix

  • Store _config_context_length on AIAgent instance during __init__
  • Pass _config_context_length when creating new ContextCompressor in switch_model()
  • Add test to verify config_context_length is preserved across model switches

Testing

  • Added tests/run_agent/test_switch_model_context.py with 2 test cases:
    • test_switch_model_preserves_config_context_length - verifies config override is preserved
    • test_switch_model_without_config_context_length - verifies behavior when no override is set

Fixes: quando estamos alterando o modelo não está alterando o tamanho do contexto

rarf added 2 commits April 9, 2026 23:59
When switching models at runtime, the config_context_length override
was not being passed to the new context compressor instance. This
meant the user-specified context length from config.yaml was lost
after a model switch.

- Store _config_context_length on AIAgent instance during __init__
- Pass _config_context_length when creating new ContextCompressor in switch_model
- Add test to verify config_context_length is preserved across model switches

Fixes: quando estamos alterando o modelo não está alterando o tamanho do contexto
… credential check

When opencode-go API key is set, it should appear in the /model list.
The provider was already in PROVIDER_TO_MODELS_DEV and PROVIDER_REGISTRY,
so it appears via Part 1 (built-in source).

Also fixes a potential issue in Part 2 (HERMES_OVERLAYS) where providers
with auth_type=api_key but no extra_env_vars would not be detected:
- Now also checks api_key_env_vars from PROVIDER_REGISTRY for api_key auth_type

- Add test verifying opencode-go appears when OPENCODE_GO_API_KEY is set
@trevorgordon981

Copy link
Copy Markdown
Contributor

In run_agent.py (lines 1145-1386) and hermes_cli/model_switch.py (lines 790-811), changes are made to preserve config_context_length across model switches and provider listings.

Observation: The switch_model method (lines 1383-1386) now explicitly passes config_context_length to the context compressor. However, in list_authenticated_providers (lines 800-811), the logic checks overlay.extra_env_vars and api_key_env_vars from PROVIDER_REGISTRY to determine credential presence.

Question: In list_authenticated_providers, if a provider (like opencode-go) relies on api_key_env_vars defined in PROVIDER_REGISTRY rather than extra_env_vars in HERMES_OVERLAYS, is the current logic robust enough to handle all auth types correctly? Specifically, if api_key_env_vars are updated or added to PROVIDER_REGISTRY after this code is written, will this function automatically adapt, or does it rely on hardcoded assumptions about which env vars are checked?

@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #7187. Both commits cherry-picked with your authorship preserved. Thanks for both fixes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants