Conversation
Summary of ChangesHello @jayy-77, 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 plugin framework by introducing a new callback mechanism for plugins to react to changes in the session state. By adding an 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. Changelog
Activity
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 @jayy-77, thank you for your contribution! To help us review this pull request, could you please fill out the Testing Plan section in the PR description? As per our contribution guidelines, this is required for all changes that are not small documentation or typo fixes. This will help reviewers understand how you've verified the changes. Thanks! |
There was a problem hiding this comment.
Code Review
This pull request introduces a new on_state_change_callback to the plugin framework, allowing plugins to observe state changes. The implementation is sound, but I've identified a couple of areas for improvement. Specifically, the execution logic for the new callback could inadvertently prevent some plugins from being notified, and there's an opportunity to reduce code duplication in the runner. My detailed feedback is in the comments below.
| await self._run_callbacks( | ||
| "on_state_change_callback", | ||
| invocation_context=invocation_context, | ||
| state_delta=state_delta, | ||
| ) |
There was a problem hiding this comment.
Using _run_callbacks here introduces an early-exit behavior if any plugin returns a non-None value. For an observational callback like on_state_change_callback, all registered plugins should be notified regardless of the return values of others. The current implementation could lead to some plugins missing state change notifications if a preceding plugin in the chain returns a value.
To ensure all plugins are reliably called, consider implementing this method by looping through the plugins directly. This would align better with the 'observational only' nature of this callback.
for plugin in self.plugins:
callback_method = getattr(plugin, "on_state_change_callback")
try:
await callback_method(
invocation_context=invocation_context,
state_delta=state_delta,
)
except Exception as e:
error_message = (
f"Error in plugin '{plugin.name}' during 'on_state_change_callback'"
f" callback: {e}"
)
logger.error(error_message, exc_info=True)
raise RuntimeError(error_message) from e| # Detect state_delta changes after yielding the modified event | ||
| if modified_event.actions.state_delta: | ||
| await plugin_manager.run_on_state_change_callback( | ||
| invocation_context=invocation_context, | ||
| state_delta=modified_event.actions.state_delta.copy(), | ||
| ) | ||
| else: | ||
| yield event | ||
| # Detect state_delta changes after yielding the original event | ||
| if event.actions.state_delta: | ||
| await plugin_manager.run_on_state_change_callback( | ||
| invocation_context=invocation_context, | ||
| state_delta=event.actions.state_delta.copy(), | ||
| ) |
There was a problem hiding this comment.
The logic to detect and handle state_delta is duplicated in both the if modified_event: block and the else block. To improve maintainability and reduce redundancy, this could be refactored. A single block of code after the if/else could determine which event to yield (modified_event or event) and then perform the state_delta check on that final event.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
#4393
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
If applicable, please follow the issue templates to provide as much detail as
possible.
Problem:
A clear and concise description of what the problem is.
Solution:
A clear and concise description of what you want to happen and why you choose
this solution.
Testing Plan
Please describe the tests that you ran to verify your changes. This is required
for all PRs that are not small documentation or typo fixes.
Unit Tests:
Please include a summary of passed
pytestresults.Manual End-to-End (E2E) Tests:
Please provide instructions on how to manually test your changes, including any
necessary setup or configuration. Please provide logs or screenshots to help
reviewers better understand the fix.
Checklist
Additional context
Add any other context or screenshots about the feature request here.