fix(config): propagate max_tokens from config.yaml to AI transport (#20741)#20769
Closed
Beandon13 wants to merge 1 commit into
Closed
fix(config): propagate max_tokens from config.yaml to AI transport (#20741)#20769Beandon13 wants to merge 1 commit into
Beandon13 wants to merge 1 commit into
Conversation
…ousResearch#20741) model.max_tokens documented in cli-config.yaml.example was silently ignored — never read from config and never forwarded to AIAgent.__init__() or ChatCompletionsTransport.build_kwargs(). On providers without a hardcoded output cap (Ollama Cloud, zai, custom OpenAI-compatible endpoints) the parameter was omitted from the API call entirely, causing truncation. Three gaps fixed: 1. cli.py: HermesCLI.__init__ now reads model.max_tokens from CLI_CONFIG (falling back to HERMES_MAX_TOKENS env var) and stores it as self.max_tokens. Both the interactive and background AIAgent construction sites pass max_tokens=self.max_tokens. 2. gateway/run.py: new _resolve_config_max_tokens() helper reads model.max_tokens from ~/.hermes/config.yaml (with HERMES_MAX_TOKENS env-var override). _resolve_runtime_agent_kwargs() returns the value; and _resolve_turn_agent_config() copies it into the runtime dict so all six AIAgent(...) call sites receive it via **turn_route["runtime"] or **runtime_kwargs. 3. ChatCompletionsTransport.build_kwargs() already honours max_tokens when non-None — no changes needed there. Also adds tests/test_max_tokens_config_propagation.py with 13 tests covering _resolve_config_max_tokens, _resolve_runtime_agent_kwargs, and the CLI max_tokens resolution logic (all 13 pass). Fixes: NousResearch#20741 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
|
Automated hermes-sweeper review: this PR's fix is already implemented on main via the merged #39864 path. Evidence:
Thanks for the original fix and test work here. The main-branch implementation preserves the same core behavior and widens it to the per-provider cap path as well. |
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.
Summary
Fixes #20741. The
model.max_tokenskey documented incli-config.yaml.examplewas silently ignored — never read from config and never forwarded toAIAgent.__init__()orChatCompletionsTransport.build_kwargs(). On providers without a hardcoded output cap (Ollama Cloud, zai, custom OpenAI-compatible endpoints) the parameter was omitted from the API call entirely, causingfinish_reason="length"truncation.Three independent gaps fixed:
CLI path (
cli.py):HermesCLI.__init__now readsmodel.max_tokensfromCLI_CONFIG(withHERMES_MAX_TOKENSenv-var override) and stores it asself.max_tokens. Both the interactive agent and the background agentAIAgent(...)construction sites passmax_tokens=self.max_tokens.Gateway path (
gateway/run.py): new_resolve_config_max_tokens()helper readsmodel.max_tokensfrom~/.hermes/config.yaml(same env-var override)._resolve_runtime_agent_kwargs()includes the value;_resolve_turn_agent_config()copies it into theruntimedict so all sixAIAgent(...)sites receive it via**turn_route["runtime"]or**runtime_kwargs.Transport layer (
ChatCompletionsTransport.build_kwargs): already honoursmax_tokenswhen non-None — no changes needed.Test proof
Files changed
cli.pymodel.max_tokens/HERMES_MAX_TOKENS; store asself.max_tokens; pass to bothAIAgentsitesgateway/run.py_resolve_config_max_tokens(); includemax_tokensin_resolve_runtime_agent_kwargs()and_resolve_turn_agent_config()tests/test_max_tokens_config_propagation.pyCHANGELOG.md🤖 Generated with Claude Code