Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions agent/bedrock_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1296,9 +1296,20 @@ def classify_bedrock_error(error_message: str) -> str:
# detection is unavailable.

BEDROCK_CONTEXT_LENGTHS: Dict[str, int] = {
# Anthropic Claude models on Bedrock
"anthropic.claude-opus-4-6": 200_000,
"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

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.

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.

# agent/model_metadata.py, which already maps these to 1M). Keys are
# matched by longest-substring, so the versioned 4-6/4-7/4-8 entries win
# over the generic "anthropic.claude-opus-4" / "...-sonnet-4" fallbacks.
"anthropic.claude-opus-4-8": 1_000_000,
"anthropic.claude-opus-4-7": 1_000_000,
"anthropic.claude-opus-4-6": 1_000_000,
"anthropic.claude-sonnet-4-8": 1_000_000,
"anthropic.claude-sonnet-4-7": 1_000_000,
"anthropic.claude-sonnet-4-6": 1_000_000,
# Claude 4.5 and older Claude 4 / 3.x remain at the 200K Bedrock window.
# Haiku 4.5 specifically is 200K (no 1M window).
"anthropic.claude-sonnet-4-5": 200_000,
"anthropic.claude-haiku-4-5": 200_000,
"anthropic.claude-opus-4": 200_000,
Expand Down
19 changes: 17 additions & 2 deletions tests/agent/test_bedrock_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1165,13 +1165,28 @@ def test_unknown_error(self):
class TestBedrockContextLength:
"""Test Bedrock model context length lookup."""

def test_claude_opus_4_8(self):
from agent.bedrock_adapter import get_bedrock_context_length
# opus 4.8 exposes the 1M window on Bedrock (matches native Anthropic).
assert get_bedrock_context_length("anthropic.claude-opus-4-8-20250514-v1:0") == 1_000_000

def test_claude_opus_4_6(self):
from agent.bedrock_adapter import get_bedrock_context_length
assert get_bedrock_context_length("anthropic.claude-opus-4-6-20250514-v1:0") == 200_000
assert get_bedrock_context_length("anthropic.claude-opus-4-6-20250514-v1:0") == 1_000_000

def test_claude_sonnet_versioned(self):
from agent.bedrock_adapter import get_bedrock_context_length
assert get_bedrock_context_length("anthropic.claude-sonnet-4-6-20250514-v1:0") == 200_000
assert get_bedrock_context_length("anthropic.claude-sonnet-4-6-20250514-v1:0") == 1_000_000

def test_claude_haiku_4_5_stays_200k(self):
from agent.bedrock_adapter import get_bedrock_context_length
# Haiku 4.5 has no 1M window — must stay at the 200K Bedrock limit and
# not get swept up by the opus/sonnet 4.x bump.
assert get_bedrock_context_length("anthropic.claude-haiku-4-5-20250514-v1:0") == 200_000

def test_claude_sonnet_4_5_stays_200k(self):
from agent.bedrock_adapter import get_bedrock_context_length
assert get_bedrock_context_length("anthropic.claude-sonnet-4-5-20250514-v1:0") == 200_000

def test_nova_pro(self):
from agent.bedrock_adapter import get_bedrock_context_length
Expand Down