fix(gateway): read custom provider context length in status#8240
Open
anthhub wants to merge 1 commit into
Open
fix(gateway): read custom provider context length in status#8240anthhub wants to merge 1 commit into
anthhub wants to merge 1 commit into
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.
This was referenced Apr 25, 2026
This was referenced Apr 30, 2026
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.
What does this PR do?
Fixes gateway session info / status context-length detection for models defined under
custom_providers.Previously
_format_session_info()only respectedmodel.context_lengthat the top level, so custom provider models with per-modelcontext_lengthmetadata fell back to the default 128K display/hint path.This PR adds a shared lookup helper for
custom_providersper-model context lengths and uses it in both session-info formatting and gateway session hygiene fallback logic.Related Issue
Fixes #5089
Type of Change
Changes Made
gateway/run.pycontext_lengthfromcustom_providers_format_session_info()to use that helper when top-levelmodel.context_lengthis absentcustom_providers[].modelsas a dict map and as a list of{name, context_length}entriestests/gateway/test_session_info.pycustom_providerslist entries carryingcontext_lengthHow to Test
Or run:
Checklist
Code
Documentation & Housekeeping