-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: implement streaming support in to_a2a for issue #640 #4230
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @sanjeevamk1, 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 Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe 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 by creating a comment using either
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 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
|
|
Response from ADK Triaging Agent Hello @sanjeevamk1, thank you for creating this PR! To help reviewers understand and evaluate your contribution, could you please fill out the pull request template in the description? Specifically, please provide the following:
This information is crucial for an efficient review process. You can find more details in our contribution guide. Thanks! |
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 streaming support for the to_a2a function. The implementation approach is sound, but I've identified a critical issue with a shadowed import that will likely lead to runtime failures. Additionally, there's an opportunity to improve maintainability by addressing significant code duplication in the new request converter. I've also pointed out a minor typo. Please review my comments for details.
| from pydantic import BaseModel | ||
|
|
||
| from ...agents.run_config import RunConfig,StreamingMode | ||
| from ...runners import RunConfig |
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.
This import of RunConfig from ...runners shadows the one imported from ...agents.run_config on the previous line. The RunConfig from ...agents.run_config is required for the streaming_mode parameter introduced in this PR. This shadowing will cause a runtime error because the RunConfig from ...runners likely does not support streaming_mode. This line should be removed.
| def create_request_converter( | ||
| streaming_mode: StreamingMode = StreamingMode.NONE | ||
| ) -> A2ARequestToAgentRunRequestConverter: | ||
| """Creates a request converter with specified streaming mode. | ||
| Args: | ||
| streaming_mode: The streaming mode to use for the agent execution. | ||
| Returns: | ||
| A Converter function configured with the specified streaming mode. | ||
| """ | ||
| def converter( | ||
| request: RequestContext, | ||
| part_converter: A2APartToGenAIPartConverter = convert_a2a_part_to_genai_part, | ||
| )-> AgentRunRequest: | ||
|
|
||
| if not request.message: | ||
| raise ValueError('Request message cannot be None') | ||
|
|
||
| custom_metadata = {} | ||
| if request.metadata: | ||
| custom_metadata['a2a_metadata'] = request.metadata | ||
|
|
||
| output_parts = [] | ||
| for a2a_part in request.message.parts: | ||
| genai_parts = part_converter(a2a_part) | ||
| if not isinstance(genai_parts, list): | ||
| genai_parts = [genai_parts] if genai_parts else [] | ||
| output_parts.extend(genai_parts) | ||
|
|
||
| return AgentRunRequest( | ||
| user_id=_get_user_id(request), | ||
| session_id=request.context_id, | ||
| new_message=genai_types.Content( | ||
| role='user', | ||
| parts=output_parts, | ||
| ), | ||
| run_config=RunConfig(streaming_mode=streaming_mode, custom_metadata=custom_metadata), | ||
| ) | ||
|
|
||
| return converter |
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.
The new converter function defined inside create_request_converter is almost identical to the existing convert_a2a_request_to_agent_run_request function. This introduces significant code duplication, which makes the code harder to maintain. Please consider refactoring to remove this duplication. For example, the common logic could be extracted into a private helper function, or convert_a2a_request_to_agent_run_request could be updated to use this new factory.
| executer_config = A2aAgentExecutorConfig( | ||
| request_converter=create_request_converter(streaming_mode=streaming_mode) | ||
| ) | ||
|
|
||
| agent_executor = A2aAgentExecutor( | ||
| runner=runner or create_runner, | ||
| config=executer_config, | ||
| ) |
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.
There is a typo in the variable name executer_config on lines 130 and 136. It should be executor_config.
| executer_config = A2aAgentExecutorConfig( | |
| request_converter=create_request_converter(streaming_mode=streaming_mode) | |
| ) | |
| agent_executor = A2aAgentExecutor( | |
| runner=runner or create_runner, | |
| config=executer_config, | |
| ) | |
| executor_config = A2aAgentExecutorConfig( | |
| request_converter=create_request_converter(streaming_mode=streaming_mode) | |
| ) | |
| agent_executor = A2aAgentExecutor( | |
| runner=runner or create_runner, | |
| config=executor_config, | |
| ) |
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
For token streaming when akd agent is exposed with to_a2a
Solution:
Added streaming_mode in to_a2a so user can select streaming while exposing the agent