Skip to main content

google-adk-memorysync

Long-term memory for Google ADK (Agent Development Kit), backed by MemorySync — a real BaseMemoryService whose ingestion methods actually store your sessions, powering ADK's native load_memory / preload_memory tools with durable, cross-session, cross-app memory.

  • MemorySyncMemoryService — all four BaseMemoryService methods implemented: add_session_to_memory, add_events_to_memory, add_memory, search_memory. Plug it into Runner(memory_service=...) and ADK's own memory tools just work.
  • MemorySyncContextTool — guaranteed memory injection before every turn plus automatic user-turn persistence, no memory-tool calls left to model discretion.
  • create_memory_callbacks — an after_model_callback that persists assistant turns.
  • Five agent tools — add, search, list, update, delete; they never raise.
  • Async helpersget_memory_context, search_memories, save_turn.
pip install google-adk-memorysync google-adk

Set MEMORYSYNC_API_KEY in the environment (create a key at app.memorysync.io), or pass api_key explicitly. Python 3.10+, google-adk 2.x.

The memory service

from google.adk.agents import LlmAgent
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService
from google.adk.tools import preload_memory
from google_adk_memorysync import MemorySyncMemoryService

memory_service = MemorySyncMemoryService()  # reads MEMORYSYNC_API_KEY

agent = LlmAgent(
    name="assistant",
    model="gemini-2.5-flash",
    instruction="You are a helpful assistant.",
    tools=[preload_memory],  # ADK's native tool — our service powers it
)

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

# ... after a conversation, ingest the session:
session = await runner.session_service.get_session(
    app_name="support", user_id="customer-7", session_id=session_id
)
await memory_service.add_session_to_memory(session)

The next run — any session, any process, any deploy — preload_memory injects what MemorySync knows about the user before the model call.

Ingestion is real. add_session_to_memory persists every completed text turn (streaming partial chunks, tool traffic and authorless events are skipped) and raises on failure — a memory service that silently drops sessions is data loss behind a green pipeline. Re-ingesting the same session converges instead of duplicating: every event carries an idempotency seed derived from its ADK event id.

Incremental ingestion. add_events_to_memory(app_name=..., user_id=..., events=[...]) persists events as they happen and converges with a later whole-session add_session_to_memory — same seeds on both paths, each event stored exactly once.

Search never raises. search_memory returns proper MemoryEntry objects (content, author, timestamp, custom_metadata.memory_id) so ADK's preload_memory formatter renders them natively; failures degrade to an empty response through on_error.

Scoping. By default the same user's memory follows them across ADK apps (that's the point of a memory service); pass scope_to_app=True to silo each app_name.

Guaranteed context injection

ADK's load_memory leaves recall to model discretion and preload_memory only injects — nothing persists turns as they happen. The context tool does both:

from google_adk_memorysync import MemorySyncContextTool

agent = LlmAgent(
    name="assistant",
    model="gemini-2.5-flash",
    instruction="You are a helpful assistant.",
    tools=[MemorySyncContextTool()],  # inject memory + persist user turns
)

Before every turn it recalls relevant memories for tool_context.user_id and appends them to the request instructions — once per invocation, even when a multi-tool turn makes several model calls. After injection it persists the user's message (persist=False for read-only). Outages degrade to a memoryless turn through on_error, never a crashed one.

Pair it with the assistant-side callback for a full loop with zero manual calls:

from google_adk_memorysync import MemorySyncContextTool, create_memory_callbacks

agent = LlmAgent(
    name="assistant",
    model="gemini-2.5-flash",
    instruction="You are a helpful assistant.",
    tools=[MemorySyncContextTool()],
    **create_memory_callbacks(),  # after_model_callback persists assistant turns
)

All surfaces share the same idempotency seeds, so mixing the service, the tool and the callbacks cannot double-store a turn.

Agent tools

from google_adk_memorysync import create_memorysync_tools

agent = LlmAgent(
    name="assistant",
    model="gemini-2.5-flash",
    instruction="Use the memory tools to remember durable facts.",
    tools=create_memorysync_tools(user_id="customer-7"),
)

# Untrusted agents: search + list only.
create_memorysync_tools(user_id="customer-7", read_only=True)

add_memory, search_memory, list_memories, update_memory, delete_memory — the same five operations, same response strings as the MemorySync LangChain, AI SDK, CrewAI, Mastra, OpenAI Agents and LlamaIndex tool sets. Plain async callables that ADK auto-wraps as FunctionTools; failures return short readable strings, never exceptions.

Helpers

from google_adk_memorysync import get_memory_context, save_turn, search_memories

context = await get_memory_context("what should I cook?", user_id="customer-7")
hits = await search_memories("dietary preferences", user_id="customer-7")
await save_turn(user_id="customer-7", user="I'm vegetarian", assistant="Noted!")

save_turn raises on failure — an explicit persist call is owed the truth.

Version support

Package Requires Runtime
google-adk-memorysync 1.0.0 google-adk >=2,<3 Python 3.10+

CI drives a REAL ADK Runner — native preload_memory end to end, repeated-ingestion convergence, partial-event filtering, per-invocation injection dedup — against the latest google-adk 2.x release on every push.

Documentation

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_memorysync-1.0.0.tar.gz (18.2 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_memorysync-1.0.0-py3-none-any.whl (24.4 kB view details)

Uploaded Python 3

File details

Details for the file google_adk_memorysync-1.0.0.tar.gz.

File metadata

  • Download URL: google_adk_memorysync-1.0.0.tar.gz
  • Upload date:
  • Size: 18.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.9

File hashes

Hashes for google_adk_memorysync-1.0.0.tar.gz
Algorithm Hash digest
SHA256 98f7c23f2d5a8f2cfacf7ce5eb22ccaf40883266b1bcaccf269a8b28ab764dcf
MD5 dee9da53c10770393d83f78c2b5621b1
BLAKE2b-256 1bd5bf406829fcf0a875a94d66a951a3257b69a96577f68d3d25f9bb14d429b8

See more details on using hashes here.

File details

Details for the file google_adk_memorysync-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for google_adk_memorysync-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6788012c3d8e4e24838366c1fe3558586acf56340209fea10eda240f63881498
MD5 3c786d2dfbf32af0e390f5bda1a9ab9a
BLAKE2b-256 cc329ef6d29febefb0a43a57c40d5b1a1fe8decec7865fd88c47a24c9c49c822

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page