This example demonstrates how to use the A2A Java SDK to communicate with an A2A server. The example includes a Java client that sends both regular and streaming messages to a Python A2A server.
- Java 11 or higher
- JBang (see INSTALL_JBANG.md for quick installation instructions)
- Python 3.8 or higher
- uv (recommended) or pip
- Git
The Python A2A server is part of the a2a-samples project. To set it up and run it:
-
Clone the a2a-samples repository:
git clone https://github.com/google-a2a/a2a-samples.git cd a2a-samples/samples/python/agents/helloworld -
Recommended method: Install dependencies using uv (much faster Python package installer):
# Install uv if you don't have it already # On macOS and Linux curl -LsSf https://astral.sh/uv/install.sh | sh # On Windows powershell -c "irm https://astral.sh/uv/install.ps1 | iex" # Install the package using uv uv venv source .venv/bin/activate # On Windows: .venv\Scripts\activate uv pip install -e .
-
Run the server with uv (recommended):
uv run .
The server will start running on http://localhost:9999.
The Java client can be run using JBang, which allows you to run Java source files directly without any manual compilation.
First, ensure you have built the a2a-java project:
cd /path/to/a2a-java
mvn clean installA JBang script is provided in the example directory to make running the client easy:
-
Make sure you have JBang installed. If not, follow the JBang installation guide.
-
Navigate to the example directory:
cd examples/helloworld/client/src/main/java/io/a2a/examples/helloworld/ -
Run the client using the JBang script:
jbang HelloWorldRunner.java
This script automatically handles the dependencies and sources for you.
The Java client (HelloWorldClient.java) performs the following actions:
- Fetches the server's public agent card
- Fetches the server's extended agent card
- Creates a client using the extended agent card that connects to the Python server at
http://localhost:9999. - Sends a regular message asking "how much is 10 USD in INR?".
- Prints the server's response.
- Sends the same message as a streaming request.
- Prints each chunk of the server's streaming response as it arrives.
- Make sure the Python server is running before starting the Java client.
- The client will wait for 10 seconds to collect streaming responses before exiting.
- You can modify the message text or server URL in the
HelloWorldClient.javafile if needed.