Bug Description
model.max_tokens set in ~/.hermes/config.yaml has no effect — it is never read or passed to AIAgent in either Gateway or CLI mode.
Steps to Reproduce
- Set
model.max_tokens in config.yaml:
model:
default: aws.claude-sonnet-4.6
provider: custom:friday
max_tokens: 128000
-
Use Hermes via Gateway (API server / messaging platforms) or CLI (hermes chat)
-
The upstream API receives no max_tokens parameter in the request
Expected Behavior
The configured model.max_tokens should be passed to the AIAgent constructor and included in API requests as max_tokens (or max_completion_tokens for direct OpenAI).
Actual Behavior
- Gateway mode (
gateway/run.py): _resolve_runtime_agent_kwargs() only extracts provider-related fields (api_key, base_url, provider, api_mode, etc.) — max_tokens is not included.
- CLI mode (
cli.py): AIAgent(...) is constructed without max_tokens at line ~2872. No code reads model.max_tokens from config.
AIAgent.__init__ defaults to max_tokens=None (line 799 of run_agent.py)
- When
max_tokens is None, _build_api_kwargs() skips adding it to the request (line ~6563)
Impact
Most providers default to a reasonable output limit when max_tokens is omitted. However, some providers (e.g., AWS Bedrock proxied through custom endpoints) default to very low values like 1024 tokens, causing:
- Tool call arguments getting truncated (
finish_reason: length)
- Long responses cut short (e.g., multi-step analysis, structured JSON output)
- The agent entering a truncation → retry → give up loop, returning
"Response truncated due to output length limit"
Affected Code Paths
gateway/run.py:_resolve_runtime_agent_kwargs() (line ~319) — does not read model.max_tokens from config
gateway/run.py:_resolve_turn_agent_config() (line ~967) — primary dict and route["runtime"] do not include max_tokens
cli.py (line ~2872) — AIAgent(...) constructor call missing max_tokens=
- All other
AIAgent(...) instantiation points in gateway/run.py (lines ~5690, ~5871, ~8572)
Suggested Fix
Read model.max_tokens from config and pass it through to AIAgent:
# In _resolve_runtime_agent_kwargs() or wherever config is loaded:
cfg = _load_gateway_config()
model_cfg = cfg.get("model", {})
if isinstance(model_cfg, dict):
max_tokens = model_cfg.get("max_tokens")
if max_tokens is not None:
result["max_tokens"] = int(max_tokens)
And ensure max_tokens flows through resolve_turn_route() → route["runtime"] → AIAgent(max_tokens=...).
Environment
- Hermes v0.9.0 (2026.4.13)
- Provider: custom:friday (AWS Bedrock proxy via
https://aigc.sankuai.com/v1/openai/native)
- Model:
aws.claude-sonnet-4.6
- OS: macOS (arm64)
Workaround
Manually patch gateway/run.py to bridge model.max_tokens from config into runtime_kwargs and turn_route["runtime"]. This survives until the next hermes update.
Bug Description
model.max_tokensset in~/.hermes/config.yamlhas no effect — it is never read or passed toAIAgentin either Gateway or CLI mode.Steps to Reproduce
model.max_tokensin config.yaml:Use Hermes via Gateway (API server / messaging platforms) or CLI (
hermes chat)The upstream API receives no
max_tokensparameter in the requestExpected Behavior
The configured
model.max_tokensshould be passed to theAIAgentconstructor and included in API requests asmax_tokens(ormax_completion_tokensfor direct OpenAI).Actual Behavior
gateway/run.py):_resolve_runtime_agent_kwargs()only extracts provider-related fields (api_key, base_url, provider, api_mode, etc.) —max_tokensis not included.cli.py):AIAgent(...)is constructed withoutmax_tokensat line ~2872. No code readsmodel.max_tokensfrom config.AIAgent.__init__defaults tomax_tokens=None(line 799 ofrun_agent.py)max_tokensisNone,_build_api_kwargs()skips adding it to the request (line ~6563)Impact
Most providers default to a reasonable output limit when
max_tokensis omitted. However, some providers (e.g., AWS Bedrock proxied through custom endpoints) default to very low values like 1024 tokens, causing:finish_reason: length)"Response truncated due to output length limit"Affected Code Paths
gateway/run.py:_resolve_runtime_agent_kwargs()(line ~319) — does not readmodel.max_tokensfrom configgateway/run.py:_resolve_turn_agent_config()(line ~967) —primarydict androute["runtime"]do not includemax_tokenscli.py(line ~2872) —AIAgent(...)constructor call missingmax_tokens=AIAgent(...)instantiation points ingateway/run.py(lines ~5690, ~5871, ~8572)Suggested Fix
Read
model.max_tokensfrom config and pass it through toAIAgent:And ensure
max_tokensflows throughresolve_turn_route()→route["runtime"]→AIAgent(max_tokens=...).Environment
https://aigc.sankuai.com/v1/openai/native)aws.claude-sonnet-4.6Workaround
Manually patch
gateway/run.pyto bridgemodel.max_tokensfrom config intoruntime_kwargsandturn_route["runtime"]. This survives until the nexthermes update.