Class GrpcHandler
- All Implemented Interfaces:
io.grpc.BindableService, A2AServiceGrpc.AsyncService
- Direct Known Subclasses:
QuarkusGrpcHandler
This abstract class implements the gRPC service interface for the A2A protocol, handling both unary (blocking) and server streaming RPC calls. It translates gRPC requests to A2A protocol operations, coordinates with the request handler and agent executor, and manages error handling with appropriate gRPC status codes.
Request Flow
gRPC Request → GrpcHandler (this class)
↓
Protobuf → Domain conversion
↓
RequestHandler → AgentExecutor
↓
Domain → Protobuf conversion
↓
gRPC Response (unary or streaming)
Supported Operations
Unary RPC (blocking):
sendMessage(SendMessageRequest, StreamObserver)- Send message and wait for completiongetTask(GetTaskRequest, StreamObserver)- Retrieve task by IDcancelTask(CancelTaskRequest, StreamObserver)- Cancel task executionlistTasks(ListTasksRequest, StreamObserver)- List tasks with filteringcreateTaskPushNotificationConfig(TaskPushNotificationConfig, StreamObserver)- Configure push notificationsgetTaskPushNotificationConfig(GetTaskPushNotificationConfigRequest, StreamObserver)- Get push notification configlistTaskPushNotificationConfigs(ListTaskPushNotificationConfigsRequest, StreamObserver)- List push notification configsdeleteTaskPushNotificationConfig(DeleteTaskPushNotificationConfigRequest, StreamObserver)- Delete push notification configgetExtendedAgentCard(GetExtendedAgentCardRequest, StreamObserver)- Get extended agent capabilities
Server Streaming RPC:
sendStreamingMessage(SendMessageRequest, StreamObserver)- Send message with streaming responsesubscribeToTask(SubscribeToTaskRequest, StreamObserver)- Subscribe to task events
Error Handling
A2A errors are mapped to gRPC status codes:
InvalidRequestError→Status.INVALID_ARGUMENTMethodNotFoundError→Status.NOT_FOUNDTaskNotFoundError→Status.NOT_FOUNDInternalError→Status.INTERNALUnsupportedOperationError→Status.UNIMPLEMENTEDSecurityException→Status.UNAUTHENTICATEDorStatus.PERMISSION_DENIED
Context Access
The handler provides rich context information equivalent to Python's
grpc.aio.ServicerContext:
getCurrentMetadata()- Request metadata (headers)getCurrentMethodName()- gRPC method namegetCurrentPeerInfo()- Client connection details
Extension Points
Subclasses must implement:
getRequestHandler()- Request handler instancegetAgentCard()- Public agent cardgetExtendedAgentCard()- Extended agent card (nullable)getCallContextFactory()- Custom context factory (nullable)getExecutor()- Executor for async operations
CDI Integration
This class is marked with @Vetoed to prevent direct CDI management.
Subclasses should be CDI beans (e.g., @GrpcService in Quarkus) that
inject dependencies and provide them through the abstract methods.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcancelTask(CancelTaskRequest request, io.grpc.stub.StreamObserver<Task> responseObserver) Cancels a task in progress.voidcreateTaskPushNotificationConfig(TaskPushNotificationConfig request, io.grpc.stub.StreamObserver<TaskPushNotificationConfig> responseObserver) (-- api-linter: client-libraries::4232::required-fields=disabled api-linter: core::0133::method-signature=disabled api-linter: core::0133::request-message-name=disabled aip.dev/not-precedent: method_signature preserved for backwards compatibility --) Creates a push notification config for a task.voiddeleteTaskPushNotificationConfig(DeleteTaskPushNotificationConfigRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.Empty> responseObserver) Deletes a push notification config for a task.protected abstract @Nullable AgentCardReturns the public agent card defining the agent's capabilities and metadata, ornullif no public agent card is configured.protected @Nullable AgentCardRouterReturns the optional agent card router for tenant-based resolution, ornull.protected abstract CallContextFactoryReturns the custom call context factory, or null to use default context creation.protected static @Nullable io.grpc.MetadataGets the complete gRPC metadata from the current context.protected static @Nullable StringGets the current gRPC method name.protected static @Nullable StringGets the peer information for the current gRPC call.protected ClassLoaderReturns the deployment classloader for this handler.protected abstract ExecutorReturns the executor for running async operations (streaming subscriptions, etc.).protected abstract AgentCardReturns the extended agent card with additional capabilities, or null if not configured.voidgetExtendedAgentCard(GetExtendedAgentCardRequest request, io.grpc.stub.StreamObserver<AgentCard> responseObserver) Gets the extended agent card for the authenticated agent.protected abstract RequestHandlerReturns the request handler instance for processing A2A protocol requests.voidgetTask(GetTaskRequest request, io.grpc.stub.StreamObserver<Task> responseObserver) Gets the latest state of a task.voidgetTaskPushNotificationConfig(GetTaskPushNotificationConfigRequest request, io.grpc.stub.StreamObserver<TaskPushNotificationConfig> responseObserver) Gets a push notification config for a task.voidlistTaskPushNotificationConfigs(ListTaskPushNotificationConfigsRequest request, io.grpc.stub.StreamObserver<ListTaskPushNotificationConfigsResponse> responseObserver) Get a list of push notifications configured for a task.voidlistTasks(ListTasksRequest request, io.grpc.stub.StreamObserver<ListTasksResponse> responseObserver) Lists tasks that match the specified filter.voidsendMessage(SendMessageRequest request, io.grpc.stub.StreamObserver<SendMessageResponse> responseObserver) Handles a unary (blocking) message send request.voidsendStreamingMessage(SendMessageRequest request, io.grpc.stub.StreamObserver<StreamResponse> responseObserver) Handles a server streaming message send request.static voidsetStreamingSubscribedRunnable(Runnable runnable) Sets a callback to be invoked when streaming subscription starts.voidsubscribeToTask(SubscribeToTaskRequest request, io.grpc.stub.StreamObserver<StreamResponse> responseObserver) Subscribes to task updates for tasks not in a terminal state.Methods inherited from class A2AServiceGrpc.A2AServiceImplBase
bindService
-
Constructor Details
-
GrpcHandler
public GrpcHandler()Constructs a new GrpcHandler.
-
-
Method Details
-
sendMessage
public void sendMessage(SendMessageRequest request, io.grpc.stub.StreamObserver<SendMessageResponse> responseObserver) Handles a unary (blocking) message send request.This method processes a message send request, waits for the agent to complete processing, and returns either a Task or Message in the response.
Protocol Flow:
- Validate A2A protocol version and extensions
- Convert protobuf request to domain
MessageSendParams - Invoke
RequestHandler.onMessageSend(MessageSendParams, ServerCallContext) - Convert domain response to protobuf
SendMessageResponse - Send response and complete the RPC
Error Handling:
A2AError→ mapped to appropriate gRPC status codeSecurityException→UNAUTHENTICATEDorPERMISSION_DENIEDThrowable→INTERNALerror
- Parameters:
request- the gRPC message send requestresponseObserver- the gRPC response stream observer
-
getTask
Description copied from interface:A2AServiceGrpc.AsyncServiceGets the latest state of a task.
-
listTasks
public void listTasks(ListTasksRequest request, io.grpc.stub.StreamObserver<ListTasksResponse> responseObserver) Description copied from interface:A2AServiceGrpc.AsyncServiceLists tasks that match the specified filter.
-
cancelTask
public void cancelTask(CancelTaskRequest request, io.grpc.stub.StreamObserver<Task> responseObserver) Description copied from interface:A2AServiceGrpc.AsyncServiceCancels a task in progress.
-
createTaskPushNotificationConfig
public void createTaskPushNotificationConfig(TaskPushNotificationConfig request, io.grpc.stub.StreamObserver<TaskPushNotificationConfig> responseObserver) Description copied from interface:A2AServiceGrpc.AsyncService(-- api-linter: client-libraries::4232::required-fields=disabled api-linter: core::0133::method-signature=disabled api-linter: core::0133::request-message-name=disabled aip.dev/not-precedent: method_signature preserved for backwards compatibility --) Creates a push notification config for a task. -
getTaskPushNotificationConfig
public void getTaskPushNotificationConfig(GetTaskPushNotificationConfigRequest request, io.grpc.stub.StreamObserver<TaskPushNotificationConfig> responseObserver) Description copied from interface:A2AServiceGrpc.AsyncServiceGets a push notification config for a task.
-
listTaskPushNotificationConfigs
public void listTaskPushNotificationConfigs(ListTaskPushNotificationConfigsRequest request, io.grpc.stub.StreamObserver<ListTaskPushNotificationConfigsResponse> responseObserver) Description copied from interface:A2AServiceGrpc.AsyncServiceGet a list of push notifications configured for a task.
-
sendStreamingMessage
public void sendStreamingMessage(SendMessageRequest request, io.grpc.stub.StreamObserver<StreamResponse> responseObserver) Handles a server streaming message send request.This method processes a message send request with streaming response, where the agent can emit multiple events (artifacts, status updates, messages) as the task progresses.
Protocol Flow:
- Verify streaming capability is enabled in agent card
- Validate A2A protocol version and extensions
- Convert protobuf request to domain
MessageSendParams - Invoke
RequestHandler.onMessageSendStream(MessageSendParams, ServerCallContext) - Subscribe to event publisher and stream responses
- Convert each domain event to protobuf
StreamResponse - Complete RPC when final event received or error occurs
Streaming Characteristics:
- Server streaming RPC - server sends multiple responses
- Backpressure handled through reactive streams subscription
- Client disconnect detection via gRPC context cancellation
- Automatic cleanup when stream completes or errors
Error Handling:
- Streaming not enabled →
UnsupportedOperationError - Other
A2AError→ mapped to appropriate gRPC status code SecurityException→UNAUTHENTICATEDorPERMISSION_DENIEDThrowable→INTERNALerror
- Parameters:
request- the gRPC message send requestresponseObserver- the gRPC response stream observer
-
subscribeToTask
public void subscribeToTask(SubscribeToTaskRequest request, io.grpc.stub.StreamObserver<StreamResponse> responseObserver) Description copied from interface:A2AServiceGrpc.AsyncServiceSubscribes to task updates for tasks not in a terminal state. Returns `UnsupportedOperationError` if the task is already in a terminal state (completed, failed, canceled, rejected).
-
getExtendedAgentCard
public void getExtendedAgentCard(GetExtendedAgentCardRequest request, io.grpc.stub.StreamObserver<AgentCard> responseObserver) Description copied from interface:A2AServiceGrpc.AsyncServiceGets the extended agent card for the authenticated agent.
-
deleteTaskPushNotificationConfig
public void deleteTaskPushNotificationConfig(DeleteTaskPushNotificationConfigRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.Empty> responseObserver) Description copied from interface:A2AServiceGrpc.AsyncServiceDeletes a push notification config for a task.
-
getDeploymentClassLoader
Returns the deployment classloader for this handler.Used for transport configuration validation with proper classloader context.
- Returns:
- the deployment classloader
-
setStreamingSubscribedRunnable
Sets a callback to be invoked when streaming subscription starts.This is a testing hook used to synchronize test execution with streaming setup. In production, this remains null.
- Parameters:
runnable- the callback to invoke on subscription
-
getRequestHandler
Returns the request handler instance for processing A2A protocol requests.- Returns:
- the request handler
-
getAgentCard
Returns the public agent card defining the agent's capabilities and metadata, ornullif no public agent card is configured.- Returns:
- the agent card, or
nullif not configured
-
getExtendedAgentCard
Returns the extended agent card with additional capabilities, or null if not configured.- Returns:
- the extended agent card, or null if not available
-
getCallContextFactory
Returns the custom call context factory, or null to use default context creation.- Returns:
- the call context factory, or null for default behavior
-
getExecutor
Returns the executor for running async operations (streaming subscriptions, etc.).- Returns:
- the executor
-
getAgentCardRouter
Returns the optional agent card router for tenant-based resolution, ornull. Subclasses may override to provide a router implementation.- Returns:
- the agent card router, or
nullif multitenancy is not configured
-
getCurrentMetadata
protected static @Nullable io.grpc.Metadata getCurrentMetadata()Gets the complete gRPC metadata from the current context. Equivalent to Python's context.invocation_metadata.- Returns:
- the gRPC Metadata object, or null if not available
-
getCurrentMethodName
Gets the current gRPC method name. Equivalent to Python's context.method().- Returns:
- the method name, or null if not available
-
getCurrentPeerInfo
Gets the peer information for the current gRPC call. Equivalent to Python's context.peer().- Returns:
- the peer information, or null if not available
-