Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
import io.a2a.client.A2AClient;
import io.a2a.A2A;
import io.a2a.spec.AgentCard;
import io.a2a.spec.EventKind;
import io.a2a.spec.Message;
import io.a2a.spec.MessageSendParams;
import io.a2a.spec.SendMessageResponse;
import io.a2a.spec.Part;
import io.a2a.spec.TextPart;

/**
* A simple example of using the A2A Java SDK to communicate with an A2A server.
Expand Down Expand Up @@ -50,7 +53,19 @@ public static void main(String[] args) {
.build();
SendMessageResponse response = client.sendMessage(params);
System.out.println("Message sent with ID: " + response.getId());
System.out.println("Response: " + response.toString());

EventKind result = response.getResult();
if (result instanceof Message responseMessage) {
StringBuilder textBuilder = new StringBuilder();
if (responseMessage.getParts() != null) {
for (Part<?> part : responseMessage.getParts()) {
if (part instanceof TextPart textPart) {
textBuilder.append(textPart.getText());
}
}
}
System.out.println("Response: " + textBuilder.toString());
}
} catch (Exception e) {
System.err.println("An error occurred: " + e.getMessage());
e.printStackTrace();
Expand Down