Skip to content

Conversation

@rakshith-git
Copy link
Contributor

Add OpenMemory Service Integration

This PR adds support for OpenMemory, a self-hosted, open-source memory system for AI agents, as a new memory service in ADK Community. OpenMemory provides brain-inspired multi-sector embeddings, graceful memory decay, and server-side filtering for efficient multi-user agent deployments.

Summary

This PR includes:

  1. Core implementation of OpenMemoryService implementing BaseMemoryService interface
  2. Sample agent demonstrating OpenMemoryService integration with auto-save callback
  3. Unit tests for service functionality
  4. Comprehensive documentation in the sample README

Problem

ADK currently supports Vertex AI-based memory services, but users need self-hostable, open-source alternatives for:

  • On-premise deployments with data sovereignty requirements
  • Development/testing without cloud dependencies
  • Cost-effective memory solutions for smaller projects
  • Full control over memory storage and retrieval logic

Solution

OpenMemory fills this gap by providing a production-ready, self-hosted memory backend that integrates seamlessly with ADK's BaseMemoryService interface. This implementation uses direct httpx calls for maximum control and reliability.

Changes

Core Implementation

  • New file: src/google/adk_community/memory/open_memory_service.py

    • OpenMemoryService: Implements BaseMemoryService interface
    • OpenMemoryServiceConfig: Pydantic config model for user-configurable behavior
    • Direct httpx integration (no SDK dependency)
    • Server-side filtering by user_id for multi-tenant isolation
    • Enriched content format embedding author/timestamp metadata in content string
    • Required API key authentication
  • New file: src/google/adk_community/memory/utils.py

    • Utility function for extracting text from events, filtering out thought parts
  • New file: src/google/adk_community/memory/__init__.py

    • Module exports

Sample Agent

  • New directory: samples/open_memory/
    • agent.py: Sample agent with memory tools and auto-save callback
    • README.md: Setup instructions for OpenMemory backend and ADK integration

Tests

  • New directory: tests/unittests/memory/
    • test_open_memory_service.py: Comprehensive unit tests with mocked HTTP client

Dependencies

  • Added: httpx>=0.27.0, <1.0.0 as a core dependency in pyproject.toml

Key Features

  • Store session events: Automatically converts ADK session events to OpenMemory memories
  • Semantic search: Leverages OpenMemory's multi-sector embeddings for retrieval
  • Multi-user isolation: Server-side filtering ensures users only access their own memories
  • App-level filtering: Tag-based filtering for application-specific memory contexts
  • Required API key: Secure authentication with OpenMemory backend
  • Configurable behavior: All parameters exposed as configurable options
    • search_top_k: Number of memories to retrieve (default: 10)
    • timeout: Request timeout in seconds (default: 30.0)
    • user_content_salience: Importance score for user messages (default: 0.8)
    • model_content_salience: Importance score for model responses (default: 0.7)
    • default_salience: Fallback salience value (default: 0.6)
    • enable_metadata_tags: Toggle session/app tagging (default: true)

Technical Decisions

Direct HTTP Integration with httpx

This implementation uses httpx for direct REST API calls rather than a client SDK. This provides:

  • Full control over request/response format
  • Easy to integrate other memory services like Mem0 or zep as they also expose REST API endpoints
  • Minimal dependency footprint
  • Easy debugging and request customization

Enriched Content Format

Since OpenMemory's query endpoint returns lightweight results, we embed author/timestamp directly in content during storage:

[Author: user, Time: 2025-11-04T12:34:56] What is the weather today?

On retrieval, regex parsing extracts this metadata and returns clean content to users. This design:

  • Avoids N+1 API calls for metadata
  • Preserves context information efficiently
  • Maintains compatibility with OpenMemory's performance optimizations

Server-Side Filtering

user_id is passed as a top-level parameter (not metadata) to leverage OpenMemory's indexed database column for fast, secure multi-user isolation.

API Key Authentication

API key is required for all OpenMemory operations, ensuring secure communication with the backend. The service validates that an API key is provided at initialization.

Testing

Unit Tests

All unit tests use mocked httpx.AsyncClient to avoid external dependencies. Tests cover:

  • Adding session events to memory
  • Searching memories with filters
  • Configuration validation
  • Error handling and logging
  • Metadata parsing from enriched content format
  • API key requirement validation

All tests pass:

pytest tests/unittests/memory/test_open_memory_service.py

Installation & Usage

Install dependencies:

pip install google-adk google-adk-community

Setup OpenMemory Backend:

Follow the OpenMemory Quick Start Guide to set up your OpenMemory server.

Configure ADK Agent:

from google.adk_community.memory import OpenMemoryService, OpenMemoryServiceConfig
from google.adk import Agent, Runner

# Create OpenMemory service with API key (required)
memory_service = OpenMemoryService(
    base_url="http://localhost:8080",
    api_key="your-api-key"  # Required
)

# Use with runner
runner = Runner(
    app_name="my_app",
    agent=my_agent,
    memory_service=memory_service
)

See samples/open_memory/README.md for complete setup instructions and examples.

Checklist

  • I have read the CONTRIBUTING.md document
  • I have performed a self-review of my own code
  • I have added tests that prove my feature works
  • New and existing unit tests pass locally with my changes
  • Code follows ADK style guide and conventions

