Skip to content

feat(memory): add LangMemMemoryService with semantic and episodic extraction - #116

Open
miyannishar wants to merge 1 commit into
google:mainfrom
miyannishar:feat/langmem-memory-service
Open

feat(memory): add LangMemMemoryService with semantic and episodic extraction#116
miyannishar wants to merge 1 commit into
google:mainfrom
miyannishar:feat/langmem-memory-service

Conversation

@miyannishar

@miyannisharmiyannishar commented Apr 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds LangMemMemoryService — a BaseMemoryService implementation backed by LangMem and any LangGraph BaseStore, providing self-hosted long-term memory with semantic search for ADK agents.

This addresses the long-term memory portion of #46 (Tier 2: persistent facts, semantic search, cross-session persistence). The session service portion (Tier 1: working memory with auto-summarization and context window management) is not included here — that would require wrapping the Redis Agent Memory Server client and is a separate effort.

Changes

  • src/google/adk_community/memory/langmem_memory_service.py — full implementation
  • tests/unittests/memory/test_langmem_memory_service.py — 21 unit tests with async mock infrastructure
  • src/google/adk_community/memory/__init__.py — export LangMemMemoryService
  • pyproject.toml — add langmem optional dependency group

Design Decisions

ConcernApproach
BackendAccepts any LangGraph BaseStoreInMemoryStore for dev, AsyncPostgresStore for production
Extraction modelUser-provided model string (e.g. "openai:gpt-4o-mini", "google:gemini-2.0-flash")
Memory tiersDual-tier: semantic (user facts/preferences) + episodic (tool call narratives)
Episodic opt-outenable_episodic=False skips episodic extraction for simpler use cases
Namespacing(*prefix, user_id, "semantic"|"episodic") — fully configurable prefix
Sensitive dataDefault extraction prompts instruct LLM to omit credentials
Error handlingPartial failures logged, not raised — one tier failing doesn't block the other
Optional dependencylangmem + langgraph only required via pip install google-adk-community[langmem]

Usage

fromlanggraph.store.memoryimportInMemoryStorefromgoogle.adk_community.memoryimportLangMemMemoryServicestore=InMemoryStore(
index={"dims": 1536, "embed": "openai:text-embedding-3-small"}
)
memory_service=LangMemMemoryService(
store=store,
extraction_model="openai:gpt-4o-mini",
)
# Use with ADK Runnerrunner=Runner(
app_name="my_app",
agent=agent,
memory_service=memory_service,
)

Test Plan

pip install google-adk-community[langmem,test]
pytest tests/unittests/memory/ -v
  • 21 unit tests covering extraction, search, namespace scoping, error handling, and edge cases
  • All tests pass without LangMem installed (full mock infrastructure)
  • Existing memory tests unaffected

Related: #46 (long-term memory only — session service is a separate effort)

…raction
Add a self-hosted, LangMem-backed memory service that provides semantic
and episodic long-term memory for ADK agents.
Features:
- Dual-tier memory: semantic (user facts/preferences) + episodic (tool
call narratives), with episodic opt-out via enable_episodic=False
- Backend-agnostic: accepts any LangGraph BaseStore (InMemoryStore for
dev, AsyncPostgresStore for production)
- Configurable extraction model, namespace prefix, and instructions
- Automatic sensitive data exclusion in default extraction prompts
- Graceful error handling with partial failure support
Components:
- langmem_memory_service.py (~320 lines)
- 21 async unit tests
- Optional [langmem] dependency group in pyproject.toml
Related: google#46
@DeanChensj

Copy link
Copy Markdown
Collaborator

@gemini-cli /review

@github-actions

Copy link
Copy Markdown

🤖 Hi @DeanChensj, I've received your request, and I'm working on it now! You can track my progress in the logs for more details.

@github-actionsgithub-actionsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for the PR! This is a solid implementation of LangMemMemoryService. The dual-tier approach (semantic + episodic) is well-designed, and the test coverage is impressive.

I've left a few minor suggestions regarding robustness in message extraction and search result sorting. Most of these are edge-case considerations.

Overall, great work!

Sign up for freeto 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

@miyannishar@DeanChensj