Commit ac804f9
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
- tests_integ
- tests/strands/models
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
31 | 36 | | |
32 | 37 | | |
33 | 38 | | |
| |||
0 commit comments