@@ -139,18 +139,6 @@ public class WeatherAgentExecutorProducer {
139139 updater. complete();
140140 }
141141
142- private String extractTextFromMessage (Message message ) {
143- StringBuilder textBuilder = new StringBuilder ();
144- if (message. getParts() != null ) {
145- for (Part part : message. getParts()) {
146- if (part instanceof TextPart textPart) {
147- textBuilder. append(textPart. getText());
148- }
149- }
150- }
151- return textBuilder. toString();
152- }
153-
154142 @Override
155143 public void cancel (RequestContext context , EventQueue eventQueue ) throws JSONRPCError {
156144 Task task = context. getTask();
@@ -169,6 +157,18 @@ public class WeatherAgentExecutorProducer {
169157 TaskUpdater updater = new TaskUpdater (context, eventQueue);
170158 updater. cancel();
171159 }
160+
161+ private String extractTextFromMessage (Message message ) {
162+ StringBuilder textBuilder = new StringBuilder ();
163+ if (message. getParts() != null ) {
164+ for (Part part : message. getParts()) {
165+ if (part instanceof TextPart textPart) {
166+ textBuilder. append(textPart. getText());
167+ }
168+ }
169+ }
170+ return textBuilder. toString();
171+ }
172172 }
173173}
174174```
202202</dependency >
203203```
204204
205- ## Client
205+ ## A2A Client
206206
207- An * initial * [ A2AClient ] ( https://github.com/fjuma/a2a-java-sdk/blob/main/src/main/java/ io/a2a/client/A2AClient.java ) class has been added. This is very much work in progress, we are working on implementing the methods required by the client side of the protocol .
207+ The A2A Java SDK provides a Java client implementation of the [ Agent2Agent (A2A) Protocol ] ( https://google-a2a. github.io/A2A ) , allowing communication with A2A servers .
208208
209209### Sample Usage
210210
211- #### Create a client
211+ #### Create an A2A client
212212
213213``` java
214- // Create an A2AClient (the URL specified is the server agent's URL)
214+ // Create an A2AClient (the URL specified is the server agent's URL, be sure to replace it with the actual URL of the A2A server you want to connect to )
215215A2AClient client = new A2AClient (" http://localhost:1234" );
216216```
217217
218- #### Send a message
218+ #### Send a message to the A2A server agent
219219
220220``` java
221- // Send a text message to the server agent
221+ // Send a text message to the A2A server agent
222222Message message = A2A . toUserMessage(" tell me a joke" ); // the message ID will be automatically generated for you
223223MessageSendParams params = new MessageSendParams .Builder ()
224- .id(" task-1234" ) // id is optional
225224 .message(message)
226225 .build();
227226SendMessageResponse response = client. sendMessage(params);
@@ -234,7 +233,7 @@ if you don't specify it. You can also explicitly specify a message ID like this:
234233Message message = A2A . toUserMessage(" tell me a joke" , " message-1234" ); // messageId is message-1234
235234```
236235
237- #### Get a task
236+ #### Get the current state of a task
238237
239238``` java
240239// Retrieve the task with id "task-1234"
@@ -245,7 +244,7 @@ GetTaskResponse response = client.getTask("task-1234");
245244GetTaskResponse response = client. getTask(new TaskQueryParams (" task-1234" , 10 ));
246245```
247246
248- #### Cancel a task
247+ #### Cancel an ongoing task
249248
250249``` java
251250// Cancel the task we previously submitted with id "task-1234"
@@ -259,12 +258,12 @@ CancelTaskResponse response = client.cancelTask(new TaskIdParams("task-1234", me
259258#### Get the push notification configuration for a task
260259
261260``` java
262- // Get task push notification
263- GetTaskPushNotificationResponse response = client. getTaskPushNotificationConfig(" task-1234" );
261+ // Get task push notification configuration
262+ GetTaskPushNotificationConfigResponse response = client. getTaskPushNotificationConfig(" task-1234" );
264263
265264// You can also specify additional properties using a map
266265Map<String , Object > metadata = ...
267- GetTaskPushNotificationResponse response = client. getTaskPushNotificationConfig(new TaskIdParams (" task-1234" , metadata));
266+ GetTaskPushNotificationConfigResponse response = client. getTaskPushNotificationConfig(new TaskIdParams (" task-1234" , metadata));
268267```
269268
270269#### Set the push notification configuration for a task
@@ -274,7 +273,7 @@ GetTaskPushNotificationResponse response = client.getTaskPushNotificationConfig(
274273PushNotificationConfig pushNotificationConfig = new PushNotificationConfig .Builder ()
275274 .url(" https://example.com/callback" )
276275 .authenticationInfo(new AuthenticationInfo (Collections . singletonList(" jwt" ), null ))
277- .build()) ;
276+ .build();
278277SetTaskPushNotificationResponse response = client. setTaskPushNotificationConfig(" task-1234" , pushNotificationConfig);
279278```
280279
@@ -284,12 +283,11 @@ SetTaskPushNotificationResponse response = client.setTaskPushNotificationConfig(
284283// Send a text message to the remote agent
285284Message message = A2A . toUserMessage(" tell me some jokes" ); // the message ID will be automatically generated for you
286285MessageSendParams params = new MessageSendParams .Builder ()
287- .id(" task-1234" ) // id is optional
288286 .message(message)
289287 .build();
290288
291289// Create a handler that will be invoked for Task, Message, TaskStatusUpdateEvent, and TaskArtifactUpdateEvent
292- Consumer<StreamingEventType > eventHandler = event - > {... };
290+ Consumer<StreamingEventKind > eventHandler = event - > {... };
293291
294292// Create a handler that will be invoked if an error is received
295293Consumer<JSONRPCError > errorHandler = error - > {... };
@@ -301,6 +299,23 @@ Runnable failureHandler = () -> {...};
301299client. sendStreamingMessage(params, eventHandler, errorHandler, failureHandler);
302300```
303301
302+ #### Resubscribe to a task
303+
304+ ``` java
305+ // Create a handler that will be invoked for Task, Message, TaskStatusUpdateEvent, and TaskArtifactUpdateEvent
306+ Consumer<StreamingEventKind > eventHandler = event - > {... };
307+
308+ // Create a handler that will be invoked if an error is received
309+ Consumer<JSONRPCError > errorHandler = error - > {... };
310+
311+ // Create a handler that will be invoked in the event of a failure
312+ Runnable failureHandler = () - > {... };
313+
314+ // Resubscribe to an ongoing task with id "task-1234"
315+ TaskIdParams taskIdParams = new TaskIdParams (" task-1234" );
316+ client. resubscribeToTask(" request-1234" , taskIdParams, eventHandler, errorHandler, failureHandler);
317+ ```
318+
304319#### Retrieve details about the server agent that this client agent is communicating with
305320``` java
306321AgentCard serverAgentCard = client. getAgentCard();
@@ -312,7 +327,7 @@ An agent card can also be retrieved using the `A2A#getAgentCard` method:
312327AgentCard agentCard = A2A . getAgentCard(" http://localhost:1234" );
313328```
314329
315- ## Examples
330+ ## Additional Examples
316331
317332### Hello World Example
318333
@@ -324,9 +339,13 @@ A complete example of an A2A client communicating with a Python A2A server is av
324339
325340The example includes detailed instructions on how to run both the Python server and the Java client using JBang. Check out the [ example's README] ( src/main/java/io/a2a/examples/helloworld/README.md ) for more information.
326341
327- ## Server
342+ ## License
343+
344+ This project is licensed under the terms of the [ Apache 2.0 License] ( LICENSE ) .
345+
346+ ## Contributing
328347
329- TODO
348+ See [ CONTRIBUTING.md ] ( CONTRIBUTING.md ) for contribution guidelines.
330349
331350
332351
0 commit comments