Package io.a2a.client

Class A2AClient

java.lang.Object
io.a2a.client.A2AClient

public class A2AClient extends Object
An A2A client.
  • Constructor Details

    • A2AClient

      public A2AClient(AgentCard agentCard)
      Create a new A2AClient.
      Parameters:
      agentCard - the agent card for the A2A server this client will be communicating with
    • A2AClient

      public A2AClient(String agentUrl)
      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 - the A2AHttpClient to use
      baseUrl - the base URL of the agent's host
      agentCardPath - the path to the agent card endpoint, relative to the baseUrl. If null, the value A2ACardResolver.DEFAULT_AGENT_CARD_PATH will be used
      Returns:
      an initialised A2AClient instance
      Throws:
      A2AClientError - If an HTTP error occurs fetching the card
      A2AClientJSONError - if the agent card response is invalid
    • getAgentCard

      public AgentCard getAgentCard() throws A2AClientError, A2AClientJSONError
      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 card
      A2AClientJSONError - 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, A2AClientJSONError
      Get 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 server
      authHeaders - the HTTP authentication headers to use
      Returns:
      the agent card for the A2A server
      Throws:
      A2AClientError - If an HTTP error occurs fetching the card
      A2AClientJSONError - 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 use
      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
    • getTask

      public GetTaskResponse getTask(String id) throws A2AServerException
      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

      public GetTaskResponse getTask(TaskQueryParams taskQueryParams) throws A2AServerException
      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 use
      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
    • cancelTask

      public CancelTaskResponse cancelTask(String id) throws A2AServerException
      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

      public CancelTaskResponse cancelTask(TaskIdParams taskIdParams) throws A2AServerException
      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 use
      taskIdParams - 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 ID
      pushNotificationConfigId - 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 use
      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
    • setTaskPushNotificationConfig

      public SetTaskPushNotificationConfigResponse setTaskPushNotificationConfig(String taskId, PushNotificationConfig pushNotificationConfig) throws A2AServerException
      Set push notification configuration for a task.
      Parameters:
      taskId - the task ID
      pushNotificationConfig - 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 use
      taskId - the task ID
      pushNotificationConfig - 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 use
      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(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 use
      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
    • 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 use
      taskId - the task ID
      pushNotificationConfigId - 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 ID
      pushNotificationConfigId - 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 use
      deleteTaskPushNotificationConfigParams - 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 sent
      eventHandler - a consumer that will be invoked for each event received from the remote agent
      errorHandler - a consumer that will be invoked if the remote agent returns an error
      failureHandler - 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 use
      messageSendParams - the parameters for the message to be sent
      eventHandler - a consumer that will be invoked for each event received from the remote agent
      errorHandler - a consumer that will be invoked if the remote agent returns an error
      failureHandler - 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 to
      eventHandler - a consumer that will be invoked for each event received from the remote agent
      errorHandler - a consumer that will be invoked if the remote agent returns an error
      failureHandler - 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 use
      taskIdParams - the params for the task to resubscribe to
      eventHandler - a consumer that will be invoked for each event received from the remote agent
      errorHandler - a consumer that will be invoked if the remote agent returns an error
      failureHandler - a consumer that will be invoked if a failure occurs when processing events
      Throws:
      A2AServerException - if resubscribing to the task fails for any reason