fix(gateway): honor custom provider context length#5096
Closed
dlkakbs wants to merge 1 commit into
Closed
Conversation
4 tasks
pinch-claw
added a commit
to pinch-claw/hermes-agent
that referenced
this pull request
Apr 23, 2026
…nner The session-reset / info banner in `_format_session_info` resolved the context window only from the top-level `model.context_length` key. When users configured context_length under the new `providers.<name>.models.<model>` dict schema (or the legacy `custom_providers[].models.<model>` list schema), the banner fell through to `get_model_context_length()`'s probe chain. Remote OpenAI-compatible proxies frequently omit `context_length` from `/models` responses, so the probe failed silently and the banner displayed `128K tokens (default — set model.context_length in config to override)` — even though the runtime `ContextCompressor` was already budgeting with the correct value resolved by `AIAgent.__init__`. After the top-level lookup, walk `get_compatible_custom_providers(cfg)`, match the entry by `base_url` against the resolved runtime base_url, and read `entry["models"][model]["context_length"]`. This mirrors the exact resolution `AIAgent.__init__` performs at `run_agent.py:1608-1643` so the banner's displayed value matches what the compressor actually uses. Fixes NousResearch#5089. Relationship to existing open PRs (NousResearch/hermes-agent): - NousResearch#5096, NousResearch#8240, NousResearch#10690: each hand-roll traversal of the legacy `custom_providers:` list only. They do not cover the newer `providers:` dict schema users land on via `hermes model`. - NousResearch#12380: touches `/model` display + gateway fallback paths; overlaps in spirit but still traverses lists manually. Routing through `get_compatible_custom_providers()` — the existing compat shim at `hermes_cli/config.py:2078` — gives a single lookup that covers both schemas and stays consistent with every other runtime caller, eliminating future drift between display and compressor.
Contributor
|
Thanks for this fix, @dlkakbs! The issue you identified is real, but it has since been addressed on What landed on main:
This is an automated hermes-sweeper review. The cross-references to PRs #15668 and #15669 in the timeline also point to overlapping work in this area that has since landed. |
This was referenced Apr 27, 2026
Collaborator
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #5089
Summary:
This fixes gateway context-length resolution for models configured under custom_providers. When model.context_length is not set at the top level, the gateway status banner was incorrectly falling back to the default 128K context window instead of using the per-model context_length defined on the matching custom provider.
Related: #4085 fixed the gateway hygiene compression path for custom_providers context length resolution. This PR addresses the remaining gateway status/session info path and also makes the gateway-side lookup handle list-shaped custom_providers.models entries from the current repro.
Root cause:
_format_session_info() only read model.context_length from the top-level config and never resolved per-model context_length from custom_providers. The gateway hygiene path also assumed custom_providers[].models was always dict-shaped, so list-shaped model entries were skipped.
What changed:
Testing: