Skip to main content

Redis-backed session service for Google ADK

Project description

google-adk-redis

Redis-backed session service for Google ADK.

Install

From a Git repo:

pip install git+https://github.com/hucruz/google-adk-redis.git

From PyPI:

pip install google-adk-redis

Usage (programmatic)

from google_adk_redis import RedisMemorySessionService

session_service = RedisMemorySessionService(
    host="localhost",
    port=6379,
    db=0,
    expire=60 * 60,
    max_transaction_retries=16,
)

Instances created with the same Redis configuration reuse the same underlying async Redis client by default, so creating many services does not multiply connection pools. You can opt out with share_cache=False or inject a custom client with cache=....

If your application may attempt to load and create the same known session ID concurrently, prefer get_or_create_session(...) over a manual get_session(...) then create_session(...) sequence.

Each session is stored in its own Redis key using the shape session:<app_name>:<user_id>:<session_id>, so different sessions for the same user no longer overwrite each other through a shared JSON blob. If you still expect concurrent writes to the same session across processes, increase max_transaction_retries and, if needed, adjust transaction_retry_base_delay / transaction_retry_max_delay.

Optional register for google.adk.sessions

import google_adk_redis

google_adk_redis.register()
from google.adk.sessions import RedisMemorySessionService

Usage with Google ADK (Runner)

import asyncio

from google.adk.agents.llm_agent import LlmAgent
from google.adk.runners import Runner
from google.genai import types

from google_adk_redis import RedisMemorySessionService


async def main():
    session_service = RedisMemorySessionService(
        host="localhost",
        port=6379,
        db=0,
        expire=60 * 60,
    )
    agent = LlmAgent(
        name="assistant",
        model="gemini-2.0-flash",
        instruction="You are a helpful assistant.",
    )

    async with Runner(
        app_name="demo-app",
        agent=agent,
        session_service=session_service,
    ) as runner:
        session = await session_service.create_session(
            app_name="demo-app",
            user_id="user-123",
        )

        async for event in runner.run_async(
            user_id=session.user_id,
            session_id=session.id,
            new_message=types.Content(
                role="user",
                parts=[types.Part(text="Hola!")],
            ),
        ):
            if event.content and event.content.parts:
                text = "".join(part.text or "" for part in event.content.parts)
                if text:
                    print(text)


asyncio.run(main())

Authors

Maintainer

Attribution

Source repository: https://github.com/BloodBoy21/nerds-adk-python/tree/feat-redis-session

This repository packages and adapts the upstream implementation for standalone use.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

google_adk_redis-0.1.5.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

google_adk_redis-0.1.5-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file google_adk_redis-0.1.5.tar.gz.

File metadata

  • Download URL: google_adk_redis-0.1.5.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for google_adk_redis-0.1.5.tar.gz
Algorithm Hash digest
SHA256 3993ce72a6c4bf1e3476b6afb8a73ad9d3eecedc8e6259fe9ec6912ca0c98473
MD5 dcf976e6cbc9c0a15f5b4f5f20d6d5f7
BLAKE2b-256 560c976bba7b2abbf677b0ea61547fc1cce81029cae92c0cd66d031215c3a76a

See more details on using hashes here.

Provenance

The following attestation bundles were made for google_adk_redis-0.1.5.tar.gz:

Publisher: workflow.yml on hucruz/google-adk-redis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file google_adk_redis-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for google_adk_redis-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d3230512472c5fbbe5a9a2680d9c982e0a8ba96e26451a96ada003fe9b088b00
MD5 70b13656a69a987e6c75cfec9d501050
BLAKE2b-256 5d151fa23ab4727ad82078c56ac36de55084647c63645c1546b7478f83c53787

See more details on using hashes here.

Provenance

The following attestation bundles were made for google_adk_redis-0.1.5-py3-none-any.whl:

Publisher: workflow.yml on hucruz/google-adk-redis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page