Skip to content

Conversation

@nkanu17
Copy link

@nkanu17 nkanu17 commented Jan 27, 2026

Add Redis Agent Memory Services for Session and Long-Term Memory

This PR adds two Redis Agent Memory Server-based services as optional dependencies, enabling agents to use persistent session management with auto-summarization and long-term memory with semantic search. This provides a production-ready, self-hosted alternative to in-memory services.

Related to issue #46

Changes

New Services (src/google/adk_community/)

Service ADK Interface Use Case
RedisWorkingMemorySessionService BaseSessionService Session management with auto-summarization
RedisLongTermMemoryService BaseMemoryService Persistent memory with semantic search

Dependencies (pyproject.toml)

[project.optional-dependencies]
redis-agent-memory = [
    "agent-memory-client>=0.13.0",
]

Installation:

pip install "google-adk-community[redis-agent-memory]"

Sample Agents

Added two samples in contributing/samples/:

Sample Description
redis_agent_memory/ Full two-tier memory (working + long-term)
redis_agent_memory_wo_working_session/ Long-term memory only with InMemorySessionService

Architecture

High-Level Overview

┌─────────────────────────────────────────────────────────────────────────────┐
│                              ADK ARCHITECTURE                                │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│   ┌─────────────┐    ┌─────────────┐    ┌─────────────────────────────────┐ │
│   │   Agent     │    │   Runner    │    │         Session Service         │ │
│   │             │    │             │    │                                 │ │
│   │  • Tools    │◀──▶│  • Session  │◀──▶│  • InMemorySessionService (dev) │ │
│   │  • Model    │    │  • Events   │    │  • DatabaseSessionService       │ │
│   │  • Prompts  │    │  • State    │    │  • RedisWorkingMemorySession ◀──┼─┤ NEW
│   └─────────────┘    └─────────────┘    └─────────────────────────────────┘ │
│                             │                                                │
│                             │           ┌─────────────────────────────────┐ │
│                             │           │         Memory Service          │ │
│                             │           │                                 │ │
│                             └──────────▶│  • InMemoryMemoryService (dev)  │ │
│                                         │  • VertexAIMemoryService        │ │
│                                         │  • RedisLongTermMemoryService ◀─┼─┤ NEW
│                                         └─────────────────────────────────┘ │
│                                                                              │
└─────────────────────────────────────────────────────────────────────────────┘

Two-Tier Memory Stack

┌─────────────────────────────────────────────────────────────────────────────┐
│                              ADK Application                                 │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│   ┌─────────────┐         ┌─────────────────────────────────────────────┐   │
│   │   Agent     │         │              ADK Runner                     │   │
│   │             │◀───────▶│                                             │   │
│   │  • Tools    │         │  session_service = RedisWorkingMemory...    │   │
│   │  • Model    │         │  memory_service  = RedisLongTermMemory...   │   │
│   └─────────────┘         └──────────────┬──────────────────────────────┘   │
│                                          │                                   │
└──────────────────────────────────────────┼───────────────────────────────────┘
                                           │
                                           │ HTTP (agent-memory-client)
                                           ▼
┌─────────────────────────────────────────────────────────────────────────────┐
│                         Agent Memory Server (:8000)                          │
├──────────────────────────────────┬──────────────────────────────────────────┤
│     TIER 1: Working Memory API   │     TIER 2: Long-Term Memory API         │
├──────────────────────────────────┼──────────────────────────────────────────┤
│                                  │                                           │
│  PUT    /v1/working-memory/{id}  │  POST   /v1/long-term-memory/search      │
│  GET    /v1/working-memory/{id}  │  PUT    /v1/long-term-memory/            │
│  DELETE /v1/working-memory/{id}  │  GET    /v1/long-term-memory/{id}        │
│  POST   /v1/working-memory/      │  DELETE /v1/long-term-memory/            │
│         {id}/messages            │                                           │
│                                  │                                           │
├──────────────────────────────────┼──────────────────────────────────────────┤
│  • Session state management      │  • LLM-based memory extraction           │
│  • Message history               │  • Vector embedding generation           │
│  • Token counting                │  • Semantic similarity search            │
│  • Auto-summarization            │  • Recency boosting                      │
│  • Context window management     │  • Deduplication                         │
│                                  │                                           │
└──────────────────────────────────┴──────────────────────────────────────────┘
                                           │
                                           │ Redis Protocol
                                           ▼
