Skip to content

Commit 0c1987b

Browse files
authored
fix: Fix reference to grpc.aio.ServicerContext (#237)
# Description Fix references in a2a/server/request_handlers/grpc_handler.py to grpc.aio.ServicerContext. The import for grpc.aio was missing and various functions incorrectly referenced grpc.ServicerContext. This is a backwards compatible change, it's just typing annotations for internal functions that were off. The actual code itself worked, as can be demonstrated by running the sample agent in a2aproject/a2a-samples/samples/python/agents/dice_agent_grpc.
1 parent a5509e6 commit 0c1987b

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/a2a/server/request_handlers/grpc_handler.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from collections.abc import AsyncIterable
77

88
import grpc
9+
import grpc.aio
910

1011
import a2a.grpc.a2a_pb2_grpc as a2a_grpc
1112

@@ -14,10 +15,7 @@
1415
from a2a.grpc import a2a_pb2
1516
from a2a.server.context import ServerCallContext
1617
from a2a.server.request_handlers.request_handler import RequestHandler
17-
from a2a.types import (
18-
AgentCard,
19-
TaskNotFoundError,
20-
)
18+
from a2a.types import AgentCard, TaskNotFoundError
2119
from a2a.utils import proto_utils
2220
from a2a.utils.errors import ServerError
2321
from a2a.utils.helpers import validate, validate_async_generator
@@ -32,14 +30,14 @@ class CallContextBuilder(ABC):
3230
"""A class for building ServerCallContexts using the Starlette Request."""
3331

3432
@abstractmethod
35-
def build(self, context: grpc.ServicerContext) -> ServerCallContext:
33+
def build(self, context: grpc.aio.ServicerContext) -> ServerCallContext:
3634
"""Builds a ServerCallContext from a gRPC Request."""
3735

3836

3937
class DefaultCallContextBuilder(CallContextBuilder):
4038
"""A default implementation of CallContextBuilder."""
4139

42-
def build(self, context: grpc.ServicerContext) -> ServerCallContext:
40+
def build(self, context: grpc.aio.ServicerContext) -> ServerCallContext:
4341
"""Builds the ServerCallContext."""
4442
user = UnauthenticatedUser()
4543
state = {}
@@ -301,7 +299,7 @@ async def GetAgentCard(
301299
return proto_utils.ToProto.agent_card(self.agent_card)
302300

303301
async def abort_context(
304-
self, error: ServerError, context: grpc.ServicerContext
302+
self, error: ServerError, context: grpc.aio.ServicerContext
305303
) -> None:
306304
"""Sets the grpc errors appropriately in the context."""
307305
match error.error:

0 commit comments

Comments
 (0)