Skip to content

Commit 8db4e8c

Browse files
committed
refactor: standardize ContextBuilder documentation and remove redundant build_user method from GrpcContextBuilder
1 parent 1864526 commit 8db4e8c

5 files changed

Lines changed: 17 additions & 16 deletions

File tree

src/a2a/server/request_handlers/grpc_handler.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,15 @@ class GrpcContextBuilder(ABC):
4949
def build(self, context: grpc.aio.ServicerContext) -> ServerCallContext:
5050
"""Builds a ServerCallContext from a gRPC ServicerContext."""
5151

52-
@abstractmethod
53-
def build_user(self, context: grpc.aio.ServicerContext) -> User:
54-
"""Builds a User from a gRPC ServicerContext."""
55-
5652

5753
class DefaultGrpcContextBuilder(GrpcContextBuilder):
5854
"""Default implementation of GrpcContextBuilder."""
5955

6056
def build(self, context: grpc.aio.ServicerContext) -> ServerCallContext:
6157
"""Builds a ServerCallContext from a gRPC ServicerContext."""
62-
user = self.build_user(context)
6358
state = {'grpc_context': context}
6459
return ServerCallContext(
65-
user=user,
60+
user=self.build_user(context),
6661
state=state,
6762
requested_extensions=get_requested_extensions(
6863
_get_metadata_value(context, HTTP_EXTENSION_HEADER)
@@ -88,6 +83,7 @@ def _get_metadata_value(
8883
if k.lower() == lower_key
8984
]
9085

86+
9187
_ERROR_CODE_MAP = {
9288
types.InvalidRequestError: grpc.StatusCode.INVALID_ARGUMENT,
9389
types.MethodNotFoundError: grpc.StatusCode.NOT_FOUND,
@@ -125,8 +121,9 @@ def __init__(
125121
agent_card: The AgentCard describing the agent's capabilities.
126122
request_handler: The underlying `RequestHandler` instance to
127123
delegate requests to.
128-
context_builder: Optional custom user builder to extract user from the
129-
gRPC context.
124+
context_builder: The GrpcContextBuilder used to construct the
125+
ServerCallContext passed to the request_handler. If None the
126+
DefaultGrpcContextBuilder is used.
130127
card_modifier: An optional callback to dynamically modify the public
131128
agent card before it is served.
132129
"""

src/a2a/server/routes/jsonrpc_dispatcher.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,9 @@ def __init__( # noqa: PLR0913
161161
requests via http.
162162
extended_agent_card: An optional, distinct AgentCard to be served
163163
at the authenticated extended card endpoint.
164-
context_builder: Optional custom user builder to extract user from the
165-
request.
164+
context_builder: The ContextBuilder used to construct the
165+
ServerCallContext passed to the request_handler. If None the
166+
DefaultContextBuilder is used.
166167
card_modifier: An optional callback to dynamically modify the public
167168
agent card before it is served.
168169
extended_card_modifier: An optional callback to dynamically modify

src/a2a/server/routes/jsonrpc_routes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ def create_jsonrpc_routes( # noqa: PLR0913
5151
rpc_url: The URL prefix for the RPC endpoints.
5252
extended_agent_card: An optional, distinct AgentCard to be served
5353
at the authenticated extended card endpoint.
54-
context_builder: Optional custom context builder to extract user from the
55-
request.
54+
context_builder: The ContextBuilder used to construct the
55+
ServerCallContext passed to the request_handler. If None the
56+
DefaultContextBuilder is used.
5657
card_modifier: An optional callback to dynamically modify the public
5758
agent card before it is served.
5859
extended_card_modifier: An optional callback to dynamically modify

src/a2a/server/routes/rest_dispatcher.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ def __init__( # noqa: PLR0913
8686
request_handler: The underlying `RequestHandler` instance to delegate requests to.
8787
extended_agent_card: An optional, distinct AgentCard to be served
8888
at the authenticated extended card endpoint.
89-
context_builder: Optional custom user builder to extract user from the
90-
request.
89+
context_builder: The ContextBuilder used to construct the
90+
ServerCallContext passed to the request_handler. If None the
91+
DefaultContextBuilder is used.
9192
card_modifier: An optional callback to dynamically modify the public
9293
agent card before it is served.
9394
extended_card_modifier: An optional callback to dynamically modify

src/a2a/server/routes/rest_routes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ def create_rest_routes( # noqa: PLR0913
6464
requests via http.
6565
extended_agent_card: An optional, distinct AgentCard to be served
6666
at the authenticated extended card endpoint.
67-
context_builder: Optional custom user builder to extract user from the
68-
request.
67+
context_builder: The ContextBuilder used to construct the
68+
ServerCallContext passed to the request_handler. If None the
69+
DefaultContextBuilder is used.
6970
card_modifier: An optional callback to dynamically modify the public
7071
agent card before it is served.
7172
extended_card_modifier: An optional callback to dynamically modify

0 commit comments

Comments
 (0)