tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Agentic AI > ADK Agent Testing > Testing ADK Agent Built-in Memory Service

Testing ADK Agent Built-in Memory Service

Author: Venkata Sudhakar

ShopMax India's ADK agents use the built-in MemoryService to remember facts across conversations: a returning customer's preferred city, their last order, and their opted-in communication preference. Testing the MemoryService API ensures that facts written in one session are correctly retrieved in later sessions, that memory search returns the most relevant fact for a given query, and that stale or irrelevant memories do not contaminate responses for different customers.

ADK's MemoryService provides add_session_to_memory() to index a completed session and search_memory() to retrieve relevant facts. In tests, use an in-memory implementation that stores session facts as a list and searches by keyword match. Assert that the service indexes the correct facts from a session, that search returns the right fact for a given query, and that facts from one customer do not appear in searches for another customer's user ID.

The example below implements a fake MemoryService for ShopMax India. A session containing a customer's city preference is indexed. Tests verify that searching by user ID retrieves the correct fact, that cross-user isolation holds, and that the most recent fact takes precedence when multiple facts match.


It gives the following output,

.... (4 passed in 0.01s)

In production, ShopMax India should limit the number of facts stored per customer to 50 most recent entries to prevent memory bloat as customers interact over months. Use semantic similarity rather than keyword match for search so that queries like "where does the customer live" match "Preferred city: Mumbai" even without the word city. Purge memory facts when a customer requests data deletion under DPDP (Digital Personal Data Protection) Act compliance, and log every memory read with the session ID for the audit trail.


 
  


  
bl  br