Class RestHandler
This handler converts HTTP REST requests into A2A protocol operations and manages the lifecycle of agent interactions including message sending, task management, and push notification configurations.
Request Flow
HTTP REST requests flow through this handler to the underlying RequestHandler,
which coordinates with the agent executor and event queue system:
HTTP Request → RestHandler → RequestHandler → AgentExecutor
↓ ↓
Validation EventQueue → Response
Supported Operations
- Message sending (blocking and streaming)
- Task management (get, list, cancel, subscribe)
- Push notification configurations (create, get, list, delete)
- Agent card retrieval (public and extended)
Error Handling
All A2A protocol errors are caught and converted to appropriate HTTP status codes
via mapErrorToHttpStatus(A2AError). Protocol version and required extensions
are validated before processing requests.
CDI Integration
This handler is an @ApplicationScoped CDI bean that requires:
AgentCardqualified with@PublicAgentCardRequestHandlerfor processing A2A operationsExecutorqualified with@Internalfor async operations- Optional
AgentCardqualified with@ExtendedAgentCard
- See Also:
-
RequestHandlerDefaultRequestHandlerAgentCardServerCallContext
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents an HTTP REST response with status code, content type, and body.static classRepresents an HTTP streaming response with Server-Sent Events. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedNo-args constructor for CDI proxy creation.RestHandler(org.a2aproject.sdk.spec.AgentCard agentCard, jakarta.enterprise.inject.Instance<org.a2aproject.sdk.spec.AgentCard> extendedAgentCard, org.a2aproject.sdk.server.AgentCardCacheMetadata cacheMetadata, org.a2aproject.sdk.server.requesthandlers.RequestHandler requestHandler, Executor executor) Creates a REST handler with full CDI injection support.RestHandler(org.a2aproject.sdk.spec.AgentCard agentCard, org.a2aproject.sdk.server.AgentCardCacheMetadata cacheMetadata, org.a2aproject.sdk.server.requesthandlers.RequestHandler requestHandler, Executor executor) Creates a REST handler with basic dependencies. -
Method Summary
Modifier and TypeMethodDescriptioncancelTask(org.a2aproject.sdk.server.ServerCallContext context, String tenant, String body, String taskId) Handles a task cancellation request.createErrorResponse(org.a2aproject.sdk.spec.A2AError error) Creates an HTTP error response from an A2A error.createTaskPushNotificationConfiguration(org.a2aproject.sdk.server.ServerCallContext context, String tenant, String body, String taskId) Creates a push notification configuration for a task.deleteTaskPushNotificationConfiguration(org.a2aproject.sdk.server.ServerCallContext context, String tenant, String taskId, String configId) Deletes a push notification configuration for a task.Retrieves the public agent card.getExtendedAgentCard(org.a2aproject.sdk.server.ServerCallContext context, String tenant) Retrieves the extended agent card if configured.getTask(org.a2aproject.sdk.server.ServerCallContext context, String tenant, String taskId, @Nullable Integer historyLength) Retrieves a task by ID.getTaskPushNotificationConfiguration(org.a2aproject.sdk.server.ServerCallContext context, String tenant, String taskId, String configId) Retrieves a specific push notification configuration for a task.listTaskPushNotificationConfigurations(org.a2aproject.sdk.server.ServerCallContext context, String tenant, String taskId, int pageSize, String pageToken) Lists push notification configurations for a task.listTasks(org.a2aproject.sdk.server.ServerCallContext context, String tenant, @Nullable String contextId, @Nullable String status, @Nullable Integer pageSize, @Nullable String pageToken, @Nullable Integer historyLength, @Nullable String statusTimestampAfter, @Nullable Boolean includeArtifacts) Lists tasks with optional filtering and pagination.sendMessage(org.a2aproject.sdk.server.ServerCallContext context, String tenant, String body) Handles a blocking message send request.sendStreamingMessage(org.a2aproject.sdk.server.ServerCallContext context, String tenant, String body) Handles a streaming message send request.subscribeToTask(org.a2aproject.sdk.server.ServerCallContext context, String tenant, String taskId) Subscribes to task updates via a streaming connection.
-
Constructor Details
-
RestHandler
protected RestHandler()No-args constructor for CDI proxy creation. CDI requires a non-private constructor to create proxies for @ApplicationScoped beans. All fields are initialized by the @Inject constructor during actual bean creation. -
RestHandler
@Inject public RestHandler(org.a2aproject.sdk.spec.AgentCard agentCard, jakarta.enterprise.inject.Instance<org.a2aproject.sdk.spec.AgentCard> extendedAgentCard, org.a2aproject.sdk.server.AgentCardCacheMetadata cacheMetadata, org.a2aproject.sdk.server.requesthandlers.RequestHandler requestHandler, Executor executor) Creates a REST handler with full CDI injection support.- Parameters:
agentCard- the public agent card containing agent capabilitiesextendedAgentCard- optional extended agent card instancecacheMetadata- the agent card caching metadatarequestHandler- the handler for processing A2A requestsexecutor- the executor for asynchronous operations
-
RestHandler
public RestHandler(org.a2aproject.sdk.spec.AgentCard agentCard, org.a2aproject.sdk.server.AgentCardCacheMetadata cacheMetadata, org.a2aproject.sdk.server.requesthandlers.RequestHandler requestHandler, Executor executor) Creates a REST handler with basic dependencies.- Parameters:
agentCard- the agent card containing agent capabilitiescacheMetadata- the agent card caching metadatarequestHandler- the handler for processing A2A requestsexecutor- the executor for asynchronous operations
-
-
Method Details
-
sendMessage
public RestHandler.HTTPRestResponse sendMessage(org.a2aproject.sdk.server.ServerCallContext context, String tenant, String body) Handles a blocking message send request.This method processes an HTTP POST request containing a message to be sent to the agent. The request is validated for protocol version and required extensions before being forwarded to the
RequestHandler. The method blocks until the agent produces a terminal event or requires authentication/input.Example Request:
POST /v1/tenants/{tenant}/messages Content-Type: application/json { "message": { "parts": [ {"text": "What is the weather in San Francisco?"} ] } }Example Response:
HTTP/1.1 200 OK Content-Type: application/json { "task": { "id": "task-123", "status": {"state": "COMPLETED"}, "artifacts": [...] } }- Parameters:
context- the server call context containing authentication and metadatatenant- the tenant identifierbody- the JSON request body containing the message to send- Returns:
- the HTTP response containing the task or message result
- See Also:
-
sendStreamingMessage(ServerCallContext, String, String)RequestHandler.onMessageSend(org.a2aproject.sdk.spec.MessageSendParams, ServerCallContext)
-
sendStreamingMessage
public RestHandler.HTTPRestResponse sendStreamingMessage(org.a2aproject.sdk.server.ServerCallContext context, String tenant, String body) Handles a streaming message send request.This method processes an HTTP POST request for streaming responses from the agent. The response is returned as Server-Sent Events (SSE) via
RestHandler.HTTPRestStreamingResponse, allowing clients to receive task updates and artifacts as they are produced by the agent.This method requires the agent card to have
capabilities.streaming = true.Example Request:
POST /v1/tenants/{tenant}/messages/stream Content-Type: application/json { "message": { "parts": [ {"text": "Generate a long story"} ] } }Example Streaming Response:
HTTP/1.1 200 OK Content-Type: text/event-stream data: {"taskStatusUpdate":{"task":{"id":"task-123","status":{"state":"WORKING"}}}} data: {"taskArtifactUpdate":{"taskId":"task-123","artifacts":[{"parts":[{"text":"Once upon"}]}]}} data: {"taskArtifactUpdate":{"taskId":"task-123","artifacts":[{"parts":[{"text":" a time..."}]}]}} data: {"taskStatusUpdate":{"task":{"id":"task-123","status":{"state":"COMPLETED"}}}}- Parameters:
context- the server call context containing authentication and metadatatenant- the tenant identifierbody- the JSON request body containing the message to send- Returns:
- the streaming HTTP response containing a publisher of events
- See Also:
-
sendMessage(ServerCallContext, String, String)RequestHandler.onMessageSendStream(org.a2aproject.sdk.spec.MessageSendParams, ServerCallContext)RestHandler.HTTPRestStreamingResponse
-
cancelTask
public RestHandler.HTTPRestResponse cancelTask(org.a2aproject.sdk.server.ServerCallContext context, String tenant, String body, String taskId) Handles a task cancellation request.Attempts to cancel a running task identified by the task ID. The cancellation request is forwarded to the
RequestHandler, which signals the agent executor to stop processing. The agent should transition the task toCANCELEDstate.Example Request:
POST /v1/tenants/{tenant}/tasks/{taskId}/cancel- Parameters:
context- the server call context containing authentication and metadatatenant- the tenant identifierbody- the JSON request bodytaskId- the ID of the task to cancel- Returns:
- the HTTP response containing the cancelled task
- Throws:
org.a2aproject.sdk.spec.InvalidParamsError- if taskId is null or empty- See Also:
-
RequestHandler.onCancelTask(CancelTaskParams, ServerCallContext)AgentExecutor.cancel(org.a2aproject.sdk.server.agentexecution.RequestContext, org.a2aproject.sdk.server.tasks.AgentEmitter)
-
createTaskPushNotificationConfiguration
public RestHandler.HTTPRestResponse createTaskPushNotificationConfiguration(org.a2aproject.sdk.server.ServerCallContext context, String tenant, String body, String taskId) Creates a push notification configuration for a task.- Parameters:
context- the server call context containing authentication and metadatatenant- the tenant identifierbody- the JSON request body containing the configurationtaskId- the ID of the task- Returns:
- the HTTP response containing the created configuration
-
subscribeToTask
public RestHandler.HTTPRestResponse subscribeToTask(org.a2aproject.sdk.server.ServerCallContext context, String tenant, String taskId) Subscribes to task updates via a streaming connection.Creates a Server-Sent Events (SSE) stream that delivers real-time updates for an existing task. This allows clients to reconnect to ongoing or completed tasks and receive their event history and future updates.
This method requires the agent card to have
capabilities.streaming = true.Example Request:
GET /v1/tenants/{tenant}/tasks/{taskId}/subscribeUse Cases:
- Reconnecting to a task after network interruption
- Monitoring long-running tasks from multiple clients
- Viewing historical events for completed tasks
- Parameters:
context- the server call context containing authentication and metadatatenant- the tenant identifiertaskId- the ID of the task to subscribe to- Returns:
- the streaming HTTP response containing task updates
- See Also:
-
RequestHandler.onSubscribeToTask(TaskIdParams, ServerCallContext)sendStreamingMessage(ServerCallContext, String, String)
-
getTask
public RestHandler.HTTPRestResponse getTask(org.a2aproject.sdk.server.ServerCallContext context, String tenant, String taskId, @Nullable Integer historyLength) Retrieves a task by ID.- Parameters:
context- the server call context containing authentication and metadatatenant- the tenant identifiertaskId- the ID of the task to retrievehistoryLength- the maximum number of history entries to include- Returns:
- the HTTP response containing the task
-
listTasks
public RestHandler.HTTPRestResponse listTasks(org.a2aproject.sdk.server.ServerCallContext context, String tenant, @Nullable String contextId, @Nullable String status, @Nullable Integer pageSize, @Nullable String pageToken, @Nullable Integer historyLength, @Nullable String statusTimestampAfter, @Nullable Boolean includeArtifacts) Lists tasks with optional filtering and pagination.Retrieves a list of tasks with support for filtering by context, status, and timestamp, along with pagination controls. This method is useful for task management dashboards, monitoring systems, and task history retrieval.
Example Request:
GET /v1/tenants/{tenant}/tasks?status=COMPLETED&pageSize=10&includeArtifacts=trueQuery Parameters:
contextId- Filter tasks by conversation contextstatus- Filter by task state (SUBMITTED, WORKING, COMPLETED, etc.)pageSize- Maximum tasks to return (for pagination)pageToken- Token for retrieving next page of resultshistoryLength- Maximum history entries to include per taskstatusTimestampAfter- ISO-8601 timestamp for filtering recent tasksincludeArtifacts- Whether to include task artifacts in response
- Parameters:
context- the server call context containing authentication and metadatatenant- the tenant identifiercontextId- optional context ID to filter bystatus- optional task status to filter by (must be validTaskStatevalue)pageSize- optional maximum number of tasks to returnpageToken- optional token for paginationhistoryLength- optional maximum number of history entries per taskstatusTimestampAfter- optional ISO-8601 timestamp to filter tasks updated afterincludeArtifacts- optional flag to include task artifacts- Returns:
- the HTTP response containing the list of tasks
- Throws:
org.a2aproject.sdk.spec.InvalidParamsError- if status is not a valid TaskState or timestamp is malformed- See Also:
-
RequestHandler.onListTasks(ListTasksParams, ServerCallContext)TaskState
-
getTaskPushNotificationConfiguration
public RestHandler.HTTPRestResponse getTaskPushNotificationConfiguration(org.a2aproject.sdk.server.ServerCallContext context, String tenant, String taskId, String configId) Retrieves a specific push notification configuration for a task.- Parameters:
context- the server call context containing authentication and metadatatenant- the tenant identifiertaskId- the ID of the taskconfigId- the ID of the configuration to retrieve- Returns:
- the HTTP response containing the configuration
-
listTaskPushNotificationConfigurations
public RestHandler.HTTPRestResponse listTaskPushNotificationConfigurations(org.a2aproject.sdk.server.ServerCallContext context, String tenant, String taskId, int pageSize, String pageToken) Lists push notification configurations for a task.- Parameters:
context- the server call context containing authentication and metadatatenant- the tenant identifiertaskId- the ID of the taskpageSize- the maximum number of configurations to returnpageToken- the token for pagination- Returns:
- the HTTP response containing the list of configurations
-
deleteTaskPushNotificationConfiguration
public RestHandler.HTTPRestResponse deleteTaskPushNotificationConfiguration(org.a2aproject.sdk.server.ServerCallContext context, String tenant, String taskId, String configId) Deletes a push notification configuration for a task.- Parameters:
context- the server call context containing authentication and metadatatenant- the tenant identifiertaskId- the ID of the taskconfigId- the ID of the configuration to delete- Returns:
- the HTTP response with no content on success
-
createErrorResponse
Creates an HTTP error response from an A2A error.- Parameters:
error- the A2A error to convert- Returns:
- the HTTP response with appropriate status code and error details
-
getExtendedAgentCard
public RestHandler.HTTPRestResponse getExtendedAgentCard(org.a2aproject.sdk.server.ServerCallContext context, String tenant) Retrieves the extended agent card if configured.The extended agent card provides additional metadata beyond the public agent card, such as tenant-specific configurations or private capabilities. This endpoint requires the agent card to have
capabilities.extendedAgentCard = trueand a CDI-produced@ExtendedAgentCardinstance.Example Request:
GET /v1/tenants/{tenant}/extended-agent-card- Parameters:
context- the server call context containing authentication and metadatatenant- the tenant identifier- Returns:
- the HTTP response containing the extended agent card
- Throws:
org.a2aproject.sdk.spec.ExtendedAgentCardNotConfiguredError- if extended agent card is not available- See Also:
-
getAgentCard()AgentCard
-
getAgentCard
Retrieves the public agent card.The agent card is a self-describing manifest that provides essential metadata about the agent, including its capabilities, supported skills, communication methods, and security requirements. This is the primary discovery endpoint for clients to understand what the agent can do and how to interact with it.
Example Request:
GET /v1/agent-cardExample Response:
{ "name": "Weather Agent", "description": "Provides weather information", "version": "1.0.0", "capabilities": { "streaming": true, "pushNotifications": false }, "skills": [...], "supportedInterfaces": [...] }- Returns:
- the HTTP response containing the agent card
- See Also:
-