77 import grpc
88except ImportError as e :
99 raise ImportError (
10- " A2AGrpcClient requires grpcio and grpcio-tools to be installed. "
11- " Install with: "
10+ ' A2AGrpcClient requires grpcio and grpcio-tools to be installed. '
11+ ' Install with: '
1212 "'pip install a2a-sdk[grpc]'"
1313 ) from e
1414
@@ -47,7 +47,9 @@ def __init__(
4747 self .agent_card = agent_card
4848 self .stub = grpc_stub
4949 self ._needs_extended_card = (
50- agent_card .supports_authenticated_extended_card if agent_card else True
50+ agent_card .supports_authenticated_extended_card
51+ if agent_card
52+ else True
5153 )
5254
5355 async def send_message (
@@ -101,7 +103,7 @@ async def resubscribe(
101103 ]:
102104 """Reconnects to get task updates."""
103105 stream = self .stub .TaskSubscription (
104- a2a_pb2 .TaskSubscriptionRequest (name = f" tasks/{ request .id } " )
106+ a2a_pb2 .TaskSubscriptionRequest (name = f' tasks/{ request .id } ' )
105107 )
106108 while True :
107109 response = await stream .read ()
@@ -117,7 +119,7 @@ async def get_task(
117119 ) -> Task :
118120 """Retrieves the current state and history of a specific task."""
119121 task = await self .stub .GetTask (
120- a2a_pb2 .GetTaskRequest (name = f" tasks/{ request .id } " )
122+ a2a_pb2 .GetTaskRequest (name = f' tasks/{ request .id } ' )
121123 )
122124 return proto_utils .FromProto .task (task )
123125
@@ -129,7 +131,7 @@ async def cancel_task(
129131 ) -> Task :
130132 """Requests the agent to cancel a specific task."""
131133 task = await self .stub .CancelTask (
132- a2a_pb2 .CancelTaskRequest (name = f" tasks/{ request .id } " )
134+ a2a_pb2 .CancelTaskRequest (name = f' tasks/{ request .id } ' )
133135 )
134136 return proto_utils .FromProto .task (task )
135137
@@ -142,9 +144,11 @@ async def set_task_callback(
142144 """Sets or updates the push notification configuration for a specific task."""
143145 config = await self .stub .CreateTaskPushNotificationConfig (
144146 a2a_pb2 .CreateTaskPushNotificationConfigRequest (
145- parent = "" ,
146- config_id = "" ,
147- config = proto_utils .ToProto .task_push_notification_config (request ),
147+ parent = '' ,
148+ config_id = '' ,
149+ config = proto_utils .ToProto .task_push_notification_config (
150+ request
151+ ),
148152 )
149153 )
150154 return proto_utils .FromProto .task_push_notification_config (config )
@@ -158,7 +162,7 @@ async def get_task_callback(
158162 """Retrieves the push notification configuration for a specific task."""
159163 config = await self .stub .GetTaskPushNotificationConfig (
160164 a2a_pb2 .GetTaskPushNotificationConfigRequest (
161- name = f" tasks/{ request .id } /pushNotification/{ request .push_notification_config_id } " ,
165+ name = f' tasks/{ request .id } /pushNotification/{ request .push_notification_config_id } ' ,
162166 )
163167 )
164168 return proto_utils .FromProto .task_push_notification_config (config )
@@ -170,11 +174,10 @@ async def get_card(
170174 ) -> AgentCard :
171175 """Retrieves the agent's card."""
172176 card = self .agent_card
173- if card is None and not self ._needs_extended_card :
174- raise ValueError ("Agent card is not available." )
175-
176- if not self ._needs_extended_card :
177+ if card and not self ._needs_extended_card :
177178 return card
179+ if card is None and not self ._needs_extended_card :
180+ raise ValueError ('Agent card is not available.' )
178181
179182 card_pb = await self .stub .GetAgentCard (
180183 a2a_pb2 .GetAgentCardRequest (),
@@ -186,5 +189,5 @@ async def get_card(
186189
187190 async def close (self ) -> None :
188191 """Closes the gRPC channel."""
189- if hasattr (self .stub , " close" ):
192+ if hasattr (self .stub , ' close' ):
190193 await self .stub .close ()
0 commit comments