tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Generative AI > Google Gemini API > Agent Engine Managed Sessions

Agent Engine Managed Sessions

Author: Venkata Sudhakar

When you run an ADK agent locally, InMemorySessionService stores conversation history in RAM and it disappears when the process ends. In production on Vertex AI Agent Engine, sessions are managed by the cloud service automatically. The same user can send messages hours or days apart and Agent Engine maintains the full conversation context between calls, even as your backend scales across multiple instances. This managed session infrastructure is one of the core enterprise features that differentiates Agent Engine from a bare container deployment.

Agent Engine sessions work transparently when you deploy via AdkApp - every call to async_stream_query with the same user_id and session_id resumes the same conversation. You can also explicitly manage sessions via the API: list sessions for a user, retrieve full conversation history, create sessions with pre-loaded state, and delete sessions when resolved. This is essential for customer service applications where agents need to remember context, and for compliance where you must audit every conversation turn the agent had with a customer.

The below example demonstrates multi-turn session continuity where the agent remembers context across turns, then shows the session management API for listing, reading, and creating sessions with pre-loaded customer state.


It gives the following output showing session continuity and isolation,

Turn 1: Initial query
Agent: Your ACC-1001 balances:
       Savings: Rs 45,200.50 | Current: Rs 12,800 | FD: Rs 1,00,000
       Anything specific you want to know about these accounts?

Turn 2: Follow-up (agent remembers ACC-1001 from Turn 1)
Agent: Your Fixed Deposit of Rs 1,00,000 is earning at PrimBank FD rates.
       At the current 1-year rate of 7.25% you would earn approximately
       Rs 7,250 per year. Would you like to know the maturity date?

Turn 3: Different session - agent has NO memory of Turn 1
Agent: I would be happy to help! Could you please share your account ID
       so I can look up your Fixed Deposit balance for you?

# Turn 2: agent knew "ACC-1001" and "FD" from Turn 1 in the SAME session
# Turn 3: new session = clean slate, agent asks for account ID again
# In production on Agent Engine: sessions persist across server restarts

Session management API output showing enterprise session controls,

Sessions for customer-priya-001
 - session-apr-01      updated: 2025-04-01 14:32:18
 - session-mar-15      updated: 2025-03-15 09:18:44

New session with pre-loaded state: session-abc123
Events in session: 0
Session deleted after resolution

# State injection: agent starts session already knowing the customer name,
# account ID, and last issue - no need for the customer to repeat anything
# list_sessions + get_session = full audit trail for compliance teams

Agent Engine managed sessions are the production-grade replacement for InMemorySessionService. The key production patterns: use a consistent session_id per customer support ticket so all messages about one issue stay in one session; inject customer context via create_session state at the start of each support interaction so the agent greets customers by name; archive or export session history to your data warehouse after sessions close for analytics and compliance; set a maximum session length policy and create a new session after 50 turns to keep context focused. Session state persists indefinitely until deleted - implement a cleanup job to delete sessions older than your retention policy.


 
  


  
bl  br