Skip to content

Commit 94fc8dd

Browse files
BV-VenkyBV-Venky
andauthored
feat: add service_tier support to BedrockModel (#1799)
Co-authored-by: BV-Venky <venkateshcjjc@@gmail.com>
1 parent 635edbc commit 94fc8dd

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

src/strands/models/bedrock.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ class BedrockConfig(TypedDict, total=False):
9393
model_id: The Bedrock model ID (e.g., "us.anthropic.claude-sonnet-4-20250514-v1:0")
9494
include_tool_result_status: Flag to include status field in tool results.
9595
True includes status, False removes status, "auto" determines based on model_id. Defaults to "auto".
96+
service_tier: Service tier for the request, controlling the trade-off between latency and cost.
97+
Valid values: "default" (standard), "priority" (faster, premium), "flex" (cheaper, slower).
98+
Please check https://docs.aws.amazon.com/bedrock/latest/userguide/service-tiers-inference.html for
99+
supported service tiers, models, and regions
96100
stop_sequences: List of sequences that will stop generation when encountered
97101
streaming: Flag to enable/disable streaming. Defaults to True.
98102
temperature: Controls randomness in generation (higher = more random)
@@ -117,6 +121,7 @@ class BedrockConfig(TypedDict, total=False):
117121
max_tokens: int | None
118122
model_id: str
119123
include_tool_result_status: Literal["auto"] | bool | None
124+
service_tier: str | None
120125
stop_sequences: list[str] | None
121126
streaming: bool | None
122127
temperature: float | None
@@ -245,6 +250,7 @@ def _format_request(
245250
"modelId": self.config["model_id"],
246251
"messages": self._format_bedrock_messages(messages),
247252
"system": system_blocks,
253+
**({"serviceTier": {"type": self.config["service_tier"]}} if self.config.get("service_tier") else {}),
248254
**(
249255
{
250256
"toolConfig": {

tests/strands/models/test_bedrock.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,20 @@ def test_format_request_guardrail_config_without_trace_or_stream_processing_mode
379379
assert tru_request == exp_request
380380

381381

382+
def test_format_request_with_service_tier(model, messages, model_id):
383+
model.update_config(service_tier="flex")
384+
tru_request = model._format_request(messages)
385+
exp_request = {
386+
"inferenceConfig": {},
387+
"modelId": model_id,
388+
"messages": messages,
389+
"serviceTier": {"type": "flex"},
390+
"system": [],
391+
}
392+
393+
assert tru_request == exp_request
394+
395+
382396
def test_format_request_inference_config(model, messages, model_id, inference_config):
383397
model.update_config(**inference_config)
384398
tru_request = model._format_request(messages)

tests_integ/models/test_model_bedrock.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,27 @@ def test_non_streaming_agent(non_streaming_agent):
7373
assert len(str(result)) > 0
7474

7575

76+
def test_bedrock_service_tier_flex_invocation_succeeds():
77+
"""Bedrock accepts serviceTier when model and region support Priority/Flex tiers.
78+
79+
Tier support is model- and region-specific. See:
80+
https://docs.aws.amazon.com/bedrock/latest/userguide/service-tiers-inference.html
81+
82+
CI runs integ tests with AWS_REGION=us-east-1; amazon.nova-pro-v1:0 is listed for
83+
that region under Priority and Flex tiers.
84+
"""
85+
model = BedrockModel(
86+
model_id="amazon.nova-pro-v1:0",
87+
region_name="us-east-1",
88+
service_tier="flex",
89+
)
90+
agent = Agent(model=model, load_tools_from_directory=False)
91+
result = agent("Reply with exactly the word: ok")
92+
93+
assert result.stop_reason == "end_turn"
94+
assert len(str(result).strip()) > 0
95+
96+
7697
@pytest.mark.asyncio
7798
async def test_streaming_model_events(streaming_model, alist):
7899
"""Test streaming model events."""

0 commit comments

Comments
 (0)