feat(bedrock): add support for Anthropic Claude V4 models#4701
Open
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Open
feat(bedrock): add support for Anthropic Claude V4 models#4701devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Conversation
- Add _strip_region_prefix() to handle us./eu./apac./global. prefixes - Update get_context_window_size() with V4 model entries (200K tokens) - Update supports_multimodal() to detect V4 models - Update _is_nova_model() to use region prefix stripping - Add V4 model context windows to LLM_CONTEXT_WINDOW_SIZES in llm.py - Add 11 comprehensive tests covering V4 model detection, context windows, multimodal support, region prefixes, function calling, and regression Closes #4700 Co-Authored-By: João <joao@crewai.com>
Contributor
Author
|
Prompt hidden (unlisted session) |
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
feat(bedrock): add support for Anthropic Claude V4 models
Summary
Adds support for AWS Bedrock's Anthropic Claude V4 model family (Claude Sonnet 4, Opus 4, Opus 4.1, Haiku 4.5, Sonnet 4.5, Opus 4.5). These models use the same Converse API as V3, so the changes are primarily capability detection and configuration — no new API implementation was needed.
Key changes:
_strip_region_prefix()static method onBedrockCompletion— stripsus./eu./apac./global.region qualifiers from model IDs so capability lookups work uniformly regardless of cross-region inference prefix.get_context_window_size()— added V4 model prefix entries (all 200K tokens), now uses_strip_region_prefixfor matching.supports_multimodal()— refactored to use_strip_region_prefixinstead of hardcoding region-prefixed model names. Added V4 model prefixes._is_nova_model()— also updated to use_strip_region_prefixfor consistency (minor behavioral change: substring match → prefix match after stripping).LLM_CONTEXT_WINDOW_SIZESinllm.py— added V4 model IDs withus.,eu.,apac., and bare prefixes.Closes #4700
Review & Testing Checklist for Human
get_context_window_size():"anthropic.claude-opus-4"will matchopus-4-1andopus-4-5viastartswith. This is currently fine since all have 200K context, but the pattern is fragile if future models diverge. Verify this is acceptable.LLM_CONTEXT_WINDOW_SIZES: Theeu.andapac.sections have fewer V4 entries thanus.— confirm this matches actual AWS regional availability rather than being an omission.supports_multimodal()refactor: Previously hardcodedus.amazon.nova-*for Nova vision support; now uses_strip_region_prefixwhich meanseu./apac./global.Nova models are also covered. Verify this is a desired side-effect fix.LLM(model="bedrock/anthropic.claude-sonnet-4-20250514-v1:0")and calling it against real Bedrock to confirm the model IDs are correct.Test plan
uv run pytest tests/llms/bedrock/test_bedrock.py -vv(39 passed ✅)uv run ruff check lib/crewai/src/crewai/llm.py lib/crewai/src/crewai/llms/providers/bedrock/completion.py lib/crewai/tests/llms/bedrock/test_bedrock.py(all checks passed ✅)Notes
BEDROCK_MODELSconstants but were not functional due to missing capability detection.Note
Medium Risk
Updates Bedrock model capability detection (context window, multimodal, Nova identification) and introduces region-prefix normalization, which could subtly change behavior for existing region-prefixed model IDs if matching assumptions were relied on.
Overview
Adds recognition of Anthropic Claude 4.x Bedrock model IDs (including
us./eu./apac./global.-prefixed variants) and maps them to a 200K context window inLLM_CONTEXT_WINDOW_SIZES.In
BedrockCompletion, introduces_strip_region_prefix()and uses it to makeget_context_window_size(),supports_multimodal(), and_is_nova_model()work consistently across region-prefixed model IDs; multimodal detection is expanded to include Claude 4.x and simplified to base-model prefixes.Extends
test_bedrock.pywith a focused suite covering Claude 4.x routing, context window sizing, multimodal support, region-prefix handling, inference config, mocked calls, Nova detection with prefixes, and a Claude 3.x regression check.Written by Cursor Bugbot for commit d0da114. This will update automatically on new commits. Configure here.