Skip to content

Commit 1e35b62

Browse files
committed
Update client docs in README
1 parent 80cb1ea commit 1e35b62

File tree

3 files changed

+45
-31
lines changed

3 files changed

+45
-31
lines changed

README.md

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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
```
@@ -202,26 +202,25 @@ OR
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)
215215
A2AClient 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
222222
Message message = A2A.toUserMessage("tell me a joke"); // the message ID will be automatically generated for you
223223
MessageSendParams params = new MessageSendParams.Builder()
224-
.id("task-1234") // id is optional
225224
.message(message)
226225
.build();
227226
SendMessageResponse response = client.sendMessage(params);
@@ -234,7 +233,7 @@ if you don't specify it. You can also explicitly specify a message ID like this:
234233
Message 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");
245244
GetTaskResponse 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
266265
Map<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(
274273
PushNotificationConfig pushNotificationConfig = new PushNotificationConfig.Builder()
275274
.url("https://example.com/callback")
276275
.authenticationInfo(new AuthenticationInfo(Collections.singletonList("jwt"), null))
277-
.build());
276+
.build();
278277
SetTaskPushNotificationResponse 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
285284
Message message = A2A.toUserMessage("tell me some jokes"); // the message ID will be automatically generated for you
286285
MessageSendParams 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
295293
Consumer<JSONRPCError> errorHandler = error -> {...};
@@ -312,7 +310,7 @@ An agent card can also be retrieved using the `A2A#getAgentCard` method:
312310
AgentCard agentCard = A2A.getAgentCard("http://localhost:1234");
313311
```
314312

315-
## Examples
313+
## Additional Examples
316314

317315
### Hello World Example
318316

@@ -324,9 +322,6 @@ A complete example of an A2A client communicating with a Python A2A server is av
324322

325323
The 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.
326324

327-
## Server
328-
329-
TODO
330325

331326

332327

core/src/main/java/io/a2a/client/A2AClient.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,20 @@ public SetTaskPushNotificationConfigResponse setTaskPushNotificationConfig(Strin
347347
}
348348
}
349349

350+
/**
351+
* Send a streaming message to the remote agent.
352+
*
353+
* @param messageSendParams the parameters for the message to be sent
354+
* @param eventHandler a consumer that will be invoked for each event received from the remote agent
355+
* @param errorHandler a consumer that will be invoked if the remote agent returns an error
356+
* @param failureHandler a consumer that will be invoked if a failure occurs when processing events
357+
* @throws A2AServerException if sending the streaming message fails for any reason
358+
*/
359+
public void sendStreamingMessage(MessageSendParams messageSendParams, Consumer<StreamingEventKind> eventHandler,
360+
Consumer<JSONRPCError> errorHandler, Runnable failureHandler) throws A2AServerException {
361+
sendStreamingMessage(null, messageSendParams, eventHandler, errorHandler, failureHandler);
362+
}
363+
350364
/**
351365
* Send a streaming message to the remote agent.
352366
*

core/src/main/java/io/a2a/spec/SendStreamingMessageRequest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import static io.a2a.spec.A2A.SEND_STREAMING_MESSAGE_METHOD;
55
import static io.a2a.util.Utils.defaultIfNull;
66

7+
import java.util.UUID;
8+
79
import com.fasterxml.jackson.annotation.JsonCreator;
810
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
911
import com.fasterxml.jackson.annotation.JsonInclude;
@@ -67,6 +69,9 @@ public Builder params(MessageSendParams params) {
6769
}
6870

6971
public SendStreamingMessageRequest build() {
72+
if (id == null) {
73+
id = UUID.randomUUID().toString();
74+
}
7075
return new SendStreamingMessageRequest(jsonrpc, id, method, params);
7176
}
7277
}

0 commit comments

Comments
 (0)