Skip to content

fix(bedrock): raise default max_tokens from 4096 to 16384 - #20619

Open
liorfranko wants to merge 1 commit into
NousResearch:mainfrom
liorfranko:fix/bedrock-max-tokens-default
Open

fix(bedrock): raise default max_tokens from 4096 to 16384#20619
liorfranko wants to merge 1 commit into
NousResearch:mainfrom
liorfranko:fix/bedrock-max-tokens-default

Conversation

@liorfranko

Copy link
Copy Markdown

Problem

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.

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__ accepts max_tokens: int = None, and there is no config-level key to set it (#15037 is open but unimplemented). When self.max_tokens is None, the Bedrock path falls through to hardcoded 4096:

# run_agent.py:8462
max_tokens=self.max_tokens or 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.pyBedrockTransport.build_kwargs() default
  • agent/bedrock_adapter.pybuild_converse_kwargs(), call_converse(), call_converse_stream() function signatures

Impact

  • ✅ Fixes truncation for all Bedrock users without any config change
  • ✅ No behavioral change for users who explicitly set max_tokens
  • ✅ 16384 is well within Claude Opus/Sonnet 4.x limits (32768 max output)
  • ✅ Minimal diff — 6 lines changed across 3 files

Related

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)
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists provider/bedrock AWS Bedrock (boto3, IAM) comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint labels May 6, 2026

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_kwargs was extracted from run_agent.py in 4b25619bc; the live native Bedrock request path is now agent/chat_completion_helpers.py:692-705, and it still sends agent.max_tokens or 4096 at line 702. The PR edits the old location and is currently conflicting.
  • agent/auxiliary_client.py:1403-1412 independently calls Converse and explicitly falls back to 4096 at 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:702 and retain the explicit model.max_tokens override behavior resolved in agent/agent_init.py:1602-1628.
  • Cover the unset default in regression tests; tests/agent/transports/test_bedrock_transport.py:44-51 currently covers only an explicit cap.

Automated hermes-sweeper review.

Comment thread run_agent.py
@@ -8459,7 +8459,7 @@ def _build_api_kwargs(self, api_messages: list) -> dict:
model=self.model,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists provider/bedrock AWS Bedrock (boto3, IAM) sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants