@@ -87,7 +87,8 @@ def create_agent_card(
8787 provided.
8888 """
8989 # pylint: disable=g-import-not-at-top
90- from a2a .types import AgentCard , AgentCapabilities , TransportProtocol
90+ from a2a .types import AgentCard , AgentCapabilities , AgentInterface
91+ from a2a .utils .constants import TransportProtocol , PROTOCOL_VERSION_CURRENT
9192
9293 # Check if a dictionary was provided.
9394 if agent_card :
@@ -98,14 +99,18 @@ def create_agent_card(
9899 return AgentCard (
99100 name = agent_name ,
100101 description = description ,
101- url = "http://localhost:9999/" ,
102102 version = "1.0.0" ,
103103 default_input_modes = default_input_modes or ["text/plain" ],
104104 default_output_modes = default_output_modes or ["application/json" ],
105- capabilities = AgentCapabilities (streaming = streaming ),
105+ capabilities = AgentCapabilities (streaming = streaming , extended_agent_card = True ),
106106 skills = skills ,
107- preferred_transport = TransportProtocol .http_json , # Http Only.
108- supports_authenticated_extended_card = True ,
107+ supported_interfaces = [
108+ AgentInterface (
109+ url = "http://localhost:9999/" ,
110+ protocol_binding = TransportProtocol .HTTP_JSON ,
111+ protocol_version = PROTOCOL_VERSION_CURRENT ,
112+ )
113+ ],
109114 )
110115
111116 # Raise an error if insufficient data is provided.
@@ -181,14 +186,11 @@ def __init__(
181186 """Initializes the A2A agent."""
182187 # pylint: disable=g-import-not-at-top
183188 from google .cloud .aiplatform import initializer
184- from a2a .types import TransportProtocol
189+ from a2a .utils . constants import TransportProtocol
185190
186- if (
187- agent_card .preferred_transport
188- and agent_card .preferred_transport != TransportProtocol .http_json
189- ):
191+ if agent_card .supported_interfaces and agent_card .supported_interfaces [0 ].interface .protocol_binding != TransportProtocol .HTTP_JSON :
190192 raise ValueError (
191- "Only HTTP+JSON is supported for preferred transport on agent card "
193+ "Only HTTP+JSON is supported for the primary interface on agent card "
192194 )
193195
194196 self ._tmpl_attrs : dict [str , Any ] = {
@@ -244,7 +246,21 @@ def set_up(self):
244246 agent_engine_id = os .getenv ("GOOGLE_CLOUD_AGENT_ENGINE_ID" , "test-agent-engine" )
245247 version = "v1beta1"
246248
247- self .agent_card .url = f"https://{ location } -aiplatform.googleapis.com/{ version } /projects/{ project } /locations/{ location } /reasoningEngines/{ agent_engine_id } /a2a"
249+ new_url = f"https://{ location } -aiplatform.googleapis.com/{ version } /projects/{ project } /locations/{ location } /reasoningEngines/{ agent_engine_id } /a2a"
250+ if not self .agent_card .supported_interfaces :
251+ from a2a .types import AgentInterface
252+ from a2a .utils .constants import TransportProtocol , PROTOCOL_VERSION_CURRENT
253+
254+ self .agent_card .supported_interfaces .append (
255+ AgentInterface (
256+ url = new_url ,
257+ protocol_binding = TransportProtocol .HTTP_JSON ,
258+ protocol_version = PROTOCOL_VERSION_CURRENT ,
259+ )
260+ )
261+ else :
262+ # primary interface must be HTTP+JSON
263+ self .agent_card .supported_interfaces [0 ].url = new_url
248264 self ._tmpl_attrs ["agent_card" ] = self .agent_card
249265
250266 # Create the agent executor if a builder is provided.
@@ -339,8 +355,8 @@ def register_operations(self) -> Dict[str, List[str]]:
339355 }
340356 if self .agent_card .capabilities and self .agent_card .capabilities .streaming :
341357 routes ["a2a_extension" ].append ("on_message_send_stream" )
342- routes ["a2a_extension" ].append ("on_resubscribe_to_task " )
343- if self .agent_card .supports_authenticated_extended_card :
358+ routes ["a2a_extension" ].append ("on_subscribe_to_task " )
359+ if self .agent_card .capabilities and self . agent_card . capabilities . extended_agent_card :
344360 routes ["a2a_extension" ].append ("handle_authenticated_agent_card" )
345361 return routes
346362
@@ -353,11 +369,52 @@ async def on_message_send_stream(
353369 async for chunk in self .rest_handler .on_message_send_stream (request , context ):
354370 yield chunk
355371
356- async def on_resubscribe_to_task (
372+ async def on_subscribe_to_task (
357373 self ,
358374 request : "Request" ,
359375 context : "ServerCallContext" ,
360376 ) -> AsyncIterator [str ]:
361377 """Handles A2A task resubscription requests via SSE."""
362- async for chunk in self .rest_handler .on_resubscribe_to_task (request , context ):
378+ async for chunk in self .rest_handler .on_subscribe_to_task (request , context ):
363379 yield chunk
380+
381+ def __getstate__ (self ):
382+ """Serializes AgentCard proto to a dictionary."""
383+ from google .protobuf import json_format
384+ import json
385+
386+ state = self .__dict__ .copy ()
387+
388+ def _to_dict_if_proto (obj ):
389+ if hasattr (obj , "DESCRIPTOR" ):
390+ return {"__protobuf_AgentCard__" : json .loads (json_format .MessageToJson (obj ))}
391+ return obj
392+
393+ state ["agent_card" ] = _to_dict_if_proto (state .get ("agent_card" ))
394+ if "_tmpl_attrs" in state :
395+ tmpl_attrs = state ["_tmpl_attrs" ].copy ()
396+ tmpl_attrs ["agent_card" ] = _to_dict_if_proto (tmpl_attrs .get ("agent_card" ))
397+ tmpl_attrs ["extended_agent_card" ] = _to_dict_if_proto (tmpl_attrs .get ("extended_agent_card" ))
398+ state ["_tmpl_attrs" ] = tmpl_attrs
399+
400+ return state
401+
402+ def __setstate__ (self , state ):
403+ """Deserializes AgentCard proto from a dictionary."""
404+ from google .protobuf import json_format
405+ from a2a .types import AgentCard
406+
407+ def _from_dict_if_proto (obj ):
408+ if isinstance (obj , dict ) and "__protobuf_AgentCard__" in obj :
409+ agent_card = AgentCard ()
410+ json_format .ParseDict (obj ["__protobuf_AgentCard__" ], agent_card )
411+ return agent_card
412+ return obj
413+
414+ state ["agent_card" ] = _from_dict_if_proto (state .get ("agent_card" ))
415+ if "_tmpl_attrs" in state :
416+ state ["_tmpl_attrs" ]["agent_card" ] = _from_dict_if_proto (state ["_tmpl_attrs" ].get ("agent_card" ))
417+ state ["_tmpl_attrs" ]["extended_agent_card" ] = _from_dict_if_proto (state ["_tmpl_attrs" ].get ("extended_agent_card" ))
418+
419+ self .__dict__ .update (state )
420+
0 commit comments