-
Notifications
You must be signed in to change notification settings - Fork 61
Open
Description
What happened?
Lib in build.gradle
implementation("io.github.a2asdk:a2a-java-sdk-client:0.2.5")
Steps I tried
-
I downloaded the repo for Python Helloworld A2A sample agent and started the server at port 9999 by referring this example link
-
Then I downloaded the Java helloworld example , I tried the below A2A client code in java to connect to Python A2A helloworld agent
A2A Client PoC – Java Example
package com.org;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.a2a.A2A;
import io.a2a.client.A2AClient;
import io.a2a.spec.AgentCard;
import io.a2a.spec.Message;
import io.a2a.spec.MessageSendParams;
import io.a2a.spec.SendMessageResponse;
import java.util.HashMap;
import java.util.Map;
public class A2AClientPoc {
private static final String SERVER_URL = "http://localhost:9999";
private static final String MESSAGE_TEXT = "can you greet me ?";
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
public static void main(String[] args) {
try {
System.out.println("DEBUG: Starting client...");
System.out.println("DEBUG: Connecting to server at: " + SERVER_URL);
AgentCard finalAgentCard;
System.out.println("DEBUG: Attempting to fetch public agent card...");
AgentCard publicAgentCard = A2A.getAgentCard(SERVER_URL);
System.out.println("DEBUG: Successfully fetched public agent card:");
System.out.println(OBJECT_MAPPER.writeValueAsString(publicAgentCard));
System.out.println("DEBUG: Using public agent card for client initialization (default).");
finalAgentCard = publicAgentCard;
if (publicAgentCard.supportsAuthenticatedExtendedCard()) {
System.out.println("DEBUG: Public card supports authenticated extended card.");
String extendedCardUrl = SERVER_URL + "/agent/authenticatedExtendedCard";
System.out.println("DEBUG: Attempting to fetch from: " + extendedCardUrl);
Map<String, String> authHeaders = new HashMap<>();
authHeaders.put("Authorization", "Bearer dummy-token-for-extended-card");
System.out.println("DEBUG: Using auth headers: " + authHeaders);
try {
AgentCard extendedAgentCard = A2A.getAgentCard(
SERVER_URL,
"/agent/authenticatedExtendedCard",
authHeaders
);
System.out.println("DEBUG: Successfully fetched authenticated extended agent card:");
System.out.println(OBJECT_MAPPER.writeValueAsString(extendedAgentCard));
System.out.println("DEBUG: Using AUTHENTICATED EXTENDED agent card for client initialization.");
finalAgentCard = extendedAgentCard;
} catch (Exception e) {
System.err.println("DEBUG: Failed to fetch extended card, using public card instead: " + e.getMessage());
}
} else {
System.out.println("DEBUG: Public card does not indicate support for an extended card. Using public card.");
}
System.out.println("DEBUG: Creating A2A client with final agent card...");
A2AClient client = new A2AClient(finalAgentCard);
System.out.println("DEBUG: Client created successfully.");
System.out.println("DEBUG: Creating message: '" + MESSAGE_TEXT + "'");
Message message = A2A.toUserMessage(MESSAGE_TEXT);
System.out.println("DEBUG: Message created with ID: " + message.getMessageId());
MessageSendParams params = new MessageSendParams.Builder()
.message(message)
.build();
System.out.println("DEBUG: MessageSendParams created.");
System.out.println(OBJECT_MAPPER.writeValueAsString(params));
System.out.println("DEBUG: Sending message to server...");
SendMessageResponse response = client.sendMessage(params);
System.out.println("DEBUG: Message sent successfully!");
System.out.println("Message sent with ID: " + response.getId());
System.out.println("Response: " + response.toString());
} catch (Exception e) {
System.err.println("DEBUG: An error occurred in main: " + e.getClass().getSimpleName());
System.err.println("DEBUG: Error message: " + e.getMessage());
System.err.println("DEBUG: Full stack trace:");
e.printStackTrace();
if (e.getMessage() != null && e.getMessage().contains("JSON")) {
System.err.println("DEBUG: This appears to be a JSON parsing error.");
System.err.println("DEBUG: Check if the server is running and returning valid JSON responses.");
System.err.println("DEBUG: Server URL: " + SERVER_URL);
}
}
}
}
- When I run the above code I am getting the Json decode error .
Relevant Python Helloworld agent log output
DEBUG: HelloWorldAgentExecutor.__init__() called
DEBUG: HelloWorldAgentExecutor initialized with HelloWorldAgent
INFO: Started server process [6668]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:9999 (Press CTRL+C to quit)
WARNING: Unsupported upgrade request.
INFO: 127.0.0.1:53512 - "GET /.well-known/agent.json HTTP/1.1" 200 OK
WARNING: Unsupported upgrade request.
INFO: 127.0.0.1:53513 - "GET /agent/authenticatedExtendedCard HTTP/1.1" 200 OK
WARNING: Unsupported upgrade request.
Traceback (most recent call last):
File "C:\Users\lapto\Music\AI\A2A\venv\Lib\site-packages\a2a\server\apps\jsonrpc\jsonrpc_app.py", line 204, in _handle_requests
body = await request.json()
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\lapto\Music\AI\A2A\venv\Lib\site-packages\starlette\requests.py", line 249, in json
self._json = json.loads(body)
^^^^^^^^^^^^^^^^
File "C:\Users\lapto\AppData\Local\Programs\Python\Python312\Lib\json\__init__.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\lapto\AppData\Local\Programs\Python\Python312\Lib\json\decoder.py", line 338, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\lapto\AppData\Local\Programs\Python\Python312\Lib\json\decoder.py", line 356, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Request Error (ID: None): Code=-32700, Message='Expecting value: line 1 column 1 (char 0)'
INFO: 127.0.0.1:53514 - "POST / HTTP/1.1" 200 OK
WARNING: Invalid HTTP request received.
Relevant Java A2A Client Log output
Caused by: io.a2a.spec.JSONParseError: Expecting value: line 1 column 1 (char 0)
Code of Conduct
- I agree to follow this project's Code of Conduct
Metadata
Metadata
Assignees
Labels
No labels