┌─────────────────────────────────────────────────────────────────────────────┐
│                            Redis Stack (:6379)                               │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│   ┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐         │
│   │   RedisJSON     │    │   RediSearch    │    │   Redis Core    │         │
│   │                 │    │                 │    │                 │         │
│   │  • Session data │    │  • HNSW index   │    │  • Key-value    │         │
│   │  • Memory docs  │    │  • Vector search│    │  • TTL/expiry   │         │
│   │  • State blobs  │    │  • Full-text    │    │  • Pub/sub      │         │
│   └─────────────────┘    └─────────────────┘    └─────────────────┘         │
│                                                                              │
└─────────────────────────────────────────────────────────────────────────────┘

Data Flow

User Message
     │
     ▼
┌─────────────┐  1. append_event()  ┌────────────────────────────────────────┐
│  ADK Agent  │────────────────────▶│  RedisWorkingMemorySessionService      │
└─────────────┘                     │  (BaseSessionService)                  │
     │                              │                                        │
     │                              │  • Stores message in working memory    │
     │                              │  • Tracks token count                  │
     │                              │  • Triggers summarization if needed    │
     │                              └────────────────────┬───────────────────┘
     │                                                   │
     │                                                   │ 2. Background extraction
     │                                                   ▼
     │                              ┌────────────────────────────────────────┐
     │  3. search_memory()          │  RedisLongTermMemoryService            │
     └─────────────────────────────▶│  (BaseMemoryService)                   │
                                    │                                        │
                                    │  • Semantic search across all sessions │
                                    │  • Returns relevant memories           │
                                    │  • Recency-boosted ranking             │
                                    └────────────────────────────────────────┘

Architecture Options

This integration supports two deployment architectures depending on your needs:

Option 1: Two-Tier Architecture (Recommended)

Uses both RedisWorkingMemorySessionService and RedisLongTermMemoryService for full memory capabilities.

┌─────────────┐    store     ┌──────────────────────┐
│  ADK Agent  │─────────────▶│   Working Memory     │
└─────────────┘              │  (current session)   │
     │                       └──────────┬───────────┘
     │                                  │ extract
     │ search                           ▼
     │                       ┌──────────────────────┐
     └──────────────────────▶│   Long-Term Memory   │
                             │  (all sessions)      │
                             └──────────────────────┘
from google.adk_community.sessions import (
    RedisWorkingMemorySessionService,
    RedisWorkingMemorySessionServiceConfig,
)
from google.adk_community.memory import (
    RedisLongTermMemoryService,
    RedisLongTermMemoryServiceConfig,
)

session_service = RedisWorkingMemorySessionService(
    config=RedisWorkingMemorySessionServiceConfig(
        api_base_url="http://localhost:8000",
        default_namespace="my_app",
        context_window_max=8000,
    )
)

memory_service = RedisLongTermMemoryService(
    config=RedisLongTermMemoryServiceConfig(
        api_base_url="http://localhost:8000",
        default_namespace="my_app",
    )
)

Option 2: Long-Term Memory Only

Uses ADK's InMemorySessionService with RedisLongTermMemoryService for simpler deployments.

┌─────────────┐    store     ┌──────────────────────┐
│  ADK Agent  │─────────────▶│   InMemorySession    │
└─────────────┘              │  (volatile)          │
     │                       └──────────────────────┘
     │ search
     │                       ┌──────────────────────┐
     └──────────────────────▶│   Long-Term Memory   │
                             │  (persistent)        │
                             └──────────────────────┘
from google.adk.sessions import InMemorySessionService
from google.adk_community.memory import (
    RedisLongTermMemoryService,
    RedisLongTermMemoryServiceConfig,
)

session_service = InMemorySessionService()

memory_service = RedisLongTermMemoryService(
    config=RedisLongTermMemoryServiceConfig(
        api_base_url="http://localhost:8000",
        default_namespace="my_app",
    )
)

Comparison

Feature Two-Tier Long-Term Only
Session persistence ✅ Redis-backed ❌ In-memory (volatile)
Auto-summarization ✅ When context exceeded ❌ Not available
Context window management ✅ Automatic ❌ Manual
Long-term memory ✅ Semantic search ✅ Semantic search
Memory extraction ✅ Automatic from sessions ✅ Manual via add_session_to_memory()
Setup complexity Higher (2 services) Lower (1 service)
Use case Production, multi-session Prototyping, single-session