- Implement OpenMemoryService with required API key authentication
- Add comprehensive error handling and logging
- Include metadata tags for app-level filtering
- Add sample agent with auto-save callback for testing
- Update default port to 8080 to match OpenMemory standard
- Add unit tests for service functionality
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @rakshith-git, 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 integrates OpenMemory as a new memory service within ADK Community, offering a self-hostable and open-source alternative to existing cloud-dependent memory solutions. The primary goal is to provide users with greater control over their data, enable on-premise deployments, and offer a cost-effective option for managing AI agent memories. The implementation leverages direct HTTP calls for flexibility and includes features for multi-user isolation and configurable memory behavior, ensuring a seamless and secure experience for various deployment scenarios.

Highlights

  • OpenMemory Integration: Adds OpenMemoryService to ADK Community, providing a self-hosted, open-source memory solution for AI agents, addressing needs for on-premise deployments and data sovereignty.
  • Core Implementation: Introduces OpenMemoryService implementing BaseMemoryService with direct httpx integration, server-side filtering by user_id, and an enriched content format for storing metadata.
  • Sample Agent and Documentation: Includes a new sample agent demonstrating OpenMemoryService integration with an auto-save callback, alongside comprehensive documentation in a dedicated README.
  • Unit Tests: Comprehensive unit tests with a mocked HTTP client cover service functionality, configuration validation, and error handling for robust integration.
  • Dependency Added: httpx is added as a core dependency to facilitate direct, asynchronous HTTP communication with the OpenMemory backend.
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 valuable integration with OpenMemory as a self-hosted memory service for ADK. The implementation is well-structured, including a core service, a Pydantic configuration model, a sample agent, and comprehensive unit tests. The use of httpx for direct API calls is a sound decision, and the error handling appears robust.

My review focuses on improving consistency in configuration, ensuring code examples are clear, and adhering to best practices by avoiding reliance on private attributes. I've also noted a potentially unrelated import that could be cleaned up. Overall, this is a solid contribution that expands the capabilities of ADK Community.

rakshith-git and others added 2 commits November 6, 2025 10:24
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>
@rakshith-git
Copy link
Contributor Author

@hangfei I have moved the PR to this repository

@rakshith-git
Copy link
Contributor Author

Hi team 👋,
Just following up on this PR to check if there’s any additional context or review needed from my side.
This implements the OpenMemoryService integration as discussed in the adk-python PR thread, now migrated to adk-community as suggested.
Happy to make any adjustments needed — just let me know!

@hangfei
Copy link
Collaborator

hangfei commented Nov 9, 2025

Thanks for the contribution! @rakshith-git

Could you share what manual testing(queries and scenarios) you have done? For example, update the memory and retrieve it etc.

@rakshith-git
Copy link
Contributor Author

rakshith-git commented Nov 9, 2025

Thanks for the contribution! @rakshith-git

Could you share what manual testing(queries and scenarios) you have done? For example, update the memory and retrieve it etc.
Here’s a polished Markdown comment you can paste into the PR:


I performed various manual tests to make sure it got the memories and the memories were in the right chronological order
I told things about myself and what i liked and it correctly saved , Preloaded the memories from past conversations using the preload memory tool and also recalled using the load memory tool if it didnt have the memories in the tag

These are the manual tests i performed:

Basic write and recall:

  • hello my name is rakshith and i love gaming
  • I really love fps games like valorant and apex but my favourite is hollow knight
  • my favourite snack is doritos

Then in a new session

  • tell me everything you know about me
  • Agent recalled prior details ( my name, love for gaming and mentioned games ,snacks etc)
Okay, Rakshith, here's everything I know about you:
Your name is Rakshith. You love gaming, especially FPS games like Valorant and Apex. 
Your absolute favorite game is Hollow Knight. 
And your favorite snack is Doritos!

Update / overwrite:

  • i had lied my real name is jack
  • Follow-up queries correctly reflected Jack as the name
image

Missing memory behavior:

  • what is my favourite sport → responds that it has no info
  • then what do i love → recalls You love gaming

note

this implementation is exactly like the vertex ai memory bank in which explicit update of memories is not yet supported but unlike vertex ai memory bank users can have control over how long memories are retained and also can adjust preference for newer memories by configuring openmemory and also can build tools to update using the REST API's provided by openmemory

- Memory tools (`load_memory_tool`, `preload_memory_tool`) for retrieving past conversations
- Auto-save callback that saves sessions to memory after each agent turn
- Time context for the agent to use current time in responses

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you provide one sample query or script to show case how this agent works with memory?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed.


"""Community memory services for ADK."""

from .open_memory_service import OpenMemoryService
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's do lazy loading here. @wuliang229 to help provide some guidance on what's the proper way.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's do it in a separate PR.

@hangfei hangfei merged commit 3b4ebda into google:main Nov 9, 2025
6 checks passed
@hangfei
Copy link
Collaborator

hangfei commented Nov 9, 2025

Thanks for your contribution!

@rakshith-git
Copy link
Contributor Author

Thanks a lot @hangfei I really appreciate the help! 🙏

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