1717import os
1818import re
1919from typing import (
20+ Callable ,
2021 Dict ,
2122 Mapping ,
2223 MutableMapping ,
@@ -681,7 +682,9 @@ def __init__(
681682 self ,
682683 * ,
683684 credentials : Optional [ga_credentials .Credentials ] = None ,
684- transport : Optional [Union [str , AgentsTransport ]] = None ,
685+ transport : Optional [
686+ Union [str , AgentsTransport , Callable [..., AgentsTransport ]]
687+ ] = None ,
685688 client_options : Optional [Union [client_options_lib .ClientOptions , dict ]] = None ,
686689 client_info : gapic_v1 .client_info .ClientInfo = DEFAULT_CLIENT_INFO ,
687690 ) -> None :
@@ -693,9 +696,11 @@ def __init__(
693696 credentials identify the application to the service; if none
694697 are specified, the client will attempt to ascertain the
695698 credentials from the environment.
696- transport (Union[str, AgentsTransport]): The
697- transport to use. If set to None, a transport is chosen
698- automatically.
699+ transport (Optional[Union[str,AgentsTransport,Callable[..., AgentsTransport]]]):
700+ The transport to use, or a Callable that constructs and returns a new transport.
701+ If a Callable is given, it will be called with the same set of initialization
702+ arguments as used in the AgentsTransport constructor.
703+ If set to None, a transport is chosen automatically.
699704 client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]):
700705 Custom options for the client.
701706
@@ -801,8 +806,15 @@ def __init__(
801806 api_key_value
802807 )
803808
804- Transport = type (self ).get_transport_class (cast (str , transport ))
805- self ._transport = Transport (
809+ transport_init : Union [
810+ Type [AgentsTransport ], Callable [..., AgentsTransport ]
811+ ] = (
812+ type (self ).get_transport_class (transport )
813+ if isinstance (transport , str ) or transport is None
814+ else cast (Callable [..., AgentsTransport ], transport )
815+ )
816+ # initialize with the provided callable or the passed in class
817+ self ._transport = transport_init (
806818 credentials = credentials ,
807819 credentials_file = self ._client_options .credentials_file ,
808820 host = self ._api_endpoint ,
@@ -880,19 +892,17 @@ def sample_list_agents():
880892
881893 """
882894 # Create or coerce a protobuf request object.
883- # Quick check: If we got a request object, we should *not* have
884- # gotten any keyword arguments that map to the request.
895+ # - Quick check: If we got a request object, we should *not* have
896+ # gotten any keyword arguments that map to the request.
885897 has_flattened_params = any ([parent ])
886898 if request is not None and has_flattened_params :
887899 raise ValueError (
888900 "If the `request` argument is set, then none of "
889901 "the individual field arguments should be set."
890902 )
891903
892- # Minor optimization to avoid making a copy if the user passes
893- # in a agent.ListAgentsRequest.
894- # There's no risk of modifying the input as we've already verified
895- # there are no flattened fields.
904+ # - Use the request object if provided (there's no risk of modifying the input as
905+ # there are no flattened fields), or create one.
896906 if not isinstance (request , agent .ListAgentsRequest ):
897907 request = agent .ListAgentsRequest (request )
898908 # If we have keyword arguments corresponding to fields on the
@@ -1007,19 +1017,17 @@ def sample_get_agent():
10071017
10081018 """
10091019 # Create or coerce a protobuf request object.
1010- # Quick check: If we got a request object, we should *not* have
1011- # gotten any keyword arguments that map to the request.
1020+ # - Quick check: If we got a request object, we should *not* have
1021+ # gotten any keyword arguments that map to the request.
10121022 has_flattened_params = any ([name ])
10131023 if request is not None and has_flattened_params :
10141024 raise ValueError (
10151025 "If the `request` argument is set, then none of "
10161026 "the individual field arguments should be set."
10171027 )
10181028
1019- # Minor optimization to avoid making a copy if the user passes
1020- # in a agent.GetAgentRequest.
1021- # There's no risk of modifying the input as we've already verified
1022- # there are no flattened fields.
1029+ # - Use the request object if provided (there's no risk of modifying the input as
1030+ # there are no flattened fields), or create one.
10231031 if not isinstance (request , agent .GetAgentRequest ):
10241032 request = agent .GetAgentRequest (request )
10251033 # If we have keyword arguments corresponding to fields on the
@@ -1141,19 +1149,17 @@ def sample_create_agent():
11411149
11421150 """
11431151 # Create or coerce a protobuf request object.
1144- # Quick check: If we got a request object, we should *not* have
1145- # gotten any keyword arguments that map to the request.
1152+ # - Quick check: If we got a request object, we should *not* have
1153+ # gotten any keyword arguments that map to the request.
11461154 has_flattened_params = any ([parent , agent ])
11471155 if request is not None and has_flattened_params :
11481156 raise ValueError (
11491157 "If the `request` argument is set, then none of "
11501158 "the individual field arguments should be set."
11511159 )
11521160
1153- # Minor optimization to avoid making a copy if the user passes
1154- # in a gcdc_agent.CreateAgentRequest.
1155- # There's no risk of modifying the input as we've already verified
1156- # there are no flattened fields.
1161+ # - Use the request object if provided (there's no risk of modifying the input as
1162+ # there are no flattened fields), or create one.
11571163 if not isinstance (request , gcdc_agent .CreateAgentRequest ):
11581164 request = gcdc_agent .CreateAgentRequest (request )
11591165 # If we have keyword arguments corresponding to fields on the
@@ -1277,19 +1283,17 @@ def sample_update_agent():
12771283
12781284 """
12791285 # Create or coerce a protobuf request object.
1280- # Quick check: If we got a request object, we should *not* have
1281- # gotten any keyword arguments that map to the request.
1286+ # - Quick check: If we got a request object, we should *not* have
1287+ # gotten any keyword arguments that map to the request.
12821288 has_flattened_params = any ([agent , update_mask ])
12831289 if request is not None and has_flattened_params :
12841290 raise ValueError (
12851291 "If the `request` argument is set, then none of "
12861292 "the individual field arguments should be set."
12871293 )
12881294
1289- # Minor optimization to avoid making a copy if the user passes
1290- # in a gcdc_agent.UpdateAgentRequest.
1291- # There's no risk of modifying the input as we've already verified
1292- # there are no flattened fields.
1295+ # - Use the request object if provided (there's no risk of modifying the input as
1296+ # there are no flattened fields), or create one.
12931297 if not isinstance (request , gcdc_agent .UpdateAgentRequest ):
12941298 request = gcdc_agent .UpdateAgentRequest (request )
12951299 # If we have keyword arguments corresponding to fields on the
@@ -1377,19 +1381,17 @@ def sample_delete_agent():
13771381 sent along with the request as metadata.
13781382 """
13791383 # Create or coerce a protobuf request object.
1380- # Quick check: If we got a request object, we should *not* have
1381- # gotten any keyword arguments that map to the request.
1384+ # - Quick check: If we got a request object, we should *not* have
1385+ # gotten any keyword arguments that map to the request.
13821386 has_flattened_params = any ([name ])
13831387 if request is not None and has_flattened_params :
13841388 raise ValueError (
13851389 "If the `request` argument is set, then none of "
13861390 "the individual field arguments should be set."
13871391 )
13881392
1389- # Minor optimization to avoid making a copy if the user passes
1390- # in a agent.DeleteAgentRequest.
1391- # There's no risk of modifying the input as we've already verified
1392- # there are no flattened fields.
1393+ # - Use the request object if provided (there's no risk of modifying the input as
1394+ # there are no flattened fields), or create one.
13931395 if not isinstance (request , agent .DeleteAgentRequest ):
13941396 request = agent .DeleteAgentRequest (request )
13951397 # If we have keyword arguments corresponding to fields on the
@@ -1487,10 +1489,8 @@ def sample_export_agent():
14871489
14881490 """
14891491 # Create or coerce a protobuf request object.
1490- # Minor optimization to avoid making a copy if the user passes
1491- # in a agent.ExportAgentRequest.
1492- # There's no risk of modifying the input as we've already verified
1493- # there are no flattened fields.
1492+ # - Use the request object if provided (there's no risk of modifying the input as
1493+ # there are no flattened fields), or create one.
14941494 if not isinstance (request , agent .ExportAgentRequest ):
14951495 request = agent .ExportAgentRequest (request )
14961496
@@ -1612,10 +1612,8 @@ def sample_restore_agent():
16121612
16131613 """
16141614 # Create or coerce a protobuf request object.
1615- # Minor optimization to avoid making a copy if the user passes
1616- # in a agent.RestoreAgentRequest.
1617- # There's no risk of modifying the input as we've already verified
1618- # there are no flattened fields.
1615+ # - Use the request object if provided (there's no risk of modifying the input as
1616+ # there are no flattened fields), or create one.
16191617 if not isinstance (request , agent .RestoreAgentRequest ):
16201618 request = agent .RestoreAgentRequest (request )
16211619
@@ -1707,10 +1705,8 @@ def sample_validate_agent():
17071705
17081706 """
17091707 # Create or coerce a protobuf request object.
1710- # Minor optimization to avoid making a copy if the user passes
1711- # in a agent.ValidateAgentRequest.
1712- # There's no risk of modifying the input as we've already verified
1713- # there are no flattened fields.
1708+ # - Use the request object if provided (there's no risk of modifying the input as
1709+ # there are no flattened fields), or create one.
17141710 if not isinstance (request , agent .ValidateAgentRequest ):
17151711 request = agent .ValidateAgentRequest (request )
17161712
@@ -1800,19 +1796,17 @@ def sample_get_agent_validation_result():
18001796
18011797 """
18021798 # Create or coerce a protobuf request object.
1803- # Quick check: If we got a request object, we should *not* have
1804- # gotten any keyword arguments that map to the request.
1799+ # - Quick check: If we got a request object, we should *not* have
1800+ # gotten any keyword arguments that map to the request.
18051801 has_flattened_params = any ([name ])
18061802 if request is not None and has_flattened_params :
18071803 raise ValueError (
18081804 "If the `request` argument is set, then none of "
18091805 "the individual field arguments should be set."
18101806 )
18111807
1812- # Minor optimization to avoid making a copy if the user passes
1813- # in a agent.GetAgentValidationResultRequest.
1814- # There's no risk of modifying the input as we've already verified
1815- # there are no flattened fields.
1808+ # - Use the request object if provided (there's no risk of modifying the input as
1809+ # there are no flattened fields), or create one.
18161810 if not isinstance (request , agent .GetAgentValidationResultRequest ):
18171811 request = agent .GetAgentValidationResultRequest (request )
18181812 # If we have keyword arguments corresponding to fields on the
@@ -1915,19 +1909,17 @@ def sample_get_generative_settings():
19151909 Settings for Generative AI.
19161910 """
19171911 # Create or coerce a protobuf request object.
1918- # Quick check: If we got a request object, we should *not* have
1919- # gotten any keyword arguments that map to the request.
1912+ # - Quick check: If we got a request object, we should *not* have
1913+ # gotten any keyword arguments that map to the request.
19201914 has_flattened_params = any ([name , language_code ])
19211915 if request is not None and has_flattened_params :
19221916 raise ValueError (
19231917 "If the `request` argument is set, then none of "
19241918 "the individual field arguments should be set."
19251919 )
19261920
1927- # Minor optimization to avoid making a copy if the user passes
1928- # in a agent.GetGenerativeSettingsRequest.
1929- # There's no risk of modifying the input as we've already verified
1930- # there are no flattened fields.
1921+ # - Use the request object if provided (there's no risk of modifying the input as
1922+ # there are no flattened fields), or create one.
19311923 if not isinstance (request , agent .GetGenerativeSettingsRequest ):
19321924 request = agent .GetGenerativeSettingsRequest (request )
19331925 # If we have keyword arguments corresponding to fields on the
@@ -2031,19 +2023,17 @@ def sample_update_generative_settings():
20312023 Settings for Generative AI.
20322024 """
20332025 # Create or coerce a protobuf request object.
2034- # Quick check: If we got a request object, we should *not* have
2035- # gotten any keyword arguments that map to the request.
2026+ # - Quick check: If we got a request object, we should *not* have
2027+ # gotten any keyword arguments that map to the request.
20362028 has_flattened_params = any ([generative_settings , update_mask ])
20372029 if request is not None and has_flattened_params :
20382030 raise ValueError (
20392031 "If the `request` argument is set, then none of "
20402032 "the individual field arguments should be set."
20412033 )
20422034
2043- # Minor optimization to avoid making a copy if the user passes
2044- # in a agent.UpdateGenerativeSettingsRequest.
2045- # There's no risk of modifying the input as we've already verified
2046- # there are no flattened fields.
2035+ # - Use the request object if provided (there's no risk of modifying the input as
2036+ # there are no flattened fields), or create one.
20472037 if not isinstance (request , agent .UpdateGenerativeSettingsRequest ):
20482038 request = agent .UpdateGenerativeSettingsRequest (request )
20492039 # If we have keyword arguments corresponding to fields on the
0 commit comments