feat: Add ability to skip transport validation#266
Conversation
Also add missing validation to the RestHandler.
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 enhances the flexibility of AgentCard transport validation by allowing developers to selectively skip validation checks using system properties. It also addresses a missing validation call in the RestHandler to ensure consistent application of transport configuration rules. These changes improve the robustness and configurability of the system's transport layer.
Highlights
- Transport Validation Skipping: Introduced system properties to allow skipping of AgentCard transport validation, either globally or for specific transport protocols (JSONRPC, gRPC, REST).
- RestHandler Validation Enforcement: Ensured the RestHandler explicitly performs AgentCard transport validation upon initialization, addressing a previously missing validation call.
- Comprehensive Testing: Added comprehensive unit tests to verify the correct behavior of the new transport validation skip functionality.
- Configuration Correction: Corrected a transport protocol string in a test properties file from "HTTP_JSON" to "HTTP+JSON" for consistency.
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. ↩
There was a problem hiding this comment.
Code Review
This pull request introduces a valuable feature to skip transport validation via system properties, enhancing flexibility. The implementation is solid, with thorough test coverage for the new functionality. Additionally, it correctly adds a missing validation step to the RestHandler. My feedback includes a couple of suggestions aimed at improving code maintainability and reducing duplication.
| private static boolean isTransportSkipped(String transport) { | ||
| if (transport.equals(TransportProtocol.JSONRPC.asString())) { | ||
| return Boolean.getBoolean(SKIP_JSONRPC_PROPERTY); | ||
| } else if (transport.equals(TransportProtocol.GRPC.asString())){ | ||
| return Boolean.getBoolean(SKIP_GRPC_PROPERTY); | ||
| } else if (transport.equals(TransportProtocol.HTTP_JSON.asString())) { | ||
| return Boolean.getBoolean(SKIP_REST_PROPERTY); | ||
| } | ||
| return false; | ||
| } |
There was a problem hiding this comment.
The if-else if chain can be simplified by using a switch statement. This improves readability and is slightly more efficient, making the code easier to maintain.
private static boolean isTransportSkipped(String transport) {
switch (transport) {
case "JSONRPC":
return Boolean.getBoolean(SKIP_JSONRPC_PROPERTY);
case "GRPC":
return Boolean.getBoolean(SKIP_GRPC_PROPERTY);
case "HTTP+JSON":
return Boolean.getBoolean(SKIP_REST_PROPERTY);
default:
return false;
}
}There was a problem hiding this comment.
I want to use constants
| AgentCard agentCard = new AgentCard.Builder() | ||
| .name("Test Agent") | ||
| .description("Test Description") | ||
| .url("http://localhost:9999") | ||
| .version("1.0.0") | ||
| .capabilities(new AgentCapabilities.Builder().build()) | ||
| .defaultInputModes(Collections.singletonList("text")) | ||
| .defaultOutputModes(Collections.singletonList("text")) | ||
| .skills(Collections.emptyList()) | ||
| .build(); |
There was a problem hiding this comment.
There is significant code duplication across the new test methods for building AgentCard instances. To improve maintainability and reduce this duplication, consider extracting the common AgentCard.Builder setup into a private helper method.
For example, you could create a method like this:
private AgentCard.Builder createTestAgentCardBuilder() {
return new AgentCard.Builder()
.name("Test Agent")
.description("Test Description")
.url("http://localhost:9999")
.version("1.0.0")
.capabilities(new AgentCapabilities.Builder().build())
.defaultInputModes(Collections.singletonList("text"))
.defaultOutputModes(Collections.singletonList("text"))
.skills(Collections.emptyList());
}Then, each test can call this helper and customize the agent card as needed, for instance: createTestAgentCardBuilder().preferredTransport(...).build().
Also add missing validation to the RestHandler. Fixes a2aproject#264 🦕
Also add missing validation to the RestHandler.
Fixes #264 🦕