1212from a2a .compat .v0_3 import (
1313 a2a_v0_3_pb2 ,
1414 a2a_v0_3_pb2_grpc ,
15- conversions ,
1615 proto_utils ,
1716)
1817from a2a .compat .v0_3 import (
2726 GrpcServerCallContextBuilder ,
2827)
2928from a2a .server .request_handlers .request_handler import RequestHandler
30- from a2a .types .a2a_pb2 import AgentCard
3129from a2a .utils .errors import A2AError , InvalidParamsError
32- from a2a .utils .helpers import maybe_await , validate
3330
3431
3532logger = logging .getLogger (__name__ )
@@ -42,29 +39,21 @@ class CompatGrpcHandler(a2a_v0_3_pb2_grpc.A2AServiceServicer):
4239
4340 def __init__ (
4441 self ,
45- agent_card : AgentCard ,
4642 request_handler : RequestHandler ,
4743 context_builder : GrpcServerCallContextBuilder | None = None ,
48- card_modifier : Callable [[AgentCard ], Awaitable [AgentCard ] | AgentCard ]
49- | None = None ,
5044 ):
5145 """Initializes the CompatGrpcHandler.
5246
5347 Args:
54- agent_card: The AgentCard describing the agent's capabilities (v1.0).
5548 request_handler: The underlying `RequestHandler` instance to
5649 delegate requests to.
5750 context_builder: The CallContextBuilder object. If none the
5851 DefaultCallContextBuilder is used.
59- card_modifier: An optional callback to dynamically modify the public
60- agent card before it is served.
6152 """
62- self .agent_card = agent_card
6353 self .handler03 = RequestHandler03 (request_handler = request_handler )
6454 self ._context_builder = (
6555 context_builder or DefaultGrpcServerCallContextBuilder ()
6656 )
67- self .card_modifier = card_modifier
6857
6958 async def _handle_unary (
7059 self ,
@@ -179,10 +168,6 @@ async def SendStreamingMessage(
179168 ) -> AsyncIterable [a2a_v0_3_pb2 .StreamResponse ]:
180169 """Handles the 'SendStreamingMessage' gRPC method (v0.3)."""
181170
182- @validate (
183- lambda _ : self .agent_card .capabilities .streaming ,
184- 'Streaming is not supported by the agent' ,
185- )
186171 async def _handler (
187172 server_context : ServerCallContext ,
188173 ) -> AsyncIterable [a2a_v0_3_pb2 .StreamResponse ]:
@@ -242,10 +227,6 @@ async def TaskSubscription(
242227 ) -> AsyncIterable [a2a_v0_3_pb2 .StreamResponse ]:
243228 """Handles the 'TaskSubscription' gRPC method (v0.3)."""
244229
245- @validate (
246- lambda _ : self .agent_card .capabilities .streaming ,
247- 'Streaming is not supported by the agent' ,
248- )
249230 async def _handler (
250231 server_context : ServerCallContext ,
251232 ) -> AsyncIterable [a2a_v0_3_pb2 .StreamResponse ]:
@@ -269,10 +250,6 @@ async def CreateTaskPushNotificationConfig(
269250 ) -> a2a_v0_3_pb2 .TaskPushNotificationConfig :
270251 """Handles the 'CreateTaskPushNotificationConfig' gRPC method (v0.3)."""
271252
272- @validate (
273- lambda _ : self .agent_card .capabilities .push_notifications ,
274- 'Push notifications are not supported by the agent' ,
275- )
276253 async def _handler (
277254 server_context : ServerCallContext ,
278255 ) -> a2a_v0_3_pb2 .TaskPushNotificationConfig :
@@ -360,12 +337,19 @@ async def GetAgentCard(
360337 request : a2a_v0_3_pb2 .GetAgentCardRequest ,
361338 context : grpc .aio .ServicerContext ,
362339 ) -> a2a_v0_3_pb2 .AgentCard :
363- """Get the agent card for the agent served (v0.3)."""
364- card_to_serve = self .agent_card
365- if self .card_modifier :
366- card_to_serve = await maybe_await (self .card_modifier (card_to_serve ))
367- return proto_utils .ToProto .agent_card (
368- conversions .to_compat_agent_card (card_to_serve )
340+ """Get the extended agent card for the agent served (v0.3)."""
341+
342+ async def _handler (
343+ server_context : ServerCallContext ,
344+ ) -> a2a_v0_3_pb2 .AgentCard :
345+ req_v03 = types_v03 .GetAuthenticatedExtendedCardRequest (id = 0 )
346+ res_v03 = await self .handler03 .on_get_extended_agent_card (
347+ req_v03 , server_context
348+ )
349+ return proto_utils .ToProto .agent_card (res_v03 )
350+
351+ return await self ._handle_unary (
352+ context , _handler , a2a_v0_3_pb2 .AgentCard ()
369353 )
370354
371355 async def DeleteTaskPushNotificationConfig (
0 commit comments