Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions examples/helloworld/client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ jbang examples/helloworld/client/src/main/java/org/a2aproject/sdk/examples/hello
The Java client (`HelloWorldClient.java`) performs the following actions:

1. Fetches the server's public agent card
2. Fetches the server's extended agent card
3. Creates a client using the extended agent card that connects to the Python server at `http://localhost:9999`.
2. Creates a client from it that connects to the Python server at `http://localhost:9999`.
3. Fetches the server's extended agent card through the client, if the public card advertises one. The client uses it from then on.
4. Sends a regular message asking "how much is 10 USD in INR?".
5. Prints the server's response.
6. Sends the same message as a streaming request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,6 @@ public static void main(String[] args) {
AgentCard publicAgentCard = A2ACardResolver.builder().baseUrl(SERVER_URL).build().getAgentCard();
System.out.println("Successfully fetched public agent card:");
System.out.println(JsonUtil.toJson(publicAgentCard));
System.out.println("Using public agent card for client initialization (default).");
AgentCard finalAgentCard = publicAgentCard;

if (publicAgentCard.capabilities().extendedAgentCard()) {
System.out.println("Public card supports authenticated extended card. Attempting to fetch from: " + SERVER_URL + "/ExtendedAgentCard");
Map<String, String> authHeaders = new HashMap<>();
authHeaders.put("Authorization", "Bearer dummy-token-for-extended-card");
AgentCard extendedAgentCard = A2A.getAgentCard(SERVER_URL, "/ExtendedAgentCard", authHeaders);
System.out.println("Successfully fetched authenticated extended agent card:");
System.out.println(JsonUtil.toJson(extendedAgentCard));
System.out.println("Using AUTHENTICATED EXTENDED agent card for client initialization.");
finalAgentCard = extendedAgentCard;
} else {
System.out.println("Public card does not indicate support for an extended card. Using public card.");
}

final CompletableFuture<String> messageResponse = new CompletableFuture<>();

Expand Down Expand Up @@ -109,12 +94,21 @@ public static void main(String[] args) {
}

ClientBuilder clientBuilder = Client
.builder(finalAgentCard)
.builder(publicAgentCard)
.addConsumers(consumers)
.streamingErrorHandler(streamingErrorHandler);
configureTransport(clientBuilder, openTelemetrySdk);
Client client = clientBuilder.build();

if (publicAgentCard.capabilities().extendedAgentCard()) {
// The client uses the extended card for the calls that follow
AgentCard extendedAgentCard = client.getExtendedAgentCard();
System.out.println("Successfully fetched extended agent card:");
System.out.println(JsonUtil.toJson(extendedAgentCard));
} else {
System.out.println("Public card does not indicate support for an extended card. Using public card.");
}

Message message = A2A.toUserMessage(MESSAGE_TEXT); // the message ID will be automatically generated for you
try {
System.out.println("Sending message: " + MESSAGE_TEXT);
Expand Down
4 changes: 2 additions & 2 deletions examples/helloworld/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ The client will connect to the Java server running on `http://localhost:9999`.
The Python A2A client (`test_client.py`) performs the following actions:

1. Fetches the server's public agent card
2. Fetches the server's extended agent card if supported by the server (see https://github.com/a2aproject/a2a-java/issues/81)
3. Creates an A2A client using the extended agent card that connects to the Python server at `http://localhost:9999`.
2. Fetches the server's extended agent card
3. Creates an A2A client using the extended agent card that connects to the Java server at `http://localhost:9999`.
4. Sends a regular message asking "how much is 10 USD in INR?".
5. Prints the server's response.
6. Sends the same message as a streaming request.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.a2aproject.sdk.examples.helloworld.server;

import org.a2aproject.sdk.server.ExtendedAgentCard;
import org.a2aproject.sdk.server.PublicAgentCard;
import org.a2aproject.sdk.spec.AgentCapabilities;
import org.a2aproject.sdk.spec.AgentCard;
Expand All @@ -10,6 +11,7 @@
import jakarta.enterprise.inject.Produces;
import org.eclipse.microprofile.config.inject.ConfigProperty;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

Expand All @@ -34,6 +36,7 @@ public AgentCard agentCard() {
.capabilities(AgentCapabilities.builder()
.streaming(true)
.pushNotifications(true)
.extendedAgentCard(true)
.build())
.defaultInputModes(Collections.singletonList("text"))
.defaultOutputModes(Collections.singletonList("text"))
Expand All @@ -47,6 +50,26 @@ public AgentCard agentCard() {
.build();
}

// Returned by GetExtendedAgentCard. No authentication is configured here, so any client can read it.
@Produces
@ExtendedAgentCard
public AgentCard extendedAgentCard() {
AgentCard publicCard = agentCard();
List<AgentSkill> skills = new ArrayList<>(publicCard.skills());
skills.add(AgentSkill.builder()
.id("super_hello_world")
.name("Returns a SUPER hello world")
.description("A more enthusiastic hello world, only listed in the extended agent card")
.tags(List.of("hello world", "extended"))
.examples(List.of("super hi", "give me a super hello"))
.build());
return AgentCard.builder(publicCard)
.name("Hello World Agent - Extended Edition")
.description("The full-featured hello world agent for authenticated users")
.skills(skills)
.build();
}

private AgentInterface getAgentInterface() {
TransportProtocol protocol = TransportProtocol.fromString(protocolStr);
String url = switch (protocol) {
Expand Down
Loading