-
Notifications
You must be signed in to change notification settings - Fork 13
feat: Add Redis-backed session service to ADK community extensions #4
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
feat: Add Redis-backed session service to ADK community extensions #4
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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 @yvesemmanuel, 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 significantly enhances the ADK community extensions by introducing a robust Redis-backed session service. This new service provides a scalable and persistent solution for managing user sessions and their associated states, moving away from in-memory solutions for more demanding applications. The changes include core service implementation, integration with the existing FastAPI CLI, necessary dependency updates, and thorough unit testing to ensure reliability.
Highlights
- New Redis-backed Session Service: Introduced
RedisMemorySessionServicefor persistent session management, offering methods for creating, retrieving, listing, and deleting sessions, as well as managing session state and events. - FastAPI CLI Integration: Integrated the new Redis session service into the FastAPI CLI module, allowing
redis://URIs for session service configuration. - Dependency Updates: Added
redis>=6.0.0as a core dependency andpytest>=8.4.2andpytest-asyncio>=1.2.0as development dependencies for testing. - Project Infrastructure: Added a comprehensive
.gitignorefile for Python projects and included unit tests for the new Redis session service.
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 Redis-backed session service, which is a valuable addition for enabling persistent session management in the ADK. The implementation is generally solid, with good use of async Redis operations and a comprehensive set of unit tests. However, I've identified a few critical issues with dependency versions that will prevent the package from being installed or the development environment from being set up. I also have a significant concern regarding the scalability of the current Redis storage strategy, which could lead to performance problems in production. Additionally, there are several opportunities to improve code clarity, efficiency, and test coverage. My detailed comments are provided below.
src/google/adk_community/sessions/redis_memory_session_service.py
Outdated
Show resolved
Hide resolved
src/google/adk_community/sessions/redis_memory_session_service.py
Outdated
Show resolved
Hide resolved
src/google/adk_community/sessions/redis_memory_session_service.py
Outdated
Show resolved
Hide resolved
src/google/adk_community/sessions/redis_memory_session_service.py
Outdated
Show resolved
Hide resolved
39c5588 to
1c83953
Compare
|
/gemini review |
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 Redis-backed session service. The overall structure is sound, leveraging redis-py for asynchronous operations and providing a clear API. However, I've identified several critical issues related to performance and correctness in the session management logic. The current implementation inefficiently loads and saves all of a user's sessions for operations that should only affect a single session, which can lead to significant performance degradation and race conditions under concurrent use. I have provided specific, refactored code suggestions for each affected method to resolve these issues by using atomic, single-key Redis operations. Additionally, there is a critical bug in src/google/adk_community/__init__.py that will prevent the package from being imported, and some of the new unit tests use incorrect mocking, which I've also flagged for correction. Addressing these points will make the new service robust, performant, and reliable.
src/google/adk_community/sessions/redis_memory_session_service.py
Outdated
Show resolved
Hide resolved
src/google/adk_community/sessions/redis_memory_session_service.py
Outdated
Show resolved
Hide resolved
src/google/adk_community/sessions/redis_memory_session_service.py
Outdated
Show resolved
Hide resolved
src/google/adk_community/sessions/redis_memory_session_service.py
Outdated
Show resolved
Hide resolved
0829e70 to
d0f89f7
Compare
|
/gemini review |
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 is a great addition, introducing a Redis-backed session service for more robust session management. The implementation is solid, effectively using Redis features like pipelines and expiration. The tests are comprehensive and cover the new functionality well. I've identified a few areas for improvement related to code quality, performance, and a potential bug in a utility function. My detailed comments are provided below.
src/google/adk_community/sessions/redis_memory_session_service.py
Outdated
Show resolved
Hide resolved
src/google/adk_community/sessions/redis_memory_session_service.py
Outdated
Show resolved
Hide resolved
d0f89f7 to
9ccb00d
Compare
|
/gemini review |
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 Redis-backed session service, which is a great addition for more persistent session management. The implementation is solid and includes comprehensive unit tests. I've found a critical issue regarding argument handling in the service's constructor that would cause a crash, and a high-severity issue with the use of asyncio.run() in the synchronous helper methods. I've also included a couple of medium-severity suggestions for code quality and performance improvement. Overall, great work on this feature.
src/google/adk_community/sessions/redis_memory_session_service.py
Outdated
Show resolved
Hide resolved
src/google/adk_community/sessions/redis_memory_session_service.py
Outdated
Show resolved
Hide resolved
src/google/adk_community/sessions/redis_memory_session_service.py
Outdated
Show resolved
Hide resolved
9ccb00d to
96f69fb
Compare
|
/gemini review |
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 Redis-backed session service, which is a valuable addition for enabling persistent sessions in ADK applications. The implementation is well-structured, using Redis pipelines for efficiency and including a good set of unit tests. I've identified a couple of areas for improvement related to data consistency with key expirations and the cleanup of stale session IDs. My review comments provide specific suggestions to enhance the robustness of the new service. Overall, this is a solid contribution.
src/google/adk_community/sessions/redis_memory_session_service.py
Outdated
Show resolved
Hide resolved
src/google/adk_community/sessions/redis_memory_session_service.py
Outdated
Show resolved
Hide resolved
96f69fb to
13f1b14
Compare
|
/gemini review |
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 Redis-backed session service, which is a valuable addition for enabling scalable session management. The implementation is solid, effectively using Redis pipelines for efficiency and atomicity. The code is well-structured, and the inclusion of unit tests is commendable. My review provides feedback on a few areas for improvement, focusing on code clarity, best practices, and test correctness to further enhance the quality of this new feature.
src/google/adk_community/sessions/redis_memory_session_service.py
Outdated
Show resolved
Hide resolved
src/google/adk_community/sessions/redis_memory_session_service.py
Outdated
Show resolved
Hide resolved
b892d9e to
0c51c1e
Compare
0c51c1e to
2370467
Compare
|
@hangfei could you help review? I wonder which folder these files should live. We probably shouldn't have 'google' in the path. |
2370467 to
9c03cf2
Compare
|
What is the right way to pass authentication parameters to the I've tried |
Here I'm following this pattern for the URI: |
9c03cf2 to
14ac183
Compare
14ac183 to
9804815
Compare
|
Removed JS code for now. Overall LGTM. |
| """A Redis-backed implementation of the session service.""" | ||
|
|
||
| def __init__( | ||
| self, |
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.
Shall we use keyword arguments to be more clear?
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.
seems other session impls also not using it.
any reason we are not using it there?
Redis Session Service Implementation
This pull request addresses the issue described in #5.
This PR migrates the Redis-backed session service implementation proposed in google/adk-python#789. I've excluded the changes to the
EventandSessionclasses, opting to use Pydantic's default serialization and deserialization methods instead. While credit goes to the original pull request from the main repository, I have completely refactored the implementation to align with this community repository's standards.What's Changed
New Redis-backed session service:
RedisMemorySessionServiceclass that provides a Redis-backed implementation of session management, including methods for creating, retrieving, listing, and deleting sessions, as well as managing session state and events (src/google/adk_community/sessions/redis_memory_session_service.py)__init__.pyin the sessions module to includeRedisMemorySessionServicein the exports (src/google/adk_community/sessions/__init__.py)FastAPI CLI integration:
src/google/adk_community/cli/fast_api.py)browser/dependencies dir for thedev-ui/endpoint web rendering.Dependency updates:
redis>=5.0.0, <6.0.0as a new dependency inpyproject.tomlto support the Redis-based session servicepytest>=8.2.2andpytest-asyncio>=0.23.7Project infrastructure:
.gitignorefile for Python projects with IDE, testing, and build artifacts exclusionstests/unittests/sessions/test_redis_session_service.py)Testing
Test Setup and Dependencies
The implementation has been thoroughly tested using the academic-research sample from https://github.com/google/adk-samples/tree/main/python/agents/academic-research.
Installation:
Test Implementation
The following FastAPI implementation demonstrates the Redis database session service integration:
Test Results and Verification
The testing process validates both the web interface functionality and Redis data persistence:
Web Interface Testing
The web UI successfully demonstrates conversation functionality with the academic research agent, confirming that:
Redis Data Persistence Verification
Redis Insight shows the successfully written session data and conversation history, confirming that: