1919 AgentCard ,
2020 AgentInterface ,
2121)
22-
23-
24- TRANSPORT_PROTOCOLS_JSONRPC = 'JSONRPC'
25- TRANSPORT_PROTOCOLS_GRPC = 'GRPC'
26- TRANSPORT_PROTOCOLS_HTTP_JSON = 'HTTP+JSON'
22+ from a2a . utils . constants import (
23+ TRANSPORT_GRPC ,
24+ TRANSPORT_HTTP_JSON ,
25+ TRANSPORT_JSONRPC ,
26+ )
2727
2828
2929try :
@@ -74,9 +74,9 @@ def __init__(
7474
7575 def _register_defaults (self , supported : list [str ]) -> None :
7676 # Empty support list implies JSON-RPC only.
77- if TRANSPORT_PROTOCOLS_JSONRPC in supported or not supported :
77+ if TRANSPORT_JSONRPC in supported or not supported :
7878 self .register (
79- TRANSPORT_PROTOCOLS_JSONRPC ,
79+ TRANSPORT_JSONRPC ,
8080 lambda card , url , config , interceptors : JsonRpcTransport (
8181 config .httpx_client or httpx .AsyncClient (),
8282 card ,
@@ -85,9 +85,9 @@ def _register_defaults(self, supported: list[str]) -> None:
8585 config .extensions or None ,
8686 ),
8787 )
88- if TRANSPORT_PROTOCOLS_HTTP_JSON in supported :
88+ if TRANSPORT_HTTP_JSON in supported :
8989 self .register (
90- TRANSPORT_PROTOCOLS_HTTP_JSON ,
90+ TRANSPORT_HTTP_JSON ,
9191 lambda card , url , config , interceptors : RestTransport (
9292 config .httpx_client or httpx .AsyncClient (),
9393 card ,
@@ -96,14 +96,14 @@ def _register_defaults(self, supported: list[str]) -> None:
9696 config .extensions or None ,
9797 ),
9898 )
99- if TRANSPORT_PROTOCOLS_GRPC in supported :
99+ if TRANSPORT_GRPC in supported :
100100 if GrpcTransport is None :
101101 raise ImportError (
102102 'To use GrpcClient, its dependencies must be installed. '
103103 'You can install them with \' pip install "a2a-sdk[grpc]"\' '
104104 )
105105 self .register (
106- TRANSPORT_PROTOCOLS_GRPC ,
106+ TRANSPORT_GRPC ,
107107 GrpcTransport .create ,
108108 )
109109
@@ -206,25 +206,30 @@ def create(
206206 If there is no valid matching of the client configuration with the
207207 server configuration, a `ValueError` is raised.
208208 """
209- server_set = {
210- x .protocol_binding : x .url for x in card .supported_interfaces
211- }
212209 client_set = self ._config .supported_protocol_bindings or [
213- TRANSPORT_PROTOCOLS_JSONRPC
210+ TRANSPORT_JSONRPC
214211 ]
215212 transport_protocol = None
216213 transport_url = None
217214 if self ._config .use_client_preference :
218- for x in client_set :
219- if x in server_set :
220- transport_protocol = x
221- transport_url = server_set [x ]
215+ for protocol_binding in client_set :
216+ supported_interface = next (
217+ (
218+ si
219+ for si in card .supported_interfaces
220+ if si .protocol_binding == protocol_binding
221+ ),
222+ None ,
223+ )
224+ if supported_interface :
225+ transport_protocol = protocol_binding
226+ transport_url = supported_interface .url
222227 break
223228 else :
224- for x , url in server_set . items () :
225- if x in client_set :
226- transport_protocol = x
227- transport_url = url
229+ for supported_interface in card . supported_interfaces :
230+ if supported_interface . protocol_binding in client_set :
231+ transport_protocol = supported_interface . protocol_binding
232+ transport_url = supported_interface . url
228233 break
229234 if not transport_protocol or not transport_url :
230235 raise ValueError ('no compatible transports found.' )
0 commit comments