ADK Plugin: Memory
Overview
Section titled “Overview”The ADK Memory services provide ADK-compatible memory implementations that integrate with FloTorch’s memory infrastructure.
Exports:
FlotorchMemoryService– Traditional memory search using FloTorch MemoryFlotorchADKVectorMemoryService– Vector-based memory search using FloTorch VectorStore
from flotorch.adk.memory import FlotorchMemoryService, FlotorchADKVectorMemoryService
API_KEY = "<your_api_key>"BASE_URL = "https://gateway.flotorch.cloud"PROVIDER = "<flotorch_memory_provider>"VECTORSTORE_ID = "<your_vectorstore_id>"Memory Services
Section titled “Memory Services”FlotorchMemoryService
Section titled “FlotorchMemoryService”FlotorchMemoryService( name: str, base_url: str | None = None, api_key: str | None = None,)Uses FloTorch Memory for traditional memory operations.
add_session_to_memory(…) -> None
Section titled “add_session_to_memory(…) -> None”async def add_session_to_memory(self, session: Session) -> NoneAdds an ADK session to FloTorch memory with automatic role mapping and content extraction.
search_memory(…) -> SearchMemoryResponse
Section titled “search_memory(…) -> SearchMemoryResponse”async def search_memory( self, *, app_name: str, user_id: str, query: str) -> SearchMemoryResponseSearches memory using FloTorch Memory with user/app filtering.
FlotorchADKVectorMemoryService
Section titled “FlotorchADKVectorMemoryService”Constructor:
FlotorchADKVectorMemoryService( api_key: str, base_url: str, vectorstore_id: str | None = None,)Uses FloTorch VectorStore for semantic memory search.
search_memory(…) -> SearchMemoryResponse
Section titled “search_memory(…) -> SearchMemoryResponse”async def search_memory( self, query: str, knn: int | None = None, **kwargs) -> SearchMemoryResponsePerforms vector-based semantic search with optional KNN parameter.
Features
Section titled “Features”Role Mapping
Section titled “Role Mapping”Automatically maps ADK roles to FloTorch expected roles:
model/assistant/agent/bot/ai→assistantuser/human/person→usersystem→systemtool→tool
Content Extraction
Section titled “Content Extraction”Robustly extracts text content from ADK Content and Part objects.
Error Handling
Section titled “Error Handling”- Graceful fallbacks on content extraction failures
- Empty responses on search errors instead of exceptions
Usage Example
Section titled “Usage Example”from google.adk.runner import Runner
# Traditional memorymemory_service = FlotorchMemoryService( name="mem0", base_url=BASE_URL, api_key=API_KEY)
# Vector memoryvector_memory = FlotorchADKVectorMemoryService( api_key=API_KEY, base_url=BASE_URL, vectorstore_id=VECTORSTORE_ID)
# Use with Runnerrunner = Runner( agent=agent, memory_service=memory_service # or vector_memory)- Memory services are designed to work seamlessly with ADK’s
Runner - Vector memory requires a configured vector store in FloTorch
- Both services handle ADK session and event objects automatically