fix(bedrock): raise default max_tokens from 4096 to 16384 - #20619
Open
liorfranko wants to merge 1 commit into
Open
fix(bedrock): raise default max_tokens from 4096 to 16384#20619liorfranko wants to merge 1 commit into
liorfranko wants to merge 1 commit into
Conversation
The Bedrock Converse API path hardcodes max_tokens=4096 when no explicit value is configured. This is far below Claude Opus 4.6's 32768 output limit, causing silent output truncation (finish_reason='length') on any response exceeding ~3K tokens of tool calls or long-form output. Claude Code uses the same Bedrock inference profiles without this issue because it sets a higher max_tokens. Hermes has no config-level override for max_tokens (see NousResearch#15037), so the hardcoded default is the only knob. Raise the default to 16384 (half of Opus 4.6's 32768 max) — a safe middle ground that eliminates truncation for typical agent workloads while leaving headroom for the model's own budget management. Files changed: - run_agent.py: fallback in _call_bedrock_converse() - agent/transports/bedrock.py: BedrockTransport.build_kwargs() default - agent/bedrock_adapter.py: build_converse_kwargs(), call_converse(), call_converse_stream() function signatures Closes: n/a (no existing issue for this specific bug) Related: NousResearch#15037 (per-model max_tokens config)
teknium1
reviewed
Jul 12, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for isolating the Bedrock output-cap issue. The unset-cap behavior is still present on current main, but this branch needs a small transplant before it can address it.
Problems
build_api_kwargswas extracted fromrun_agent.pyin4b25619bc; the live native Bedrock request path is nowagent/chat_completion_helpers.py:692-705, and it still sendsagent.max_tokens or 4096at line 702. The PR edits the old location and is currently conflicting.agent/auxiliary_client.py:1403-1412independently calls Converse and explicitly falls back to4096at line 1408. Changing only the adapter default leaves that sibling fallback unchanged.
Suggested changes
- Move the agent-loop edit to
agent/chat_completion_helpers.py:702and retain the explicitmodel.max_tokensoverride behavior resolved inagent/agent_init.py:1602-1628. - Cover the unset default in regression tests;
tests/agent/transports/test_bedrock_transport.py:44-51currently covers only an explicit cap.
Automated hermes-sweeper review.
| @@ -8459,7 +8459,7 @@ def _build_api_kwargs(self, api_messages: list) -> dict: | |||
| model=self.model, | |||
Contributor
There was a problem hiding this comment.
This request builder was extracted in 4b25619bc; current main executes agent/chat_completion_helpers.py:702 for native Bedrock requests. Please transplant this fallback change there, otherwise the live path will continue to pass 4096.
19 tasks
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.
Problem
The Bedrock Converse API path hardcodes
max_tokens=4096when no explicit value is configured. This is far below Claude Opus 4.6's 32768 output limit, causing silent output truncation (finish_reason='length') on any response exceeding ~3K tokens of tool calls or long-form output.This affects any Hermes user running Claude via AWS Bedrock inference profiles. Claude Code uses the same Bedrock profiles without this issue because it sets a higher max_tokens in its API calls.
Root Cause
AIAgent.__init__acceptsmax_tokens: int = None, and there is no config-level key to set it (#15037 is open but unimplemented). Whenself.max_tokensis None, the Bedrock path falls through to hardcoded 4096:Fix
Raise the hardcoded default from 4096 to 16384 (half of Opus 4.6's 32768 max) — a safe middle ground that eliminates truncation for typical agent workloads while leaving headroom for the model's own budget management.
Files changed:
run_agent.py— fallback in_call_bedrock_converse()agent/transports/bedrock.py—BedrockTransport.build_kwargs()defaultagent/bedrock_adapter.py—build_converse_kwargs(),call_converse(),call_converse_stream()function signaturesImpact
max_tokensRelated