Agent Memory Server Features

The following capabilities from the Redis Agent Memory Server are exposed through this integration:

Memory Extraction

The server automatically extracts structured memories from conversations using LLM-based analysis.

Extraction Type Description Example
Facts Objective information about the user "User is a Machine Learning Engineer"
Preferences User likes, dislikes, and preferences "User prefers dark roast coffee"
Episodic Events and experiences "User attended PyCon 2025"

Extraction strategies (configurable via extraction_strategy):

Strategy Behavior
discrete Extract individual facts as separate memories
summary Create a summary of the conversation
preferences Focus on extracting user preferences
custom Use custom extraction prompt

Auto-Summarization

When the context window limit is exceeded, the Working Memory service automatically:

  1. Summarizes older messages
  2. Replaces them with a compact summary
  3. Preserves recent messages for context
config = RedisWorkingMemorySessionServiceConfig(
    context_window_max=8000,  # Token limit before summarization
    model_name="gpt-4o-mini",  # Model for summarization
)

Semantic Search

Long-term memory uses vector embeddings for semantic similarity search:

Feature Description
Vector embeddings OpenAI, Anthropic, Gemini, or Ollama via LiteLLM
HNSW index Redis Stack's high-performance vector index
Distance threshold Filter results by similarity score
Top-K retrieval Configurable number of results
# Search returns MemoryResult objects with relevance scores
results = await memory_service.search_memory(
    app_name="my_app",
    user_id="user123",
    query="What does the user do for work?",
)

Recency Boosting

Balance semantic relevance with temporal freshness:

config = RedisLongTermMemoryServiceConfig(
    recency_boost=True,           # Enable recency boosting
    recency_weight=0.3,           # 30% recency, 70% semantic
    recency_decay_rate=0.01,      # How fast recency decays
)
Parameter Description Default
recency_boost Enable/disable recency boosting True
recency_weight Weight for recency vs semantic (0.0-1.0) 0.3
recency_decay_rate Exponential decay rate for older memories 0.01

Deduplication

The server automatically detects and merges similar memories:

  • Prevents duplicate facts from accumulating
  • Merges related information into unified memories
  • Configurable similarity threshold

Multi-User Support (Namespaces)

Isolate memories by application and user:

config = RedisLongTermMemoryServiceConfig(
    default_namespace="my_app",  # Application-level isolation
)

# User-level isolation via user_id in search
results = await memory_service.search_memory(
    app_name="my_app",
    user_id="user123",  # User-specific memories
    query="...",
)

Feature Summary

Feature Working Memory Long-Term Memory
Message storage
Session state
Auto-summarization
Context window management
Memory extraction ✅ (triggers) ✅ (stores)
Semantic search
Recency boosting
Deduplication
TTL support
Namespace isolation

Related Issues

Testing

Unit Tests

pytest tests/unittests/sessions/test_redis_working_memory_session_service.py -v
pytest tests/unittests/memory/test_redis_long_term_memory_service.py -v

All 23 tests pass with mocked agent-memory-client dependencies.

Manual E2E Testing

Prerequisites:

# Start Redis Stack
docker run -d --name redis-stack -p 6379:6379 redis/redis-stack:latest

# Start Agent Memory Server
docker run -d --name agent-memory-server -p 8000:8000 \
  -e REDIS_URL=redis://host.docker.internal:6379 \
  -e OPENAI_API_KEY=your-openai-key \
  redislabs/agent-memory-server:latest \
  agent-memory api --host 0.0.0.0 --port 8000 --task-backend=asyncio

Test conversation:

Session 1:

User: Hi, I'm Nitin. I'm a Machine Learning Engineer.
User: I love coffee, especially from Berliner Kaffeerösterei.

Session 2 (new session):

User: What do you remember about me?
Agent: [Recalls name, profession, coffee preference from long-term memory]

Additional Notes

  • Async support — Both services are fully async, compatible with ADK's async runtime
  • Lazy loadingagent-memory-client is only imported when the services are instantiated
  • Configuration classes — Both services use Pydantic config classes for validation
  • Recency boosting — Long-term memory search supports configurable semantic/recency weighting
  • Extraction strategies — Supports discrete, summary, preferences, and custom extraction

