diff --git a/examples/helloworld/client/README.md b/examples/helloworld/client/README.md index d0673779f..2a6834df6 100644 --- a/examples/helloworld/client/README.md +++ b/examples/helloworld/client/README.md @@ -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. diff --git a/examples/helloworld/client/src/main/java/org/a2aproject/sdk/examples/helloworld/client/HelloWorldClient.java b/examples/helloworld/client/src/main/java/org/a2aproject/sdk/examples/helloworld/client/HelloWorldClient.java index 46a80ecb2..d26439c7d 100644 --- a/examples/helloworld/client/src/main/java/org/a2aproject/sdk/examples/helloworld/client/HelloWorldClient.java +++ b/examples/helloworld/client/src/main/java/org/a2aproject/sdk/examples/helloworld/client/HelloWorldClient.java @@ -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 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 messageResponse = new CompletableFuture<>(); @@ -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); diff --git a/examples/helloworld/server/README.md b/examples/helloworld/server/README.md index 66f39f7ec..a01f4aa1f 100644 --- a/examples/helloworld/server/README.md +++ b/examples/helloworld/server/README.md @@ -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. diff --git a/examples/helloworld/server/src/main/java/org/a2aproject/sdk/examples/helloworld/server/AgentCardProducer.java b/examples/helloworld/server/src/main/java/org/a2aproject/sdk/examples/helloworld/server/AgentCardProducer.java index 40e0b0b54..31711f9ea 100644 --- a/examples/helloworld/server/src/main/java/org/a2aproject/sdk/examples/helloworld/server/AgentCardProducer.java +++ b/examples/helloworld/server/src/main/java/org/a2aproject/sdk/examples/helloworld/server/AgentCardProducer.java @@ -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; @@ -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; @@ -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")) @@ -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 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) {