fix(bedrock): map Claude opus/sonnet 4.6+ to 1M context window - #54918
fix(bedrock): map Claude opus/sonnet 4.6+ to 1M context window#54918iizotov wants to merge 1 commit into
Conversation
The Bedrock static context table only had entries up to the 4-6 generation and capped all Claude models at 200K. Newer model IDs (opus/sonnet 4-7, 4-8) silently inherited 200K via the generic "anthropic.claude-opus-4" / "...-sonnet-4" substring fallback, contradicting the native Anthropic table in model_metadata.py which already maps these to 1M. Map opus/sonnet 4-6/4-7/4-8 to 1_000_000 on Bedrock. Haiku 4.5, sonnet 4.5, legacy Claude 4 and 3.x stay at 200K (no 1M window). Add opus-4-8 coverage and haiku/sonnet-4-5 200K guards.
Duplicate of #24059 (earliest open PR aligning the Bedrock Claude context-window table to 1M for the 4.x generations). The core change here -- bumping the opus/sonnet 4.6/4.7/4.8 entries in |
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: LGTM
Clean, well-scoped change with no concerns.
--- Reviewed by Hermes Agent
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the focused Bedrock metadata update. The underlying 200K fallback is still present on current main, but one existing test must be updated with the table change.
Problems
tests/agent/test_bedrock_adapter.py:1191still expectsus.anthropic.claude-sonnet-4-6to resolve to 200K. The proposedanthropic.claude-sonnet-4-6: 1_000_000entry wins under the longest-substring resolver inagent/bedrock_adapter.py:1335-1342, so this unchanged test will fail.- The new comment says
agent/model_metadata.pymaps the 4.6+ Opus/Sonnet generations to 1M, but currentDEFAULT_CONTEXT_LENGTHSonly lists Opus 4.6/4.7/4.8 and Sonnet 4.6 atagent/model_metadata.py:216-223.
Suggested changes
- Change the inference-profile expectation at
tests/agent/test_bedrock_adapter.py:1191to1_000_000. - Scope the explanatory comment to the native mappings actually present, or support the additional Sonnet mappings with an independent Bedrock citation.
Automated hermes-sweeper review.
| "anthropic.claude-sonnet-4-6": 200_000, | ||
| # Anthropic Claude models on Bedrock. | ||
| # The opus/sonnet 4.6+ generations expose a 1M context window on Bedrock, | ||
| # matching the native Anthropic API (see DEFAULT_CONTEXT_LENGTHS in |
There was a problem hiding this comment.
DEFAULT_CONTEXT_LENGTHS currently contains 1M entries for Opus 4.6/4.7/4.8 and Sonnet 4.6, but not Sonnet 4.7/4.8 (agent/model_metadata.py:216-223). Please narrow this “matching the native Anthropic API” claim or cite Bedrock independently for those additional mappings.
|
Merged via PR #67977 — your commit (Opus 4.8 row + the longest-substring guard tests) was cherry-picked onto current main with your authorship preserved (rebase merge), on top of #24059's earlier table flip. Thanks for catching that the generic |
Summary
The Bedrock static context-length table (
BEDROCK_CONTEXT_LENGTHSinagent/bedrock_adapter.py) only had entries up to the Claude 4.6 generation and capped every Claude model at 200K. Newer model IDs (opus-4-7,opus-4-8,sonnet-4-7,sonnet-4-8) silently inherited 200K via the genericanthropic.claude-opus-4/...-sonnet-4substring fallback.This contradicted the native Anthropic table in
agent/model_metadata.py(DEFAULT_CONTEXT_LENGTHS), which already mapsclaude-opus-4-8/4-7/4-6andclaude-sonnet-4-6to 1,000,000. The same model resolved to 1M on the native path but 200K on the Bedrock path.Symptom
A Bedrock user running
global.anthropic.claude-opus-4-8got a 200K context window instead of 1M, forcing a manualmodel.context_length: 1000000override inconfig.yaml.Fix
Add explicit 1M entries for the opus/sonnet 4.6 / 4.7 / 4.8 generations. Longest-substring matching ensures the versioned entries win over the generic
anthropic.claude-opus-4/...-sonnet-4200K fallbacks.Models that genuinely have no 1M window are explicitly held at 200K so the 4.x bump doesn't sweep them up:
Values verified against the authoritative Anthropic model list (1M window for Fable/Mythos 5, opus 4.6–4.8, sonnet 4.6; 200K for everything 4.5 and older, including Haiku 4.5).
Tests
tests/agent/test_bedrock_adapter.py::TestBedrockContextLength:test_claude_opus_4_8→ 1M (new)test_claude_opus_4_6/test_claude_sonnet_versioned→ updated 200K → 1Mtest_claude_haiku_4_5_stays_200k→ 200K guard (new)test_claude_sonnet_4_5_stays_200k→ 200K guard (new)Impact
Bedrock users on Claude opus/sonnet 4.6+ get the correct 1M window without a manual config override. No change for Haiku 4.5, Claude 4.5/4/3.x, Nova, Llama, Mistral, or DeepSeek.