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 Agents with Firestore Session Persistence

Testing ADK Agents with Firestore Session Persistence

Author: Venkata Sudhakar

ShopMax India uses Firestore to persist ADK agent session state across service restarts and horizontal scaling - ensuring a customer in Chennai who starts a return request on one pod can seamlessly continue on another. Testing Firestore session persistence verifies that state written during one agent invocation is correctly read back in the next, and that Firestore-specific behaviors like document TTL and partial updates work as expected in the agent context.

To test Firestore-backed ADK sessions without a live database, use a mock Firestore client that stores documents in memory and mirrors the Firestore API: set, get, update, and delete by document path. Assert that the session service writes to the correct collection and document path, that subsequent reads return the persisted state, and that TTL fields are written correctly. This approach runs fast in CI without Firestore credentials.

The example below implements a mock Firestore client and a Firestore-backed session service for ShopMax India. Tests verify write path correctness, state persistence across reads, partial updates via merge, and TTL field presence on every written document.


It gives the following output,

... (3 passed in 0.01s)

In production, ShopMax India should use Firestore TTL policies to automatically delete expired sessions without a manual cleanup job. Index the session collection on customer ID so support agents can look up all active sessions for a given customer. Use Firestore transactions when updating session state concurrently to prevent write conflicts during the Diwali sale when thousands of customers update their carts simultaneously.


 
  


  
bl  br