Skip to content

Commit 852df79

Browse files
committed
Fix error handling for gRPC
1 parent 3f7fc15 commit 852df79

3 files changed

Lines changed: 181 additions & 194 deletions

File tree

src/a2a/compat/v0_3/grpc_handler.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,17 @@ async def _handler(
170170
context, _handler, a2a_v0_3_pb2.SendMessageResponse()
171171
)
172172

173-
@validate_async_generator(
174-
lambda self: self.agent_card.capabilities.streaming,
175-
'Streaming is not supported by the agent',
176-
)
177173
async def SendStreamingMessage(
178174
self,
179175
request: a2a_v0_3_pb2.SendMessageRequest,
180176
context: grpc.aio.ServicerContext,
181177
) -> AsyncIterable[a2a_v0_3_pb2.StreamResponse]:
182178
"""Handles the 'SendStreamingMessage' gRPC method (v0.3)."""
183179

180+
@validate_async_generator(
181+
lambda _: self.agent_card.capabilities.streaming,
182+
'Streaming is not supported by the agent',
183+
)
184184
async def _handler(
185185
server_context: ServerCallContext,
186186
) -> AsyncIterable[a2a_v0_3_pb2.StreamResponse]:
@@ -233,17 +233,17 @@ async def _handler(
233233

234234
return await self._handle_unary(context, _handler, a2a_v0_3_pb2.Task())
235235

236-
@validate_async_generator(
237-
lambda self: self.agent_card.capabilities.streaming,
238-
'Streaming is not supported by the agent',
239-
)
240236
async def TaskSubscription(
241237
self,
242238
request: a2a_v0_3_pb2.TaskSubscriptionRequest,
243239
context: grpc.aio.ServicerContext,
244240
) -> AsyncIterable[a2a_v0_3_pb2.StreamResponse]:
245241
"""Handles the 'TaskSubscription' gRPC method (v0.3)."""
246242

243+
@validate_async_generator(
244+
lambda _: self.agent_card.capabilities.streaming,
245+
'Streaming is not supported by the agent',
246+
)
247247
async def _handler(
248248
server_context: ServerCallContext,
249249
) -> AsyncIterable[a2a_v0_3_pb2.StreamResponse]:
@@ -260,17 +260,17 @@ async def _handler(
260260
async for item in self._handle_stream(context, _handler):
261261
yield item
262262

263-
@validate(
264-
lambda self: self.agent_card.capabilities.push_notifications,
265-
'Push notifications are not supported by the agent',
266-
)
267263
async def CreateTaskPushNotificationConfig(
268264
self,
269265
request: a2a_v0_3_pb2.CreateTaskPushNotificationConfigRequest,
270266
context: grpc.aio.ServicerContext,
271267
) -> a2a_v0_3_pb2.TaskPushNotificationConfig:
272268
"""Handles the 'CreateTaskPushNotificationConfig' gRPC method (v0.3)."""
273269

270+
@validate(
271+
lambda _: self.agent_card.capabilities.push_notifications,
272+
'Push notifications are not supported by the agent',
273+
)
274274
async def _handler(
275275
server_context: ServerCallContext,
276276
) -> a2a_v0_3_pb2.TaskPushNotificationConfig:

0 commit comments

Comments
 (0)