feat: Check transports in AgentCard match those on classpath#251
feat: Check transports in AgentCard match those on classpath#251fjuma merged 3 commits intoa2aproject:mainfrom
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @kabir, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request addresses a potential runtime issue by implementing a robust validation system for AgentCards. It ensures that any transport protocols declared within an AgentCard are genuinely supported and available on the classpath, thereby improving the reliability and preventing errors related to missing transport dependencies. The changes involve new interfaces, a dedicated validator, and integration points within existing transport handlers.
Highlights
- AgentCard Transport Validation: Introduced a new validation mechanism to ensure that the transport protocols specified in an AgentCard are actually available on the application's classpath. This prevents misconfigurations and ensures runtime stability.
- New TransportMetadata Interface: Defined a new
TransportMetadatainterface that transport implementations must implement to expose their supported protocols, enabling dynamic discovery via Java'sServiceLoader. - Integration with Existing Handlers: Integrated the new validation logic into the
GrpcHandlerandJSONRPCHandlerinitialization processes, ensuring that AgentCards are validated when handlers are set up. - Enhanced Test Coverage: Added new unit tests for the
AgentCardValidatorand updated existing test infrastructure to support the new transport discovery and validation, including the use of properties files for preferred transport configuration in tests.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
523f593 to
c8a14af
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces a validation mechanism to ensure that transports specified in an AgentCard are available on the classpath. This is achieved by using Java's ServiceLoader to discover TransportMetadata implementations. The core logic is in the new AgentCardValidator class, which is then integrated into the gRPC and JSON-RPC transport handlers.
The implementation is solid, but I've identified a potential design issue with how ServiceLoader interacts with dependency injection, which could lead to NullPointerExceptions in the future. I've left comments with suggestions on how to make this more robust. I also noticed some code duplication in test helper methods that could be refactored for better maintainability.
reference/grpc/src/main/java/io/a2a/server/grpc/quarkus/QuarkusGrpcHandler.java
Outdated
Show resolved
Hide resolved
reference/jsonrpc/src/main/java/io/a2a/server/apps/quarkus/A2AServerRoutes.java
Outdated
Show resolved
Hide resolved
| private static String loadPreferredTransportFromProperties() { | ||
| URL url = AgentCardProducer.class.getResource(A2A_REQUESTHANDLER_TEST_PROPERTIES); | ||
| if (url == null) { | ||
| return null; | ||
| } | ||
| Properties properties = new Properties(); | ||
| try { | ||
| try (InputStream in = url.openStream()){ | ||
| properties.load(in); | ||
| } | ||
| } catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
|
|
||
| String preferredTransport = properties.getProperty(PREFERRED_TRANSPORT); | ||
| Assertions.assertNotNull(preferredTransport); | ||
| return preferredTransport; | ||
| } |
There was a problem hiding this comment.
This loadDefaultTransportFromProperties method is nearly identical to the one in AbstractA2ARequestHandlerTest. To improve maintainability and avoid code duplication, consider extracting this logic into a shared test utility class.
The two implementations also have a slight difference in handling a missing properties file (url == null): one returns null while the other fails with an assertion. Consolidating them would also unify this behavior.
There was a problem hiding this comment.
I don't think this makes sense. It is only test code, and dependencies between those is a bit tricky
438d08d to
6e13ad6
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a valuable feature for validating AgentCard transport configurations against available transports on the classpath. The implementation correctly uses the ServiceLoader pattern for discovering transport metadata, making it extensible. The validation logic is sound, and the integration into the transport handlers is well-thought-out. I've identified one potential race condition in the GrpcHandler's initialization logic that should be addressed to ensure thread safety.
transport/grpc/src/main/java/io/a2a/transport/grpc/handler/GrpcHandler.java
Outdated
Show resolved
Hide resolved
6e13ad6 to
9ac1e19
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a valuable feature to validate that the transports specified in an AgentCard are available on the classpath, improving the robustness of agent configurations. The implementation correctly uses Java's ServiceLoader for discovering transport metadata, and includes a good set of unit tests. My review found a logical error in the one-time validation for the gRPC handler and a minor case of code duplication in the test helpers. Overall, this is a solid contribution.
transport/grpc/src/main/java/io/a2a/transport/grpc/handler/GrpcHandler.java
Outdated
Show resolved
Hide resolved
| private static String loadPreferredTransportFromProperties() { | ||
| URL url = AgentCardProducer.class.getResource(A2A_REQUESTHANDLER_TEST_PROPERTIES); | ||
| if (url == null) { | ||
| return null; | ||
| } | ||
| Properties properties = new Properties(); | ||
| try { | ||
| try (InputStream in = url.openStream()){ | ||
| properties.load(in); | ||
| } | ||
| } catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
|
|
||
| String preferredTransport = properties.getProperty(PREFERRED_TRANSPORT); | ||
| Assertions.assertNotNull(preferredTransport); | ||
| return preferredTransport; | ||
| } |
There was a problem hiding this comment.
9ac1e19 to
d186f8c
Compare
server-common/src/main/java/io/a2a/server/TransportMetadata.java
Outdated
Show resolved
Hide resolved
reference/jsonrpc/src/main/java/io/a2a/server/apps/quarkus/A2AServerRoutes.java
Outdated
Show resolved
Hide resolved
d186f8c to
8c6c718
Compare
|
@fjuma Should be fixed now |
Fixes #246 🦕