Skip to content

Commit af34181

Browse files
authored
chore: Update Example to print the actual response returned from Agent (#203)
# Description The current helloworld example only ends up printing `Response: io.a2a.spec.SendMessageResponse@63252cf7` when it does `System.out.println("Response: " + response.toString());`. I expect the actual intent to be to print the response message sent by the Agent which is what this update does. Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [X] Follow the [`CONTRIBUTING` Guide](../CONTRIBUTING.md). - [X] Make your Pull Request title in the <https://www.conventionalcommits.org/> specification. - Important Prefixes for [release-please](https://github.com/googleapis/release-please): - `fix:` which represents bug fixes, and correlates to a [SemVer](https://semver.org/) patch. - `feat:` represents a new feature, and correlates to a SemVer minor. - `feat!:`, or `fix!:`, `refactor!:`, etc., which represent a breaking change (indicated by the `!`) and will result in a SemVer major. - [X] Ensure the tests pass - [X] Appropriate READMEs were updated (if necessary) - The current helloworld example READMEs (client and server) seem to need work beyond this minor update. Happy to handle that under another Issue/PR if strategic and helpful. Fixes #<issue_number_goes_here> 🦕
1 parent 4b11c00 commit af34181

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

examples/helloworld/client/src/main/java/io/a2a/examples/helloworld/HelloWorldClient.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
import io.a2a.client.A2AClient;
88
import io.a2a.A2A;
99
import io.a2a.spec.AgentCard;
10+
import io.a2a.spec.EventKind;
1011
import io.a2a.spec.Message;
1112
import io.a2a.spec.MessageSendParams;
1213
import io.a2a.spec.SendMessageResponse;
14+
import io.a2a.spec.Part;
15+
import io.a2a.spec.TextPart;
1316

1417
/**
1518
* A simple example of using the A2A Java SDK to communicate with an A2A server.
@@ -50,7 +53,19 @@ public static void main(String[] args) {
5053
.build();
5154
SendMessageResponse response = client.sendMessage(params);
5255
System.out.println("Message sent with ID: " + response.getId());
53-
System.out.println("Response: " + response.toString());
56+
57+
EventKind result = response.getResult();
58+
if (result instanceof Message responseMessage) {
59+
StringBuilder textBuilder = new StringBuilder();
60+
if (responseMessage.getParts() != null) {
61+
for (Part<?> part : responseMessage.getParts()) {
62+
if (part instanceof TextPart textPart) {
63+
textBuilder.append(textPart.getText());
64+
}
65+
}
66+
}
67+
System.out.println("Response: " + textBuilder.toString());
68+
}
5469
} catch (Exception e) {
5570
System.err.println("An error occurred: " + e.getMessage());
5671
e.printStackTrace();

0 commit comments

Comments
 (0)