Skip to main content
The MemMachine adapter for the Google Agent Development Kit (ADK) provides a seamless implementation of the BaseMemoryService. This allows your Google GenAI agents to automatically store session events and retrieve relevant context using MemMachine’s hybrid episodic and semantic search.

Overview

By using the MemmachineMemoryService, your ADK agents can:
  • Auto-Archive Sessions: Automatically move completed ADK session events into MemMachine episodic memory.
  • Contextual Recall: Use the standard ADK load_memory tool to query past interactions across different sessions.
  • Scoped Search: Metadata like app_name and user_id are automatically preserved to ensure privacy and relevance.

Configuration

The adapter is configured via constructor arguments when initializing the service.
ParameterDescriptionDefault
api_keyRequired. Your MemMachine API Key.N/A
endpointThe MemMachine v2 REST API URL.https://api.memmachine.ai/v2
org_idYour organization identifier.None
project_idYour project identifier.None

1

Install with ADK Extra

To ensure all Google GenAI and ADK dependencies are included, install the client with the google-adk extra:
pip install "memmachine-client[google-adk]"
2

Initialize the Memory Service

Create an instance of the MemmachineMemoryService. This service acts as the bridge between Google ADK and your memory backend.
from memmachine.integrations.google_adk.memmachine_memory_service import MemmachineMemoryService

memory_service = MemmachineMemoryService(
    api_key="YOUR_API_KEY",
    endpoint="http://localhost:8080/api/v2", # Use for self-hosted
    org_id="my-org",
    project_id="my-project"
)
3

Equip the Agent

Add the standard load_memory tool to your LlmAgent. This allows the agent to decide when it needs to “look back” at past conversations to answer a query.
from google.adk.agents import LlmAgent
from google.adk.tools import load_memory

agent = LlmAgent(
    model="gemini-2.0-flash",
    name="MemoryAgent",
    instruction="Use the 'load_memory' tool if the answer is in past conversations.",
    tools=[load_memory]
)
4

Wire the Runner

Connect your agent, session service, and the MemMachine memory service into a Runner.
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService

runner = Runner(
    agent=agent,
    app_name="my_adk_app",
    session_service=InMemorySessionService(),
    memory_service=memory_service
)

Memory Lifecycle

Persistence

To move a session from active memory into long-term storage (so it can be recalled by other sessions), call add_session_to_memory once a conversation is finished:
# completed_session is a google.adk.sessions.session.Session object
await memory_service.add_session_to_memory(completed_session)

Retrieval

When the agent invokes load_memory, the adapter automatically filters results based on the app_name and user_id defined in the Runner, ensuring the agent only recalls information relevant to the current user.
Important: The ADK integration requires Python 3.10+ and the google-adk extra package. If you encounter import errors, verify that you have installed memmachine-client[google-adk].