Skip to content
Open
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ If you want to use the HTTP+JSON/REST transport, you'll need to add a relevant d

```java
// First, get the agent card for the A2A server agent you want to connect to
AgentCard agentCard = new A2ACardResolver("http://localhost:1234").getAgentCard();
AgentCard agentCard = A2ACardResolver.builder().baseUrl("http://localhost:1234").build().getWellKnownAgentCard();

// Specify configuration for the ClientBuilder
ClientConfig clientConfig = new ClientConfig.Builder()
Expand Down Expand Up @@ -776,7 +776,7 @@ gRPC and REST transports are also available:
#### 3. Create the v0.3 client

```java
AgentCard card = new A2ACardResolver("http://localhost:1234").getAgentCard();
AgentCard card = A2ACardResolver.builder().baseUrl("http://localhost:1234").build().getWellKnownAgentCard();

// Find the v0.3 interface from the agent card
AgentInterface v03Interface = card.supportedInterfaces().stream()
Expand Down
11 changes: 9 additions & 2 deletions client/base/src/main/java/org/a2aproject/sdk/A2A.java
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,14 @@ public static AgentCard getAgentCard(String agentUrl, String relativeCardPath, M
* @throws org.a2aproject.sdk.spec.A2AClientJSONError if the response body cannot be decoded as JSON or validated against the AgentCard schema
*/
public static AgentCard getAgentCard(A2AHttpClient httpClient, String agentUrl, String relativeCardPath, Map<String, String> authHeaders) throws A2AClientError, A2AClientJSONError {
A2ACardResolver resolver = new A2ACardResolver(httpClient, agentUrl, "", relativeCardPath, authHeaders);
return resolver.getAgentCard();
A2ACardResolver resolver = A2ACardResolver.builder()
.httpClient(httpClient)
.baseUrl(agentUrl)
.agentCardPath(relativeCardPath)
.authHeaders(authHeaders)
.build();
return (relativeCardPath == null || relativeCardPath.isBlank())
? resolver.getWellKnownAgentCard()
: resolver.getConfiguredAgentCard();
Comment on lines +402 to +404
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

With the fix applied to A2ACardResolver where configuredAgentCardUrl correctly defaults to wellKnownUrl when agentCardPath is null or blank, we can simplify this logic and remove the ternary operator check.

        return resolver.getConfiguredAgentCard();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class HelloWorldClient {
public static void main(String[] args) {
OpenTelemetrySdk openTelemetrySdk = null;
try {
AgentCard publicAgentCard = new A2ACardResolver(SERVER_URL).getAgentCard();
AgentCard publicAgentCard = A2ACardResolver.builder().baseUrl(SERVER_URL).build().getWellKnownAgentCard();
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).");
Expand Down
8 changes: 4 additions & 4 deletions extras/http-client-vertx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ The Vert.x HTTP client is automatically discovered via **Java SPI (Service Provi

```java
// No changes needed - A2A SDK automatically uses VertxA2AHttpClient
A2ACardResolver resolver = new A2ACardResolver("http://localhost:9999");
AgentCard card = resolver.getAgentCard(); // Uses Vert.x under the hood
A2ACardResolver resolver = A2ACardResolver.builder().baseUrl("http://localhost:9999").build();
AgentCard card = resolver.getWellKnownAgentCard(); // Uses Vert.x under the hood

// Client creation also uses Vert.x automatically
Client client = Client.builder(card)
Expand All @@ -112,8 +112,8 @@ The module works out-of-the-box with sensible defaults:
// With vertx-http-client on the classpath, it automatically uses VertxA2AHttpClient

// Example 1: Fetching agent card
A2ACardResolver resolver = new A2ACardResolver("http://localhost:9999");
AgentCard card = resolver.getAgentCard();
A2ACardResolver resolver = A2ACardResolver.builder().baseUrl("http://localhost:9999").build();
AgentCard card = resolver.getWellKnownAgentCard();

// Example 2: Using REST transport (uses HTTP client internally)
Client client = Client.builder(card)
Expand Down
Loading
Loading