Requirements

  • Python 3.10+ (required by agent-memory-client)
  • Redis Stack (for vector search)
  • Agent Memory Server (Docker recommended)
  • OpenAI API key (for embeddings, or configure alternative provider)

E2E Test Screenshot
Screenshot 2026-01-27 at 14 38 31
Screenshot 2026-01-27 at 14 39 40

nkanu17 and others added 17 commits January 12, 2026 23:23
…egration

Implement RedisAgentMemoryService class that integrates with the Redis
Agent Memory Server for production-grade long-term memory capabilities.

Features:
- Two-tier memory architecture (working memory + long-term memory)
- Configurable extraction strategies (discrete, summary, preferences)
- Recency-boosted semantic search with configurable weights
- Namespace and user filtering support
- Lazy client initialization with proper error handling

The service implements the ADK BaseMemoryService interface with:
- add_session_to_memory(): Stores session events in working memory
- search_memory(): Retrieves relevant memories with semantic search
- close(): Properly closes the client connection
Add RedisAgentMemoryService and RedisAgentMemoryServiceConfig to the
public exports of the google.adk_community.memory module.
Add agent-memory-client>=0.13.0 as an optional dependency under the
redis-agent-memory extra. Install with:
  pip install 'google-adk-community[redis-agent-memory]'
Add comprehensive unit tests covering:
- Configuration validation and defaults
- Session to memory conversion
- Memory search with recency boosting
- Error handling for missing dependencies
- Client lifecycle management

All 14 tests pass with mocked MemoryAPIClient.
Add a complete sample demonstrating RedisAgentMemoryService usage:
- main.py: FastAPI server with URI scheme registration
- redis_agent_memory_agent/: Sample agent with memory tools
- README.md: Setup and usage documentation

The sample shows how to:
- Register the redis-agent-memory:// URI scheme
- Configure extraction strategies and recency boosting
- Use memory tools (load_memory, preload_memory) with the agent
…ryService

- Rename redis_agent_memory_service.py to redis_long_term_memory_service.py
- Rename class to better reflect its purpose (long-term memory storage)
- Update imports and exports in __init__.py
- Rename test file accordingly
- No functional changes
- Implement BaseSessionService using Redis Agent Memory Server
- Support session CRUD operations via working memory API
- Add auto-summarization and context window management
- Add configuration options (namespace, model, extraction strategy)
- Unit tests
…m memory

- Use RedisWorkingMemorySessionService for session management
- Use RedisLongTermMemoryService for persistent memory
- Add README with setup instructions
@google-cla
Copy link

google-cla bot commented Jan 27, 2026

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.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @nkanu17, 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 framework by integrating Redis Agent Memory Server-based services. It provides robust, production-ready solutions for agent session management and long-term memory, moving beyond volatile in-memory options. Agents can now leverage persistent, auto-summarizing sessions and semantic search capabilities for long-term knowledge retention, supported by a flexible two-tier memory architecture.

Highlights

  • New Redis Agent Memory Services: Introduced RedisWorkingMemorySessionService for persistent session management with auto-summarization and RedisLongTermMemoryService for persistent memory with semantic search and recency boosting. These services offer production-ready, self-hosted alternatives to in-memory solutions.
  • Optional Dependency Integration: Added agent-memory-client as an optional dependency (redis-agent-memory) in pyproject.toml, allowing users to install Redis memory capabilities only when needed.
  • Comprehensive Sample Agents: Included two new sample agents (redis_agent_memory and redis_agent_memory_wo_working_session) demonstrating both the full two-tier memory architecture and a long-term memory-only setup.
  • Enhanced Memory Features: The new services expose advanced features from the Redis Agent Memory Server, including LLM-based memory extraction (facts, preferences, episodic), auto-summarization, semantic search with HNSW indexing, recency boosting, deduplication, and multi-user namespace isolation.

🧠 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.

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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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

  1. 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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 significant and valuable feature by adding Redis-based memory services for session and long-term memory. The implementation is robust, well-documented, and includes comprehensive sample code and unit tests. The code quality is high, with good use of modern Python features and error handling. I've provided a few minor suggestions to further improve robustness in the sample code, fix some typos in documentation, and enhance consistency in the new services.

nkanu17 and others added 3 commits January 27, 2026 15:17
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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.

2 participants