Welcome to the memory and session management tutorial! This tutorial teaches you how to create AI agents that can remember conversations, maintain context, and provide personalized experiences across multiple interactions.
Sign in to save downloads to your library and vote.
Preview
π§ Tutorial 5: Memory Agents - Sessions, State & Events
Welcome to the memory and session management tutorial! This tutorial teaches you how to create AI agents that can remember conversations, maintain context, and provide personalized experiences across multiple interactions.
π― What You'll Learn
- Session Management: How agents maintain conversation context
- State Persistence: Storing and retrieving conversation data
- Event Tracking: Understanding conversation flow and history
- Memory Types: In-memory, database, and cloud-based memory solutions
- Personalization: Creating agents that remember user preferences
π§ Core Concepts
1. Sessions - The Conversation Container
A Session is like a conversation thread that keeps track of all interactions between a user and an agent.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SESSION LIFECYCLE β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β CREATE βββββΆβ ACTIVE βββββΆβ CLOSED β β
β β SESSION β β CONVERSATIONβ β SESSION β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β β β β
β βΌ βΌ βΌ β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β User ID β β Events β β Memory β β
β β Created β β State β β Stored β β
β β Timestamp β β History β β Archived β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Example: When you start chatting with a travel agent, a session is created. All your questions about flights, hotels, and preferences are stored in that session.
2. State - The Current Context
State represents the current context and data that the agent needs to remember during a conversation.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SESSION STATE β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββ β
β β USER STATE β β AGENT STATE β β APP STATE β β
β βββββββββββββββββββ€ βββββββββββββββββββ€ βββββββββββββββ€ β
β β β’ User ID β β β’ Agent Name β β β’ Session IDβ β
β β β’ Preferences β β β’ Current Task β β β’ Timestamp β β
β β β’ History β β β’ Tools Used β β β’ Status β β
β β β’ Context β β β’ Memory β β β’ Metadata β β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Example: A travel agent's state might include:
- User's preferred destinations
- Budget constraints
- Travel dates
- Previous recommendations
3. Events - The Conversation History
Events are individual interactions that make up the conversation history.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β EVENT FLOW β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β USER βββββΆβ AGENT βββββΆβ RESPONSE β β
β β MESSAGE β β PROCESSING β β GENERATED β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β β β β
β βΌ βΌ βΌ β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β Event Type: β β Event Type: β β Event Type: β β
β β user_input β β processing β β response β β
β β Timestamp β β Timestamp β β Timestamp β β
β β Content β β Duration β β Content β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Example Event Sequence:
- User Event: "I want to go to Paris"
- Agent Event: Processing request, checking preferences
- Response Event: "Great! I see you prefer luxury hotels. Here are some options..."
4. Session Runtime Flow
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SESSION RUNTIME FLOW β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β 1. SESSION CREATION β
β βββββββββββββββ β
β β User starts βββββΆ Create Session with User ID β
β β conversationβ Initialize State & Memory β
β βββββββββββββββ β
β β
β 2. CONVERSATION LOOP β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β User βββββΆβ Agent βββββΆβ Update β β
β β Input β β Processes β β State β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β β β β
β βΌ βΌ βΌ β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β Record β β Use Context β β Store β β
β β Event β β & Memory β β Response β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β
β 3. SESSION CLOSURE β
β βββββββββββββββ β
β β User ends βββββΆ Save Final State β
β β conversationβ Archive Session β
β βββββββββββββββ Store in Memory Bank β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Tutorial Structure
This tutorial is divided into three progressive levels:
-
5_1_in_memory_conversation - Basic session management
- InMemorySessionService for temporary conversations
- Simple state management
- Event tracking basics
-
5_2_persistent_conversation - Database persistence
- DatabaseSessionService with SQLite
- Persistent state storage
- Conversation history across sessions
π οΈ Prerequisites
Before starting this tutorial, ensure you have:
- Python 3.11+ installed
- Google AI API Key from Google AI Studio
- SQLite (usually comes with Python)
- Basic understanding of databases (for tutorial 5_2)
π How to Use This Course
Each tutorial follows a consistent structure:
- README.md: Concept explanation and learning objectives
- agent.py: Contains the agent implementation
- requirements.txt: Dependencies for the tutorial
- app.py: Streamlit web interface (where applicable)
Learning Approach:
- Read the README to understand the memory concept
- Examine the code to see session management implementation
- Run the example to see memory in action
- Experiment by having multi-turn conversations
- Move to the next tutorial when ready
π― Tutorial Features
Each tutorial includes:
- β Clear concept explanation
- β Minimal, working code examples
- β Real-world use cases
- β Step-by-step instructions
- β Memory persistence demonstration
π Next Steps
After completing this tutorial, you'll be ready for:
- Advanced Agent Patterns - Multi-agent systems
- Custom Memory Implementations - Building your own memory services
- Production Deployment - Scaling memory agents
π‘ Pro Tips
- Start Simple: Begin with in-memory sessions before moving to persistence
- Test Conversations: Have multi-turn conversations to see memory in action
- Monitor State: Use the ADK web interface to inspect session state
- Plan Memory Strategy: Choose the right memory service for your use case
Ingestion metadata
- Source catalog
- awesome-llm-apps
- Repository
- Shubhamsaboo/awesome-llm-apps Β· main
- File path
- ai_agent_framework_crash_course/google_adk_crash_course/5_memory_agent/README.md
- Last refreshed
- 7/24/2026, 3:00:13 AM (51m ago)
- Refresh schedule
- Daily Β· 03:00 UTC
- Dedupe status
- Unique Β· deduped by (source, url)