-
Notifications
You must be signed in to change notification settings - Fork 303
fix: Re-constructing Agent RPC URL in the AgentCard using the card's request attributes #418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @vladkol, 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!
The pull request implements a crucial fix for how Agent RPC URLs are presented in AgentCard responses. Previously, these URLs might default to local endpoints (e.g., http://localhost:8000), which is problematic in modern cloud deployments that use dynamic URLs, load balancers, or URL mapping. This change introduces logic to dynamically reconstruct the Agent RPC URL based on the incoming request's attributes, including X-Forwarded-* headers, ensuring the AgentCard provides the correct, externally accessible URL for the agent.
Highlights
- Dynamic RPC URL Reconstruction: A new private method,
_modify_rpc_url, has been introduced in bothJSONRPCApplicationandRESTAdapterto intelligently reconstruct the agent's RPC URL. This method leverages the incoming request's host, port, scheme, and path, and correctly interpretsX-Forwarded-Host,X-Forwarded-Proto, andX-Forwarded-Pathheaders to determine the public-facing URL. - AgentCard URL Correction: The
_modify_rpc_urllogic is now applied to both public and authenticatedAgentCardresponses. This ensures that theurlfield within theAgentCardaccurately reflects the external endpoint from which the card was requested, rather than an internal or default URL. - Enhanced Cloud Deployment Compatibility: By dynamically adjusting the RPC URL, this change significantly improves compatibility with cloud environments like Google Cloud Run, which assign dynamic endpoint URLs, and with setups involving load balancers or reverse proxies that use
X-Forwarded-*headers. - Comprehensive Test Coverage: New test cases have been added for both JSON-RPC and REST adapters to thoroughly validate the URL rewriting functionality under various scenarios, including different combinations of
X-Forwarded-*headers and base URLs, ensuring the fix works as expected.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a valuable feature for dynamically reconstructing the agent's RPC URL based on request headers. This is a great addition for supporting deployments behind reverse proxies or in cloud environments. The implementation is well-tested for various scenarios.
My main feedback points are:
- Code Duplication: The core logic in
_modify_rpc_urlis duplicated acrossJSONRPCApplicationandRESTAdapter. This should be refactored into a single, shared utility function to improve maintainability. I've added a specific comment about this. - Potential Bug: There's a potential
TypeErrorin the new_modify_rpc_urlmethod if the requesthostisNone. I've left inline comments with suggestions on how to fix this in both affected files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not required for agent and agent_card to be hosted from the same url. For example, agent card may be hosted on http://example.com and the agent_card.url could be specified as http://agent.example.com. So, we can't default to using the forwarded headers for the url.
Card modifier should be used for this scenario so users can mutate the card as needed.
Re-constructing Agent RPC URL in the AgentCard using the card's request attributes
Current AgentCard request handler implementation in
JSONRPCApplicationandRESTAdapterreturn AgentCard with the agent's RPC url is it's originally created in code, often as local endpoints (e.g.http://localhost:8000).Modern cloud runtime usually allows multiple ways to access deployed services. Some of them, such as load balancers may expose these services under vanity URLs. Others, like Google Cloud Run, have endpoint URLs dynamically assigned at a time of the deployment.
This PR adds "rewriting" of the agent's RPC url based on how the AgentCard was requested: with host, port, protocol and path adjusted according to the way the card's request was made. It accounts for deployments with load balancers, URL mapping, etc.
Fixes #398
Will also properly fix google/adk-python#2405
Release-As: 0.3.3