Skip to main content
Integrate Mem0 with Google ADK (Agent Development Kit), an open-source framework for building multi-agent workflows. This integration enables agents to access persistent memory across conversations, enhancing context retention and personalization.

Overview

In this guide, we’ll create a Google ADK agent that:
  1. Uses ADK’s native MemoryService interface to connect Mem0
  2. Automatically injects relevant memories using ADK’s built-in load_memory tool
  3. Persists session history to Mem0 after each turn via an after-agent callback
  4. Shares memory seamlessly across multi-agent hierarchies

Setup and Configuration

Install the necessary libraries:
Set up your API keys:
Remember to get your API key from Mem0 Platform and set up a Google AI Studio API Key.

Implement Mem0MemoryService

Create a custom MemoryService by implementing ADK’s BaseMemoryService. Save the following as mem0_memory_service.py:

Add Auto-Save Callback

This after-agent callback fires at the end of every turn and saves the session to Mem0. Save as memory_callbacks.py:

Basic Integration Example

The following example demonstrates creating an ADK agent with automatic Mem0 memory:

Multi-Agent Hierarchy with Shared Memory

Because memory_service is passed to the Runner, every agent in the hierarchy shares the same memory automatically. Only the root coordinator needs the auto-save callback: ADK fires it once when the full turn completes:

Key Features

  1. Automatic Memory Injection: ADK’s built-in load_memory tool searches Mem0 at the start of each turn and injects relevant memories directly into the agent context. No prompt instructions are needed.
  2. Automatic Session Saving: The save_session_to_memory callback persists every completed turn to Mem0 without any manual calls.
  3. Native ADK Integration: Mem0MemoryService implements ADK’s BaseMemoryService and integrates via the Runner. It works natively across the entire agent hierarchy.
  4. User Scoping: user_id is passed automatically from the ADK session context, ensuring memories are always scoped to the correct user.
  5. Multi-Agent Support: A single Mem0MemoryService instance shared through the Runner gives all agents, coordinators and specialists, access to the same user memory.

Configuration Options

Using Vertex AI

To use Google Cloud Vertex AI instead of AI Studio, set the following environment variables before creating agents:

Advanced Memory Filtering

You can customize how memories are searched by modifying Mem0MemoryService.search_memory. For example, to filter by category:
InMemorySessionService stores sessions in memory and is intended for prototyping. For production, use a persistent session service and clean up sessions when they are no longer needed.

Conclusion

By implementing Mem0MemoryService as an ADK BaseMemoryService, you get persistent, user-scoped memory across single agents and complex multi-agent hierarchies with minimal code. Memory injection and session saving happen automatically, keeping your agent prompts clean and your token usage efficient.

Healthcare Agent Cookbook

Build HIPAA-compliant healthcare agents with Google ADK

OpenAI Agents SDK

Compare with OpenAI’s agent framework
Using Mem0? Star us on GitHub to help more developers discover memory for AI apps.