Package io.a2a.client
Class A2AClient
java.lang.Object
io.a2a.client.A2AClient
An A2A client.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncancelTask(TaskIdParams taskIdParams) Cancel a task that was previously submitted to the A2A server.cancelTask(String id) Cancel a task that was previously submitted to the A2A server.cancelTask(String requestId, TaskIdParams taskIdParams) Cancel a task that was previously submitted to the A2A server.deleteTaskPushNotificationConfig(DeleteTaskPushNotificationConfigParams deleteTaskPushNotificationConfigParams) Delete the push notification configuration for a specified task.deleteTaskPushNotificationConfig(String requestId, DeleteTaskPushNotificationConfigParams deleteTaskPushNotificationConfigParams) Delete the push notification configuration for a specified task.deleteTaskPushNotificationConfig(String taskId, String pushNotificationConfigId) Delete the push notification configuration for a specified task.deleteTaskPushNotificationConfig(String requestId, String taskId, String pushNotificationConfigId) Delete the push notification configuration for a specified task.Get the agent card for the A2A server this client will be communicating with from the default public agent card endpoint.getAgentCard(String relativeCardPath, Map<String, String> authHeaders) Get the agent card for the A2A server this client will be communicating with.static A2AClientgetClientFromAgentCardUrl(A2AHttpClient httpClient, String baseUrl, String agentCardPath) Fetches the agent card and initialises an A2A client.getTask(TaskQueryParams taskQueryParams) Retrieve a task from the A2A server.Retrieve a task from the A2A server.getTask(String requestId, TaskQueryParams taskQueryParams) Retrieve the generated artifacts for a task.getTaskPushNotificationConfig(GetTaskPushNotificationConfigParams getTaskPushNotificationConfigParams) Get the push notification configuration for a task.getTaskPushNotificationConfig(String taskId) Get the push notification configuration for a task.getTaskPushNotificationConfig(String requestId, GetTaskPushNotificationConfigParams getTaskPushNotificationConfigParams) Get the push notification configuration for a task.getTaskPushNotificationConfig(String taskId, String pushNotificationConfigId) Get the push notification configuration for a task.listTaskPushNotificationConfig(ListTaskPushNotificationConfigParams listTaskPushNotificationConfigParams) Retrieves the push notification configurations for a specified task.listTaskPushNotificationConfig(String taskId) Retrieves the push notification configurations for a specified task.listTaskPushNotificationConfig(String requestId, ListTaskPushNotificationConfigParams listTaskPushNotificationConfigParams) Retrieves the push notification configurations for a specified task.listTaskPushNotificationConfig(String requestId, String taskId) Retrieves the push notification configurations for a specified task.voidresubscribeToTask(TaskIdParams taskIdParams, Consumer<StreamingEventKind> eventHandler, Consumer<JSONRPCError> errorHandler, Runnable failureHandler) Resubscribe to an ongoing task.voidresubscribeToTask(String requestId, TaskIdParams taskIdParams, Consumer<StreamingEventKind> eventHandler, Consumer<JSONRPCError> errorHandler, Runnable failureHandler) Resubscribe to an ongoing task.sendMessage(MessageSendParams messageSendParams) Send a message to the remote agent.sendMessage(String requestId, MessageSendParams messageSendParams) Send a message to the remote agent.voidsendStreamingMessage(MessageSendParams messageSendParams, Consumer<StreamingEventKind> eventHandler, Consumer<JSONRPCError> errorHandler, Runnable failureHandler) Send a streaming message to the remote agent.voidsendStreamingMessage(String requestId, MessageSendParams messageSendParams, Consumer<StreamingEventKind> eventHandler, Consumer<JSONRPCError> errorHandler, Runnable failureHandler) Send a streaming message to the remote agent.setTaskPushNotificationConfig(String taskId, PushNotificationConfig pushNotificationConfig) Set push notification configuration for a task.setTaskPushNotificationConfig(String requestId, String taskId, PushNotificationConfig pushNotificationConfig) Set push notification configuration for a task.
-
Constructor Details
-
A2AClient
Create a new A2AClient.- Parameters:
agentCard- the agent card for the A2A server this client will be communicating with
-
A2AClient
Create a new A2AClient.- Parameters:
agentUrl- the URL for the A2A server this client will be communicating with
-
-
Method Details
-
getClientFromAgentCardUrl
public static A2AClient getClientFromAgentCardUrl(A2AHttpClient httpClient, String baseUrl, String agentCardPath) throws A2AClientError, A2AClientJSONError Fetches the agent card and initialises an A2A client.- Parameters:
httpClient- theA2AHttpClientto usebaseUrl- the base URL of the agent's hostagentCardPath- the path to the agent card endpoint, relative to thebaseUrl. Ifnull, the valueA2ACardResolver.DEFAULT_AGENT_CARD_PATHwill be used- Returns:
- an initialised
A2AClientinstance - Throws:
A2AClientError- If an HTTP error occurs fetching the cardA2AClientJSONError- if the agent card response is invalid
-
getAgentCard
Get the agent card for the A2A server this client will be communicating with from the default public agent card endpoint.- Returns:
- the agent card for the A2A server
- Throws:
A2AClientError- If an HTTP error occurs fetching the cardA2AClientJSONError- f the response body cannot be decoded as JSON or validated against the AgentCard schema
-
getAgentCard
public AgentCard getAgentCard(String relativeCardPath, Map<String, String> authHeaders) throws A2AClientError, A2AClientJSONErrorGet the agent card for the A2A server this client will be communicating with.- Parameters:
relativeCardPath- the path to the agent card endpoint relative to the base URL of the A2A serverauthHeaders- the HTTP authentication headers to use- Returns:
- the agent card for the A2A server
- Throws:
A2AClientError- If an HTTP error occurs fetching the cardA2AClientJSONError- f the response body cannot be decoded as JSON or validated against the AgentCard schema
-
sendMessage
public SendMessageResponse sendMessage(MessageSendParams messageSendParams) throws A2AServerException Send a message to the remote agent.- Parameters:
messageSendParams- the parameters for the message to be sent- Returns:
- the response, may contain a message or a task
- Throws:
A2AServerException- if sending the message fails for any reason
-
sendMessage
public SendMessageResponse sendMessage(String requestId, MessageSendParams messageSendParams) throws A2AServerException Send a message to the remote agent.- Parameters:
requestId- the request ID to usemessageSendParams- the parameters for the message to be sent- Returns:
- the response, may contain a message or a task
- Throws:
A2AServerException- if sending the message fails for any reason
-
getTask
Retrieve a task from the A2A server. This method can be used to retrieve the generated artifacts for a task.- Parameters:
id- the task ID- Returns:
- the response containing the task
- Throws:
A2AServerException- if retrieving the task fails for any reason
-
getTask
Retrieve a task from the A2A server. This method can be used to retrieve the generated artifacts for a task.- Parameters:
taskQueryParams- the params for the task to be queried- Returns:
- the response containing the task
- Throws:
A2AServerException- if retrieving the task fails for any reason
-
getTask
public GetTaskResponse getTask(String requestId, TaskQueryParams taskQueryParams) throws A2AServerException Retrieve the generated artifacts for a task.- Parameters:
requestId- the request ID to usetaskQueryParams- the params for the task to be queried- Returns:
- the response containing the task
- Throws:
A2AServerException- if retrieving the task fails for any reason
-
cancelTask
Cancel a task that was previously submitted to the A2A server.- Parameters:
id- the task ID- Returns:
- the response indicating if the task was cancelled
- Throws:
A2AServerException- if cancelling the task fails for any reason
-
cancelTask
Cancel a task that was previously submitted to the A2A server.- Parameters:
taskIdParams- the params for the task to be cancelled- Returns:
- the response indicating if the task was cancelled
- Throws:
A2AServerException- if cancelling the task fails for any reason
-
cancelTask
public CancelTaskResponse cancelTask(String requestId, TaskIdParams taskIdParams) throws A2AServerException Cancel a task that was previously submitted to the A2A server.- Parameters:
requestId- the request ID to usetaskIdParams- the params for the task to be cancelled- Returns:
- the response indicating if the task was cancelled
- Throws:
A2AServerException- if retrieving the task fails for any reason
-
getTaskPushNotificationConfig
public GetTaskPushNotificationConfigResponse getTaskPushNotificationConfig(String taskId) throws A2AServerException Get the push notification configuration for a task.- Parameters:
taskId- the task ID- Returns:
- the response containing the push notification configuration
- Throws:
A2AServerException- if getting the push notification configuration fails for any reason
-
getTaskPushNotificationConfig
public GetTaskPushNotificationConfigResponse getTaskPushNotificationConfig(String taskId, String pushNotificationConfigId) throws A2AServerException Get the push notification configuration for a task.- Parameters:
taskId- the task IDpushNotificationConfigId- the push notification configuration ID- Returns:
- the response containing the push notification configuration
- Throws:
A2AServerException- if getting the push notification configuration fails for any reason
-
getTaskPushNotificationConfig
public GetTaskPushNotificationConfigResponse getTaskPushNotificationConfig(GetTaskPushNotificationConfigParams getTaskPushNotificationConfigParams) throws A2AServerException Get the push notification configuration for a task.- Parameters:
getTaskPushNotificationConfigParams- the params for the task- Returns:
- the response containing the push notification configuration
- Throws:
A2AServerException- if getting the push notification configuration fails for any reason
-
getTaskPushNotificationConfig
public GetTaskPushNotificationConfigResponse getTaskPushNotificationConfig(String requestId, GetTaskPushNotificationConfigParams getTaskPushNotificationConfigParams) throws A2AServerException Get the push notification configuration for a task.- Parameters:
requestId- the request ID to usegetTaskPushNotificationConfigParams- the params for the task- Returns:
- the response containing the push notification configuration
- Throws:
A2AServerException- if getting the push notification configuration fails for any reason
-
setTaskPushNotificationConfig
public SetTaskPushNotificationConfigResponse setTaskPushNotificationConfig(String taskId, PushNotificationConfig pushNotificationConfig) throws A2AServerException Set push notification configuration for a task.- Parameters:
taskId- the task IDpushNotificationConfig- the push notification configuration- Returns:
- the response indicating whether setting the task push notification configuration succeeded
- Throws:
A2AServerException- if setting the push notification configuration fails for any reason
-
setTaskPushNotificationConfig
public SetTaskPushNotificationConfigResponse setTaskPushNotificationConfig(String requestId, String taskId, PushNotificationConfig pushNotificationConfig) throws A2AServerException Set push notification configuration for a task.- Parameters:
requestId- the request ID to usetaskId- the task IDpushNotificationConfig- the push notification configuration- Returns:
- the response indicating whether setting the task push notification configuration succeeded
- Throws:
A2AServerException- if setting the push notification configuration fails for any reason
-
listTaskPushNotificationConfig
public ListTaskPushNotificationConfigResponse listTaskPushNotificationConfig(String requestId, String taskId) throws A2AServerException Retrieves the push notification configurations for a specified task.- Parameters:
requestId- the request ID to usetaskId- the task ID to use- Returns:
- the response containing the push notification configuration
- Throws:
A2AServerException- if getting the push notification configuration fails for any reason
-
listTaskPushNotificationConfig
public ListTaskPushNotificationConfigResponse listTaskPushNotificationConfig(String taskId) throws A2AServerException Retrieves the push notification configurations for a specified task.- Parameters:
taskId- the task ID to use- Returns:
- the response containing the push notification configuration
- Throws:
A2AServerException- if getting the push notification configuration fails for any reason
-
listTaskPushNotificationConfig
public ListTaskPushNotificationConfigResponse listTaskPushNotificationConfig(ListTaskPushNotificationConfigParams listTaskPushNotificationConfigParams) throws A2AServerException Retrieves the push notification configurations for a specified task.- Parameters:
listTaskPushNotificationConfigParams- the params for retrieving the push notification configuration- Returns:
- the response containing the push notification configuration
- Throws:
A2AServerException- if getting the push notification configuration fails for any reason
-
listTaskPushNotificationConfig
public ListTaskPushNotificationConfigResponse listTaskPushNotificationConfig(String requestId, ListTaskPushNotificationConfigParams listTaskPushNotificationConfigParams) throws A2AServerException Retrieves the push notification configurations for a specified task.- Parameters:
requestId- the request ID to uselistTaskPushNotificationConfigParams- the params for retrieving the push notification configuration- Returns:
- the response containing the push notification configuration
- Throws:
A2AServerException- if getting the push notification configuration fails for any reason
-
deleteTaskPushNotificationConfig
public DeleteTaskPushNotificationConfigResponse deleteTaskPushNotificationConfig(String requestId, String taskId, String pushNotificationConfigId) throws A2AServerException Delete the push notification configuration for a specified task.- Parameters:
requestId- the request ID to usetaskId- the task IDpushNotificationConfigId- the push notification config ID- Returns:
- the response
- Throws:
A2AServerException- if deleting the push notification configuration fails for any reason
-
deleteTaskPushNotificationConfig
public DeleteTaskPushNotificationConfigResponse deleteTaskPushNotificationConfig(String taskId, String pushNotificationConfigId) throws A2AServerException Delete the push notification configuration for a specified task.- Parameters:
taskId- the task IDpushNotificationConfigId- the push notification config ID- Returns:
- the response
- Throws:
A2AServerException- if deleting the push notification configuration fails for any reason
-
deleteTaskPushNotificationConfig
public DeleteTaskPushNotificationConfigResponse deleteTaskPushNotificationConfig(DeleteTaskPushNotificationConfigParams deleteTaskPushNotificationConfigParams) throws A2AServerException Delete the push notification configuration for a specified task.- Parameters:
deleteTaskPushNotificationConfigParams- the params for deleting the push notification configuration- Returns:
- the response
- Throws:
A2AServerException- if deleting the push notification configuration fails for any reason
-
deleteTaskPushNotificationConfig
public DeleteTaskPushNotificationConfigResponse deleteTaskPushNotificationConfig(String requestId, DeleteTaskPushNotificationConfigParams deleteTaskPushNotificationConfigParams) throws A2AServerException Delete the push notification configuration for a specified task.- Parameters:
requestId- the request ID to usedeleteTaskPushNotificationConfigParams- the params for deleting the push notification configuration- Returns:
- the response
- Throws:
A2AServerException- if deleting the push notification configuration fails for any reason
-
sendStreamingMessage
public void sendStreamingMessage(MessageSendParams messageSendParams, Consumer<StreamingEventKind> eventHandler, Consumer<JSONRPCError> errorHandler, Runnable failureHandler) throws A2AServerException Send a streaming message to the remote agent.- Parameters:
messageSendParams- the parameters for the message to be senteventHandler- a consumer that will be invoked for each event received from the remote agenterrorHandler- a consumer that will be invoked if the remote agent returns an errorfailureHandler- a consumer that will be invoked if a failure occurs when processing events- Throws:
A2AServerException- if sending the streaming message fails for any reason
-
sendStreamingMessage
public void sendStreamingMessage(String requestId, MessageSendParams messageSendParams, Consumer<StreamingEventKind> eventHandler, Consumer<JSONRPCError> errorHandler, Runnable failureHandler) throws A2AServerException Send a streaming message to the remote agent.- Parameters:
requestId- the request ID to usemessageSendParams- the parameters for the message to be senteventHandler- a consumer that will be invoked for each event received from the remote agenterrorHandler- a consumer that will be invoked if the remote agent returns an errorfailureHandler- a consumer that will be invoked if a failure occurs when processing events- Throws:
A2AServerException- if sending the streaming message fails for any reason
-
resubscribeToTask
public void resubscribeToTask(TaskIdParams taskIdParams, Consumer<StreamingEventKind> eventHandler, Consumer<JSONRPCError> errorHandler, Runnable failureHandler) throws A2AServerException Resubscribe to an ongoing task.- Parameters:
taskIdParams- the params for the task to resubscribe toeventHandler- a consumer that will be invoked for each event received from the remote agenterrorHandler- a consumer that will be invoked if the remote agent returns an errorfailureHandler- a consumer that will be invoked if a failure occurs when processing events- Throws:
A2AServerException- if resubscribing to the task fails for any reason
-
resubscribeToTask
public void resubscribeToTask(String requestId, TaskIdParams taskIdParams, Consumer<StreamingEventKind> eventHandler, Consumer<JSONRPCError> errorHandler, Runnable failureHandler) throws A2AServerException Resubscribe to an ongoing task.- Parameters:
requestId- the request ID to usetaskIdParams- the params for the task to resubscribe toeventHandler- a consumer that will be invoked for each event received from the remote agenterrorHandler- a consumer that will be invoked if the remote agent returns an errorfailureHandler- a consumer that will be invoked if a failure occurs when processing events- Throws:
A2AServerException- if resubscribing to the task fails for any reason
-