Skip to content

Commit e44a302

Browse files
afarntrogUnshure
authored andcommitted
feat: add default read timeout to Bedrock model (strands-agents#829)
- Set DEFAULT_READ_TIMEOUT constant to 120 seconds - Configure BotocoreConfig with read_timeout when no custom config provided - Add test coverage for default read timeout behavior
1 parent 5268e88 commit e44a302

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/strands/models/bedrock.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
T = TypeVar("T", bound=BaseModel)
4747

48+
DEFAULT_READ_TIMEOUT = 120
4849

4950
class BedrockModel(Model):
5051
"""AWS Bedrock model provider implementation.
@@ -147,7 +148,7 @@ def __init__(
147148

148149
client_config = boto_client_config.merge(BotocoreConfig(user_agent_extra=new_user_agent))
149150
else:
150-
client_config = BotocoreConfig(user_agent_extra="strands-agents")
151+
client_config = BotocoreConfig(user_agent_extra="strands-agents", read_timeout=DEFAULT_READ_TIMEOUT)
151152

152153
resolved_region = region_name or session.region_name or os.environ.get("AWS_REGION") or DEFAULT_BEDROCK_REGION
153154

tests/strands/models/test_bedrock.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import strands
1313
from strands.models import BedrockModel
14-
from strands.models.bedrock import DEFAULT_BEDROCK_MODEL_ID, DEFAULT_BEDROCK_REGION
14+
from strands.models.bedrock import DEFAULT_BEDROCK_MODEL_ID, DEFAULT_BEDROCK_REGION, DEFAULT_READ_TIMEOUT
1515
from strands.types.exceptions import ModelThrottledException
1616
from strands.types.tools import ToolSpec
1717

@@ -216,6 +216,20 @@ def test__init__default_user_agent(bedrock_client):
216216
assert kwargs["service_name"] == "bedrock-runtime"
217217
assert isinstance(kwargs["config"], BotocoreConfig)
218218
assert kwargs["config"].user_agent_extra == "strands-agents"
219+
assert kwargs["config"].read_timeout == DEFAULT_READ_TIMEOUT
220+
221+
222+
def test__init__default_read_timeout(bedrock_client):
223+
"""Set default read timeout when no boto_client_config is provided."""
224+
with unittest.mock.patch("strands.models.bedrock.boto3.Session") as mock_session_cls:
225+
mock_session = mock_session_cls.return_value
226+
_ = BedrockModel()
227+
228+
# Verify the client was created with the correct read timeout
229+
mock_session.client.assert_called_once()
230+
args, kwargs = mock_session.client.call_args
231+
assert isinstance(kwargs["config"], BotocoreConfig)
232+
assert kwargs["config"].read_timeout == DEFAULT_READ_TIMEOUT
219233

220234

221235
def test__init__with_custom_boto_client_config_no_user_agent(bedrock_client):

0 commit comments

Comments
 (0)