Skip to content

Commit ac804f9

Browse files
committed
feat(bedrock): add BedrockModelInvoke for InvokeModel-only models
Adds a new ``BedrockModelInvoke`` provider that talks to Bedrock's native ``InvokeModel``/``InvokeModelWithResponseStream`` APIs instead of ``Converse``/``ConverseStream``. This makes Strands usable with models that do not support Converse, most notably Bedrock Custom Model Import (Llama, Mistral, Qwen, ...) and Anthropic models accessed via the Messages API. Supports both Anthropic Messages and OpenAI Chat Completions request/response formats; the wire format is auto-detected from the model id and can be overridden via the ``model_family`` config key. Streaming is fully wired through the Bedrock Converse-shaped event contract: ``messageStart``, ``contentBlockStart``/``contentBlockDelta``/``contentBlockStop`` for both text and tool-use blocks, ``messageStop`` with the mapped stop reason, and a ``metadata`` event carrying token usage. Non-streaming responses go through the same translation. Tool use, structured output, image inputs (Anthropic family), tool results, ``ToolChoice``, and the standard Bedrock error paths (throttling, context-window overflow, access-denied) are covered. The provider is exposed via lazy ``__getattr__`` import to keep package import time unchanged. Tests: 24 unit tests covering init, family detection, request formatting for both families, Anthropic and OpenAI streaming paths (text and tool use), non-streaming path, error mapping, and structured output. The integration test suite is converted from ``@pytest.mark.skip`` to runnable tests; the imported-model test is gated on the ``STRANDS_BEDROCK_INVOKE_IMPORTED_MODEL_ARN`` environment variable since ARNs are account-specific.
1 parent 305a005 commit ac804f9

4 files changed

Lines changed: 989 additions & 0 deletions

File tree

src/strands/models/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"model",
1515
"BaseModelConfig",
1616
"BedrockModel",
17+
"BedrockModelInvoke",
1718
"CacheConfig",
1819
"Model",
1920
]
@@ -28,6 +29,10 @@ def __getattr__(name: str) -> Any:
2829
from .anthropic import AnthropicModel
2930

3031
return AnthropicModel
32+
if name == "BedrockModelInvoke":
33+
from .bedrock_invoke import BedrockModelInvoke
34+
35+
return BedrockModelInvoke
3136
if name == "GeminiModel":
3237
from .gemini import GeminiModel
3338

0 commit comments

Comments
 (0)