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.

Writers for the same app_name and user_id are serialized within a single Python process to avoid clobbering the shared session blob. If you still expect cross-process contention, 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.4.tar.gz (19.5 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.4-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: google_adk_redis-0.1.4.tar.gz
  • Upload date:
  • Size: 19.5 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.4.tar.gz
Algorithm Hash digest
SHA256 674f2182a03b1a8f1356b5b9684ba3f04f8a5ce56ccd40baf3a37c146897f882
MD5 59c75d5e7d643486e13013e350348d5c
BLAKE2b-256 158d46d84d399893be0ebf580b67e3f96e6dab2736c11cf831dbc9c7f987d128

See more details on using hashes here.

Provenance

The following attestation bundles were made for google_adk_redis-0.1.4.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.4-py3-none-any.whl.

File metadata

File hashes

Hashes for google_adk_redis-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ad46822ed6da39a4e2c68b61640e9369a407dcb9c7adccde3201a7e99c3dbfae
MD5 ac841d76e556c576501583c034c63d85
BLAKE2b-256 4085e7dcf4db344bd56034beacb64c7b729ebb7aa0446abbd17a48bdd6d31e7f

See more details on using hashes here.

Provenance

The following attestation bundles were made for google_adk_redis-0.1.4-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