Package org.a2aproject.sdk.client
Class AbstractClient
java.lang.Object
org.a2aproject.sdk.client.AbstractClient
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
Client
Abstract class representing an A2A client. Provides a standard set
of methods for interacting with an A2A agent, regardless of the underlying
transport protocol. It supports sending messages, managing tasks, and
handling event streams.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final @NonNull List<BiConsumer<ClientEvent,AgentCard>> -
Constructor Summary
ConstructorsConstructorDescriptionAbstractClient(@NonNull List<BiConsumer<ClientEvent, AgentCard>> consumers) AbstractClient(@NonNull List<BiConsumer<ClientEvent, AgentCard>> consumers, @Nullable Consumer<Throwable> streamingErrorHandler) -
Method Summary
Modifier and TypeMethodDescriptioncancelTask(CancelTaskParams request) Request the agent to cancel a specific task.abstract TaskcancelTask(CancelTaskParams request, @Nullable ClientCallContext context) Request the agent to cancel a specific task.abstract voidclose()Close the transport and release any associated resources.Create or update the push notification configuration for a specific task.abstract TaskPushNotificationConfigcreateTaskPushNotificationConfiguration(TaskPushNotificationConfig request, @Nullable ClientCallContext context) Create or update the push notification configuration for a specific task.voidDelete the list of push notification configurations for a specific task.abstract voiddeleteTaskPushNotificationConfigurations(DeleteTaskPushNotificationConfigParams request, @Nullable ClientCallContext context) Delete the list of push notification configurations for a specific task.Retrieve the extended AgentCard.getExtendedAgentCard(@Nullable String tenant) Retrieve the extended AgentCard.abstract AgentCardgetExtendedAgentCard(@Nullable String tenant, @Nullable ClientCallContext context) Retrieve the extended AgentCard.getExtendedAgentCard(@Nullable ClientCallContext context) Retrieve the extended AgentCard.Get the error handler that should be used during streaming.getTask(TaskQueryParams request) Retrieve the current state and history of a specific task.abstract TaskgetTask(TaskQueryParams request, @Nullable ClientCallContext context) Retrieve the current state and history of a specific task.Retrieve the push notification configuration for a specific task.abstract TaskPushNotificationConfiggetTaskPushNotificationConfiguration(GetTaskPushNotificationConfigParams request, @Nullable ClientCallContext context) Retrieve the push notification configuration for a specific task.Retrieve the list of push notification configurations for a specific task with pagination support.listTaskPushNotificationConfigurations(ListTaskPushNotificationConfigsParams request, @Nullable ClientCallContext context) Retrieve the list of push notification configurations for a specific task with pagination support.listTasks(ListTasksParams request) List tasks with optional filtering and pagination.abstract ListTasksResultlistTasks(ListTasksParams request, @Nullable ClientCallContext context) List tasks with optional filtering and pagination.voidsendMessage(@NonNull Message request) Send a message to the remote agent.voidsendMessage(@NonNull Message request, @NonNull List<BiConsumer<ClientEvent, AgentCard>> consumers, @Nullable Consumer<Throwable> streamingErrorHandler) Send a message to the remote agent.abstract voidsendMessage(@NonNull Message request, @NonNull List<BiConsumer<ClientEvent, AgentCard>> consumers, @Nullable Consumer<Throwable> streamingErrorHandler, @Nullable ClientCallContext context) Send a message to the remote agent.voidsendMessage(@NonNull Message request, @Nullable ClientCallContext context) Send a message to the remote agent.voidsendMessage(@NonNull Message request, @Nullable TaskPushNotificationConfig pushNotificationConfiguration, @Nullable Map<String, Object> metadata) Send a message to the remote agent.abstract voidsendMessage(@NonNull Message request, @Nullable TaskPushNotificationConfig pushNotificationConfiguration, @Nullable Map<String, Object> metadata, @Nullable ClientCallContext context) Send a message to the remote agent.abstract voidsendMessage(@NonNull MessageSendParams params, @NonNull List<BiConsumer<ClientEvent, AgentCard>> consumers, @Nullable Consumer<Throwable> streamingErrorHandler, @Nullable ClientCallContext context) Send a message to the remote agent.voidsubscribeToTask(@NonNull TaskIdParams request) Subscribe to a task's event stream.voidsubscribeToTask(@NonNull TaskIdParams request, @NonNull List<BiConsumer<ClientEvent, AgentCard>> consumers, @Nullable Consumer<Throwable> streamingErrorHandler) Subscribe to a task's event stream.abstract voidsubscribeToTask(@NonNull TaskIdParams request, @NonNull List<BiConsumer<ClientEvent, AgentCard>> consumers, @Nullable Consumer<Throwable> streamingErrorHandler, @Nullable ClientCallContext context) Subscribe to a task's event stream.voidsubscribeToTask(@NonNull TaskIdParams request, @Nullable ClientCallContext context) Subscribe to a task's event stream.
-
Field Details
-
consumers
-
streamingErrorHandler
-
-
Constructor Details
-
AbstractClient
-
AbstractClient
public AbstractClient(@NonNull List<BiConsumer<ClientEvent, AgentCard>> consumers, @Nullable Consumer<Throwable> streamingErrorHandler)
-
-
Method Details
-
sendMessage
Send a message to the remote agent. This method will automatically use the streaming or non-streaming approach as determined by the server's agent card and the client configuration. The configured client consumers will be used to handle messages, tasks, and update events received from the remote agent. The configured streaming error handler will be used if an error occurs during streaming. The configured client push notification configuration will get used for streaming.- Parameters:
request- the message- Throws:
A2AClientException- if sending the message fails for any reason
-
sendMessage
public void sendMessage(@NonNull Message request, @Nullable ClientCallContext context) throws A2AClientException Send a message to the remote agent. This method will automatically use the streaming or non-streaming approach as determined by the server's agent card and the client configuration. The configured client consumers will be used to handle messages, tasks, and update events received from the remote agent. The configured streaming error handler will be used if an error occurs during streaming. The configured client push notification configuration will get used for streaming.- Parameters:
request- the messagecontext- optional client call context for the request- Throws:
A2AClientException- if sending the message fails for any reason
-
sendMessage
public void sendMessage(@NonNull Message request, @NonNull List<BiConsumer<ClientEvent, AgentCard>> consumers, @Nullable Consumer<Throwable> streamingErrorHandler) throws A2AClientExceptionSend a message to the remote agent. This method will automatically use the streaming or non-streaming approach as determined by the server's agent card and the client configuration. The specified client consumers will be used to handle messages, tasks, and update events received from the remote agent. The specified streaming error handler will be used if an error occurs during streaming. The configured client push notification configuration will get used for streaming.- Parameters:
request- the messageconsumers- a list of consumers to pass responses from the remote agent tostreamingErrorHandler- an error handler that should be used for the streaming case if an error occurs- Throws:
A2AClientException- if sending the message fails for any reason
-
sendMessage
public abstract void sendMessage(@NonNull Message request, @NonNull List<BiConsumer<ClientEvent, AgentCard>> consumers, @Nullable Consumer<Throwable> streamingErrorHandler, @Nullable ClientCallContext context) throws A2AClientExceptionSend a message to the remote agent. This method will automatically use the streaming or non-streaming approach as determined by the server's agent card and the client configuration. The specified client consumers will be used to handle messages, tasks, and update events received from the remote agent. The specified streaming error handler will be used if an error occurs during streaming. The configured client push notification configuration will get used for streaming.- Parameters:
request- the messageconsumers- a list of consumers to pass responses from the remote agent tostreamingErrorHandler- an error handler that should be used for the streaming case if an error occurscontext- optional client call context for the request- Throws:
A2AClientException- if sending the message fails for any reason
-
sendMessage
public void sendMessage(@NonNull Message request, @Nullable TaskPushNotificationConfig pushNotificationConfiguration, @Nullable Map<String, Object> metadata) throws A2AClientExceptionSend a message to the remote agent. This method will automatically use the streaming or non-streaming approach as determined by the server's agent card and the client configuration. The configured client consumers will be used to handle messages, tasks, and update events received from the remote agent. The configured streaming error handler will be used if an error occurs during streaming.- Parameters:
request- the messagepushNotificationConfiguration- the push notification configuration that should be used if the streaming approach is usedmetadata- the optional metadata to include when sending the message- Throws:
A2AClientException- if sending the message fails for any reason
-
sendMessage
public abstract void sendMessage(@NonNull Message request, @Nullable TaskPushNotificationConfig pushNotificationConfiguration, @Nullable Map<String, Object> metadata, @Nullable ClientCallContext context) throws A2AClientExceptionSend a message to the remote agent. This method will automatically use the streaming or non-streaming approach as determined by the server's agent card and the client configuration. The configured client consumers will be used to handle messages, tasks, and update events received from the remote agent. The configured streaming error handler will be used if an error occurs during streaming.- Parameters:
request- the messagepushNotificationConfiguration- the push notification configuration that should be used if the streaming approach is usedmetadata- the optional metadata to include when sending the messagecontext- optional client call context for the request- Throws:
A2AClientException- if sending the message fails for any reason
-
sendMessage
public abstract void sendMessage(@NonNull MessageSendParams params, @NonNull List<BiConsumer<ClientEvent, AgentCard>> consumers, @Nullable Consumer<Throwable> streamingErrorHandler, @Nullable ClientCallContext context) throws A2AClientExceptionSend a message to the remote agent. This method will automatically use the streaming or non-streaming approach as determined by the server's agent card and the client configuration. The specified client consumers will be used to handle messages, tasks, and update events received from the remote agent. The specified streaming error handler will be used if an error occurs during streaming. The configured client push notification configuration will get used for streaming.- Parameters:
params- the request parametersconsumers- a list of consumers to pass responses from the remote agent tostreamingErrorHandler- an error handler that should be used for the streaming case if an error occurscontext- optional client call context for the request- Throws:
A2AClientException- if sending the message fails for any reason
-
getTask
Retrieve the current state and history of a specific task.- Parameters:
request- the task query parameters specifying which task to retrieve- Returns:
- the task
- Throws:
A2AClientException- if retrieving the task fails for any reason
-
getTask
public abstract Task getTask(TaskQueryParams request, @Nullable ClientCallContext context) throws A2AClientException Retrieve the current state and history of a specific task.- Parameters:
request- the task query parameters specifying which task to retrievecontext- optional client call context for the request (may benull)- Returns:
- the task
- Throws:
A2AClientException- if retrieving the task fails for any reason
-
listTasks
List tasks with optional filtering and pagination.- Parameters:
request- the list tasks parameters including filters and pagination- Returns:
- the list tasks result containing tasks and pagination information
- Throws:
A2AClientException- if listing tasks fails for any reason
-
listTasks
public abstract ListTasksResult listTasks(ListTasksParams request, @Nullable ClientCallContext context) throws A2AClientException List tasks with optional filtering and pagination.- Parameters:
request- the list tasks parameters including filters and paginationcontext- optional client call context for the request (may benull)- Returns:
- the list tasks result containing tasks and pagination information
- Throws:
A2AClientException- if listing tasks fails for any reason
-
cancelTask
Request the agent to cancel a specific task.- Parameters:
request- the task ID parameters specifying which task to cancel- Returns:
- the cancelled task
- Throws:
A2AClientException- if cancelling the task fails for any reason
-
cancelTask
public abstract Task cancelTask(CancelTaskParams request, @Nullable ClientCallContext context) throws A2AClientException Request the agent to cancel a specific task.- Parameters:
request- the task ID parameters specifying which task to cancelcontext- optional client call context for the request (may benull)- Returns:
- the cancelled task
- Throws:
A2AClientException- if cancelling the task fails for any reason
-
createTaskPushNotificationConfiguration
public TaskPushNotificationConfig createTaskPushNotificationConfiguration(TaskPushNotificationConfig request) throws A2AClientException Create or update the push notification configuration for a specific task.- Parameters:
request- the push notification configuration to set for the task- Returns:
- the configured TaskPushNotificationConfig
- Throws:
A2AClientException- if setting the task push notification configuration fails for any reason
-
createTaskPushNotificationConfiguration
public abstract TaskPushNotificationConfig createTaskPushNotificationConfiguration(TaskPushNotificationConfig request, @Nullable ClientCallContext context) throws A2AClientException Create or update the push notification configuration for a specific task.- Parameters:
request- the push notification configuration to set for the taskcontext- optional client call context for the request (may benull)- Returns:
- the configured TaskPushNotificationConfig
- Throws:
A2AClientException- if setting the task push notification configuration fails for any reason
-
getTaskPushNotificationConfiguration
public TaskPushNotificationConfig getTaskPushNotificationConfiguration(GetTaskPushNotificationConfigParams request) throws A2AClientException Retrieve the push notification configuration for a specific task.- Parameters:
request- the parameters specifying which task's notification config to retrieve- Returns:
- the task push notification config
- Throws:
A2AClientException- if getting the task push notification config fails for any reason
-
getTaskPushNotificationConfiguration
public abstract TaskPushNotificationConfig getTaskPushNotificationConfiguration(GetTaskPushNotificationConfigParams request, @Nullable ClientCallContext context) throws A2AClientException Retrieve the push notification configuration for a specific task.- Parameters:
request- the parameters specifying which task's notification config to retrievecontext- optional client call context for the request (may benull)- Returns:
- the task push notification config
- Throws:
A2AClientException- if getting the task push notification config fails for any reason
-
listTaskPushNotificationConfigurations
public ListTaskPushNotificationConfigsResult listTaskPushNotificationConfigurations(ListTaskPushNotificationConfigsParams request) throws A2AClientException Retrieve the list of push notification configurations for a specific task with pagination support.- Parameters:
request- the parameters specifying which task's notification configs to retrieve- Returns:
- the result containing the list of task push notification configs and pagination information
- Throws:
A2AClientException- if getting the task push notification configs fails for any reason
-
listTaskPushNotificationConfigurations
public abstract ListTaskPushNotificationConfigsResult listTaskPushNotificationConfigurations(ListTaskPushNotificationConfigsParams request, @Nullable ClientCallContext context) throws A2AClientException Retrieve the list of push notification configurations for a specific task with pagination support.- Parameters:
request- the parameters specifying which task's notification configs to retrievecontext- optional client call context for the request (may benull)- Returns:
- the result containing the list of task push notification configs and pagination information
- Throws:
A2AClientException- if getting the task push notification configs fails for any reason
-
deleteTaskPushNotificationConfigurations
public void deleteTaskPushNotificationConfigurations(DeleteTaskPushNotificationConfigParams request) throws A2AClientException Delete the list of push notification configurations for a specific task.- Parameters:
request- the parameters specifying which task's notification configs to delete- Throws:
A2AClientException- if deleting the task push notification configs fails for any reason
-
deleteTaskPushNotificationConfigurations
public abstract void deleteTaskPushNotificationConfigurations(DeleteTaskPushNotificationConfigParams request, @Nullable ClientCallContext context) throws A2AClientException Delete the list of push notification configurations for a specific task.- Parameters:
request- the parameters specifying which task's notification configs to deletecontext- optional client call context for the request (may benull)- Throws:
A2AClientException- if deleting the task push notification configs fails for any reason
-
subscribeToTask
Subscribe to a task's event stream. This is only available if both the client and server support streaming. The configured client consumers will be used to handle messages, tasks, and update events received from the remote agent. The configured streaming error handler will be used if an error occurs during streaming.- Parameters:
request- the parameters specifying which task's notification configs to delete- Throws:
A2AClientException- if resubscribing fails for any reason
-
subscribeToTask
public void subscribeToTask(@NonNull TaskIdParams request, @Nullable ClientCallContext context) throws A2AClientException Subscribe to a task's event stream. This is only available if both the client and server support streaming. The configured client consumers will be used to handle messages, tasks, and update events received from the remote agent. The configured streaming error handler will be used if an error occurs during streaming.- Parameters:
request- the parameters specifying which task's notification configs to deletecontext- optional client call context for the request- Throws:
A2AClientException- if resubscribing fails for any reason
-
subscribeToTask
public void subscribeToTask(@NonNull TaskIdParams request, @NonNull List<BiConsumer<ClientEvent, AgentCard>> consumers, @Nullable Consumer<Throwable> streamingErrorHandler) throws A2AClientExceptionSubscribe to a task's event stream. This is only available if both the client and server support streaming. The specified client consumers will be used to handle messages, tasks, and update events received from the remote agent. The specified streaming error handler will be used if an error occurs during streaming.- Parameters:
request- the parameters specifying which task's notification configs to deleteconsumers- a list of consumers to pass responses from the remote agent tostreamingErrorHandler- an error handler that should be used for the streaming case if an error occurs- Throws:
A2AClientException- if resubscribing fails for any reason
-
subscribeToTask
public abstract void subscribeToTask(@NonNull TaskIdParams request, @NonNull List<BiConsumer<ClientEvent, AgentCard>> consumers, @Nullable Consumer<Throwable> streamingErrorHandler, @Nullable ClientCallContext context) throws A2AClientExceptionSubscribe to a task's event stream. This is only available if both the client and server support streaming. The specified client consumers will be used to handle messages, tasks, and update events received from the remote agent. The specified streaming error handler will be used if an error occurs during streaming.- Parameters:
request- the parameters specifying which task's notification configs to deleteconsumers- a list of consumers to pass responses from the remote agent tostreamingErrorHandler- an error handler that should be used for the streaming case if an error occurscontext- optional client call context for the request- Throws:
A2AClientException- if resubscribing fails for any reason
-
getExtendedAgentCard
Retrieve the extended AgentCard.- Returns:
- the extended AgentCard
- Throws:
A2AClientException- if retrieving the extended agent card fails for any reason
-
getExtendedAgentCard
Retrieve the extended AgentCard.- Parameters:
tenant- Optional tenant- Returns:
- the extended AgentCard
- Throws:
A2AClientException- if retrieving the extended agent card fails for any reason
-
getExtendedAgentCard
public AgentCard getExtendedAgentCard(@Nullable ClientCallContext context) throws A2AClientException Retrieve the extended AgentCard.- Parameters:
context- optional client call context for the request (may benull)- Returns:
- the extended AgentCard
- Throws:
A2AClientException- if retrieving the extended agent card fails for any reason
-
getExtendedAgentCard
public abstract AgentCard getExtendedAgentCard(@Nullable String tenant, @Nullable ClientCallContext context) throws A2AClientException Retrieve the extended AgentCard.- Parameters:
tenant- Optional tenantcontext- optional client call context for the request (may benull)- Returns:
- the extended AgentCard
- Throws:
A2AClientException- if retrieving the extended agent card fails for any reason
-
close
public abstract void close()Close the transport and release any associated resources.- Specified by:
closein interfaceAutoCloseable
-
getStreamingErrorHandler
Get the error handler that should be used during streaming.- Returns:
- the streaming error handler
-