Skip to content

feat: ✨ redis session class #789

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

Open
wants to merge 46 commits into
base: main
Choose a base branch
from

Conversation

BloodBoy21
Copy link
Contributor

This pull request introduces a Redis-backed session service implementation, along with various enhancements and adjustments to improve consistency, functionality, and maintainability across the codebase. The most significant changes include the addition of the RedisMemorySessionService, updates to the Event and Session classes to support serialization and deserialization, and the inclusion of Redis as a dependency.

New Redis-backed session service:

  • Added a new RedisMemorySessionService class to provide a Redis-backed implementation of session management. This includes methods for creating, retrieving, listing, and deleting sessions, as well as managing session state and events. (src/google/adk/sessions/redis_memory_session_service.py)
  • Updated __init__.py in the sessions module to include RedisMemorySessionService in the exports. (src/google/adk/sessions/__init__.py)

Serialization and deserialization enhancements:

  • Added to_dict and from_dict methods to the Event class to enable serialization and deserialization of event objects. (src/google/adk/events/event.py)
  • Added to_dict and from_dict methods to the Session class for similar functionality, enabling seamless handling of session data in the Redis service. (src/google/adk/sessions/session.py)

Dependency updates:

  • Added redis>=6.0.0 as a new dependency in pyproject.toml to support the Redis-based session service. (pyproject.toml)

Consistency improvements:

  • Updated string literals in the Event and Session classes to use double quotes for consistency. (src/google/adk/events/event.py) [1] [2] (src/google/adk/sessions/session.py) [3]

@BloodBoy21 BloodBoy21 changed the title feat : ✨ redis session class feat: ✨ redis session class May 19, 2025
@seanzhou1023 seanzhou1023 requested a review from DeanChensj May 21, 2025 00:24
@hangfei
Copy link
Collaborator

hangfei commented May 30, 2025

By using Redis, we’re able to share session context across any number of instances, maintaining continuity and coherence throughout the conversation flow.

Thanks for the contribution.

I don't particularly understand this part: "By using Redis, we’re able to share session context across any number of instances, maintaining continuity and coherence throughout the conversation flow."

Why does a shared memory can avoid the problems you mentioned. Could you help elaborate?

@BloodBoy21
Copy link
Contributor Author

By using Redis, we’re able to share session context across any number of instances, maintaining continuity and coherence throughout the conversation flow.

Thanks for the contribution.

I don't particularly understand this part: "By using Redis, we’re able to share session context across any number of instances, maintaining continuity and coherence throughout the conversation flow."

Why does a shared memory can avoid the problems you mentioned. Could you help elaborate?

Sure
image
In the first scenario, we have multiple instances of our application running on Cloud Run. Since requests can be routed to any instance, the user context can be lost between messages — potentially causing a looping interaction.

By integrating Redis, we can persist session data and share it across all instances. This allows us to maintain the current session state for each user. Additionally, we can use TTL (Time To Live) to automatically remove expired session data and keep the system clean.

This solution helps in the case of Artificial Nerds to scale agent bots and avoid looped conversations caused by missed context.

@whhlct
Copy link

whhlct commented Jun 6, 2025

Any update on the status of this PR?

@boyangsvl
Copy link
Collaborator

Hi, we are preparing a new repo to house community contributions which will give more freedom to the community to add new features that extend ADK's features. Please stay tuned.

@semoal
Copy link

semoal commented Jun 21, 2025

Hi, we are preparing a new repo to house community contributions which will give more freedom to the community to add new features that extend ADK's features. Please stay tuned.

Hi Bo! Are there any timeline available for that? We would love to add Redis session storage in our services.

@boyangsvl
Copy link
Collaborator

@hangfei do you have an ETA for the community repo?

@nmvijay
Copy link

nmvijay commented Jul 2, 2025

@boyangsvl this is very important feature to build scalable agents, it would be great, if we get some conclusion soon.

@boyangsvl
Copy link
Collaborator

Sorry for the delay. There are some processes we have to go through to create the repo. Please stay tuned.

@BloodBoy21 BloodBoy21 force-pushed the feat-redis-session branch from 267215a to 2a55584 Compare July 15, 2025 20:16
@javierherrera1996
Copy link

I really need this kind of solution i'm building big project and i need to share my session between many services.

@rajatm91
Copy link

@boyangsvl any timelines when this feature would be available

@hangfei
Copy link
Collaborator

hangfei commented Aug 18, 2025

Hi folks, could you migrate this PR to our community repo: https://github.com/google/adk-python-community. This work fits very well into domain of that repo. If you have any followup questions, feel free to raise them.

@anoteboom
Copy link

If this Redis Session service is implemented in this new community repository, how will we use it?
I now start our CloudRun app using get_fast_api_app:

from google.adk.cli.fast_api import get_fast_api_app
app = get_fast_api_app(
    agents_dir=AGENT_DIR,
    session_service_uri=SESSION_SERVICE_URI
)

But this session_service_uri argument does not support a URI like "redis://"

How would that work when the community creates other services?

@boyangsvl
Copy link
Collaborator

Hi @anoteboom,

I'm thinking about a registry mechanism that allows people to register a session service to a URI schema. Do you have time to think about such a design?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.