Skip to content
Draft
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
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,13 @@ Different transport protocols can be configured with specific settings using spe

##### JSON-RPC Transport Configuration

For the JSON-RPC transport, to use the default `JdkA2AHttpClient`, provide a `JSONRPCTransportConfig` created with its default constructor.
For the JSON-RPC transport, to use the default `JdkHttpClient`, provide a `JSONRPCTransportConfig` created with its default constructor.

To use a custom HTTP client implementation, simply create a `JSONRPCTransportConfig` as follows:

```java
// Create a custom HTTP client
A2AHttpClient customHttpClient = ...
// Create a custom HTTP client builder
HttpClientBuilder httpClientBuilder = ...

// Configure the client settings
ClientConfig clientConfig = new ClientConfig.Builder()
Expand All @@ -365,7 +365,7 @@ ClientConfig clientConfig = new ClientConfig.Builder()
Client client = Client
.builder(agentCard)
.clientConfig(clientConfig)
.withTransport(JSONRPCTransport.class, new JSONRPCTransportConfig(customHttpClient))
.withTransport(JSONRPCTransport.class, new JSONRPCTransportConfig(httpClientBuilder))
.build();
```

Expand Down Expand Up @@ -396,13 +396,13 @@ Client client = Client

##### HTTP+JSON/REST Transport Configuration

For the HTTP+JSON/REST transport, if you'd like to use the default `JdkA2AHttpClient`, provide a `RestTransportConfig` created with its default constructor.
For the HTTP+JSON/REST transport, if you'd like to use the default `JdkHttpClient`, provide a `RestTransportConfig` created with its default constructor.

To use a custom HTTP client implementation, simply create a `RestTransportConfig` as follows:

```java
// Create a custom HTTP client
A2AHttpClient customHttpClient = ...
HttpClientBuilder httpClientBuilder = ...

// Configure the client settings
ClientConfig clientConfig = new ClientConfig.Builder()
Expand All @@ -412,7 +412,7 @@ ClientConfig clientConfig = new ClientConfig.Builder()
Client client = Client
.builder(agentCard)
.clientConfig(clientConfig)
.withTransport(RestTransport.class, new RestTransportConfig(customHttpClient))
.withTransport(RestTransport.class, new RestTransportConfig(httpClientBuilder))
.build();
```

Expand Down
30 changes: 7 additions & 23 deletions client/base/src/main/java/io/a2a/A2A.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import io.a2a.client.http.A2ACardResolver;
import io.a2a.client.http.A2AHttpClient;
import io.a2a.client.http.JdkA2AHttpClient;
import io.a2a.client.http.HttpClient;
import io.a2a.spec.A2AClientError;
import io.a2a.spec.A2AClientJSONError;
import io.a2a.spec.AgentCard;
Expand Down Expand Up @@ -139,51 +137,37 @@ private static Message toMessage(List<Part<?>> parts, Message.Role role, String
* @throws A2AClientJSONError f the response body cannot be decoded as JSON or validated against the AgentCard schema
*/
public static AgentCard getAgentCard(String agentUrl) throws A2AClientError, A2AClientJSONError {
return getAgentCard(new JdkA2AHttpClient(), agentUrl);
}

/**
* Get the agent card for an A2A agent.
*
* @param httpClient the http client to use
* @param agentUrl the base URL for the agent whose agent card we want to retrieve
* @return the agent card
* @throws A2AClientError If an HTTP error occurs fetching the card
* @throws A2AClientJSONError f the response body cannot be decoded as JSON or validated against the AgentCard schema
*/
public static AgentCard getAgentCard(A2AHttpClient httpClient, String agentUrl) throws A2AClientError, A2AClientJSONError {
return getAgentCard(httpClient, agentUrl, null, null);
return getAgentCard(HttpClient.createHttpClient(agentUrl), null, null);
}

/**
* Get the agent card for an A2A agent.
*
* @param agentUrl the base URL for the agent whose agent card we want to retrieve
* @param relativeCardPath optional path to the agent card endpoint relative to the base
* agent URL, defaults to ".well-known/agent-card.json"
* agent URL, defaults to "/.well-known/agent-card.json"
* @param authHeaders the HTTP authentication headers to use
* @return the agent card
* @throws A2AClientError If an HTTP error occurs fetching the card
* @throws A2AClientJSONError f the response body cannot be decoded as JSON or validated against the AgentCard schema
*/
public static AgentCard getAgentCard(String agentUrl, String relativeCardPath, Map<String, String> authHeaders) throws A2AClientError, A2AClientJSONError {
return getAgentCard(new JdkA2AHttpClient(), agentUrl, relativeCardPath, authHeaders);
return getAgentCard(HttpClient.createHttpClient(agentUrl), relativeCardPath, authHeaders);
}

/**
* Get the agent card for an A2A agent.
*
* @param httpClient the http client to use
* @param agentUrl the base URL for the agent whose agent card we want to retrieve
* @param relativeCardPath optional path to the agent card endpoint relative to the base
* agent URL, defaults to ".well-known/agent-card.json"
* agent URL, defaults to "/.well-known/agent-card.json"
* @param authHeaders the HTTP authentication headers to use
* @return the agent card
* @throws A2AClientError If an HTTP error occurs fetching the card
* @throws A2AClientJSONError f 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);
public static AgentCard getAgentCard(HttpClient httpClient, String relativeCardPath, Map<String, String> authHeaders) throws A2AClientError, A2AClientJSONError {
A2ACardResolver resolver = new A2ACardResolver(httpClient, relativeCardPath, authHeaders);
return resolver.getAgentCard();
}
}
Loading