1- import logging
2- import grpc
31import contextlib
2+ import logging
43
5- from typing import AsyncIterable
64from abc import ABC , abstractmethod
5+ from collections .abc import AsyncIterable
6+
7+ import grpc
8+
9+ import a2a .grpc .a2a_pb2_grpc as a2a_grpc
710
11+ from a2a import types
12+ from a2a .auth .user import UnauthenticatedUser
13+ from a2a .grpc import a2a_pb2
814from a2a .server .context import ServerCallContext
915from a2a .server .request_handlers .request_handler import RequestHandler
1016from a2a .types import (
1117 AgentCard ,
12- InternalError ,
13- Message ,
14- Task ,
15- TaskArtifactUpdateEvent ,
1618 TaskNotFoundError ,
1719 TaskPushNotificationConfig ,
18- TaskStatusUpdateEvent ,
1920)
20- from a2a import types
21- from a2a .auth .user import User as A2AUser
22- from a2a .auth .user import UnauthenticatedUser
23- from a2a .server .context import ServerCallContext
21+ from a2a .utils import proto_utils
2422from a2a .utils .errors import ServerError
2523from a2a .utils .helpers import validate , validate_async_generator
26- from a2a .utils import proto_utils
27- import a2a .grpc .a2a_pb2 as a2a_pb2
28- import a2a .grpc .a2a_pb2_grpc as a2a_grpc
2924
3025
3126logger = logging .getLogger (__name__ )
3227
3328# For now we use a trivial wrapper on the grpc context object
3429
30+
3531class CallContextBuilder (ABC ):
3632 """A class for building ServerCallContexts using the Starlette Request."""
3733
@@ -53,7 +49,8 @@ def build(self, context: grpc.ServicerContext) -> ServerCallContext:
5349
5450class GrpcHandler (a2a_grpc .A2AServiceServicer ):
5551 """Maps incoming gRPC requests to the appropriate request handler method
56- and formats responses."""
52+ and formats responses.
53+ """
5754
5855 def __init__ (
5956 self ,
@@ -65,8 +62,7 @@ def __init__(
6562
6663 Args:
6764 agent_card: The AgentCard describing the agent's capabilities.
68- request_handler: The underlying `RequestHandler` instance to delegat
69- e requests to.
65+ request_handler: The underlying `RequestHandler` instance to delegate requests to.
7066 """
7167 self .agent_card = agent_card
7268 self .request_handler = request_handler
@@ -84,10 +80,8 @@ async def SendMessage(
8480 context: Context provided by the server.
8581
8682 Returns:
87- A `SendMessageResponse` object containing the result (Task or Messag
88- e)
89- or throws an error response if a `ServerError` is raised by the han
90- dler.
83+ A `SendMessageResponse` object containing the result (Task or Message)
84+ or throws an error response if a `ServerError` is raised by the handler.
9185 """
9286 try :
9387 # Construct the server context object
@@ -115,7 +109,7 @@ async def SendStreamingMessage(
115109 """Handles the 'StreamMessage' gRPC method.
116110
117111 Yields response objects as they are produced by the underlying handler's
118- stream.
112+ stream.
119113
120114 Args:
121115 request: The incoming `SendMessageRequest` object.
@@ -178,7 +172,7 @@ async def TaskSubscription(
178172 """Handles the 'TaskSubscription' gRPC method.
179173
180174 Yields response objects as they are produced by the underlying handler's
181- stream.
175+ stream.
182176
183177 Args:
184178 request: The incoming `TaskSubscriptionRequest` object.
@@ -190,7 +184,8 @@ async def TaskSubscription(
190184 try :
191185 server_context = self .context_builder .build (context )
192186 async for event in self .request_handler .on_resubscribe_to_task (
193- proto_utils .FromProto .task_id_params (request ), server_context ,
187+ proto_utils .FromProto .task_id_params (request ),
188+ server_context ,
194189 ):
195190 yield proto_utils .ToProto .stream_response (event )
196191 except ServerError as e :
0 commit comments