diff --git a/src/strands/models/bedrock.py b/src/strands/models/bedrock.py index f18422191..8909072f6 100644 --- a/src/strands/models/bedrock.py +++ b/src/strands/models/bedrock.py @@ -45,6 +45,7 @@ T = TypeVar("T", bound=BaseModel) +DEFAULT_READ_TIMEOUT = 120 class BedrockModel(Model): """AWS Bedrock model provider implementation. @@ -147,7 +148,7 @@ def __init__( client_config = boto_client_config.merge(BotocoreConfig(user_agent_extra=new_user_agent)) else: - client_config = BotocoreConfig(user_agent_extra="strands-agents") + client_config = BotocoreConfig(user_agent_extra="strands-agents", read_timeout=DEFAULT_READ_TIMEOUT) resolved_region = region_name or session.region_name or os.environ.get("AWS_REGION") or DEFAULT_BEDROCK_REGION diff --git a/tests/strands/models/test_bedrock.py b/tests/strands/models/test_bedrock.py index 624eec6e9..5e4c20e79 100644 --- a/tests/strands/models/test_bedrock.py +++ b/tests/strands/models/test_bedrock.py @@ -11,7 +11,7 @@ import strands from strands.models import BedrockModel -from strands.models.bedrock import DEFAULT_BEDROCK_MODEL_ID, DEFAULT_BEDROCK_REGION +from strands.models.bedrock import DEFAULT_BEDROCK_MODEL_ID, DEFAULT_BEDROCK_REGION, DEFAULT_READ_TIMEOUT from strands.types.exceptions import ModelThrottledException from strands.types.tools import ToolSpec @@ -216,6 +216,20 @@ def test__init__default_user_agent(bedrock_client): assert kwargs["service_name"] == "bedrock-runtime" assert isinstance(kwargs["config"], BotocoreConfig) assert kwargs["config"].user_agent_extra == "strands-agents" + assert kwargs["config"].read_timeout == DEFAULT_READ_TIMEOUT + + +def test__init__default_read_timeout(bedrock_client): + """Set default read timeout when no boto_client_config is provided.""" + with unittest.mock.patch("strands.models.bedrock.boto3.Session") as mock_session_cls: + mock_session = mock_session_cls.return_value + _ = BedrockModel() + + # Verify the client was created with the correct read timeout + mock_session.client.assert_called_once() + args, kwargs = mock_session.client.call_args + assert isinstance(kwargs["config"], BotocoreConfig) + assert kwargs["config"].read_timeout == DEFAULT_READ_TIMEOUT def test__init__with_custom_boto_client_config_no_user_agent(bedrock_client):