A2A Java SDK: Support for the REST Transport is Now Here
Today, we’ve released A2A Java SDK 0.3.0.Beta1 which introduces support for the HTTP+JSON/REST transport.
Our last blog post covered what’s new in the 0.3.0 version of the A2A Java SDK. In this post, we’ll focus on how to make use of the new HTTP+JSON/REST transport for both A2A server agents and clients.
Configuring an A2A Server Agent to Support the REST Transport
To enable your A2A server agent to support communication using HTTP+JSON/REST, add the following dependency:
The |
<dependency>
<groupId>io.github.a2asdk</groupId>
<artifactId>a2a-java-sdk-reference-rest</artifactId> (1)
</dependency>
1 | a2a-java-sdk-reference-rest provides access to the core classes that make up the A2A specification and provides the HTTP endpoints that implement the A2A protocol using the HTTP+JSON/REST transport. |
After adding this dependency, simply update your agent card to declare support for this new transport:
@Produces
@PublicAgentCard
public AgentCard agentCard() {
return new AgentCard.Builder()
.url(YOUR_HTTP_JSON_URL) (1)
.preferredTransport(TransportProtocol.HTTP_JSON.asString()) (2)
.additionalInterfaces(List.of(
new AgentInterface(TransportProtocol.HTTP_JSON.asString(),
YOUR_HTTP_JSON_URL)
... (3)
))
...
.build();
}
1 | This is the primary URL for your A2A server agent. This should be the URL for your preferred transport (e.g., http://localhost:8080 ). |
2 | Your A2A server agent’s preferred transport, HTTP+JSON/REST in this example. |
3 | The additionalInterfaces can optionally contain an entry for the preferred transport. Any other transports you’d like to support (e.g., TransportProtocol.JSONRPC.asString() or TransportProtocol.GRPC.asString() ) can be specified here too. |
For more details on configuring your A2A server agent to support multiple transports, refer to our previous blog post.
Configuring an A2A Client to Support the REST Transport
To get your A2A client to communicate using the HTTP+JSON/REST transport, you’ll need to add a couple dependencies.
First, add the a2a-java-sdk-client
dependency to your project. This will provide access to a Builder
that you can use to create your A2A Client
.
<dependency>
<groupId>io.github.a2asdk</groupId>
<artifactId>a2a-java-sdk-client</artifactId> (1)
</dependency>
Next, add the specific dependency for the HTTP+JSON/REST transport:
<dependency>
<groupId>io.github.a2asdk</groupId>
<artifactId>a2a-java-sdk-client-transport-rest</artifactId>
</dependency>
You can now use Client.builder()
to create a Client
that supports the HTTP+JSON/REST transport using the withTransport
method as shown below:
// Create the client using the builder
Client client = Client
.builder(agentCard)
.withTransport(RestTransport.class, new RestTransportConfig()) (1)
....
.build();
1 | This specifies that our client can support the HTTP+JSON/REST transport. At least one transport must be configured using the withTransport method. |
For a deep dive into creating clients with the Client.Builder
, check out this post.