Remember this: Agent state and memory with ADK

Google Cloud Tech · Intermediate ·🤖 AI Agents & Automation ·11mo ago

Key Takeaways

The video demonstrates how to build smarter AI agents using the Agent Development Kit (ADK) on Google Cloud, implementing short-term and long-term memory to remember past conversations and user context. It covers the use of ADK's session concept, state, and memory service, as well as integration with tools like Gemini and Vert.ex AI memory bank.

Full Transcript

Hey everyone, my name is Ann Barrage and I'm a developer relations engineer on the Google Cloud team. Today I want to show you using ADK how you can give your AI agents memory. [Music] Learning new skills is often a journey and learning through conversation is a powerful way to do it. So in this video, we're going to create a Python tutor agent which uses ADK, Google's agent development framework. An ADK has some pretty cool features, one of which we're going to dive into today called memory. So, let's quickly recap some of the key components that make up a basic ADK agent. At its core, an agent has system instructions, which define its personality and goals. It also has a model, which acts as its brain, and a set of tools that act as its hands to perform actions in the world. So to get our Python tutor really working well, we want to give our agent the ability to quiz the user, allowing them to access their knowledge. To do this, we first configure our agent with a detailed system prompt. This is more than just a simple instruction. It's the agent's core identity. We're going to give it a stepbystep quiz management process, telling it exactly how to behave when a user gives a correct or incorrect answer. Next, we give our agent a brain. In this case, we'll use a Gemini 2.5 Flash as the model for reasoning. Then we equip it with tools. These are simply Python functions that give the agent special abilities beyond just talking. We'll give it tools like start quiz, submit answer, and get quiz status. So, it can actually manage the quiz. With these components in place, we actually have a clear quiz flow that starts to emerge. The agent starts the quiz, waits for a response, and then uses its tools to check the answer and fetch the next question, all while following the logic we gave it in the system prompt. It's pretty cool. We put all of these pieces together and define our agent using the LLM agent function provided by ADK. As you can see, we're passing in the model, the system prompt, and the list of tools we created before. This function wraps everything up into a single conversational agent. And voila, we've created a simple AI agent that could teach us Python. Okay, but what if we wanted this agent to remember things like the user's name or their previous quiz score. To create a truly personalized experience, an agent needs to remember past interactions. Firstly, to have our agent remember things within a single conversation, we need to use what ADK calls short-term memory. Let's start with the foundational concept of a session. You can think of an ADK session as one complete continuous phone call between the user and our agent. Every time a user starts a new chat, a new session is created with a unique ID and the session acts as a container. If we look at its anatomy, we can see it holds the session's identification information. The entire back and forth conversational history and most importantly for our purpose is the state. Okay, but what is state exactly? This fate is like the agents, a scratch pad for the current conversation. For our Python tutor, this is where we're going to track the quiz in real time. It's a simple list of key value pairs like curve question index, correct answers, and score percentage. These values are designed to change as the user interacts with the agent. This is really powerful because both the model and the tools that we've given it can actually interact with the state. The Gemini model can read the current score or the question number directly from the system prompt using curly braces like you see here, keeping it aware of the quizzes context. And our tools can actually read from and write to the state as well. When the user answers a question, for example, our submit answer tool gets the current state from the tool context. It then checks the answer and writes the updated score directly back to the state, which the user can see in its next turn. By default, the entire session, including its state, is stored in memory and is lost when the application stops. This is perfect for a temporary scratch pad, but it's still really just short-term. One way to solve this challenge is by introducing a database to store session data. ADK actually comes with a database session service that gives you this exact functionality. With this function, you can store session data in a persistent SQL database like a local SQL light file or a cloud SQL Postgress instance. ADK will set up the session tables plus schemas for you on startup and session data can survive ADK crashes and restarts. It's good for production grade agents, but at the end, this is still just managed session data. What if we wanted our agent to actually have long-term memory? How can we make our agent remember a user score the next time that they come back or topics that they're having challenges with historically while they've been learning Python? Okay, so now we know short-term memory is great for a single quiz, but what happens when you come back tomorrow to continue learning Python? A new session with a new idea is created and temporary scratch pad is gone. To solve this, we need long-term memories so the agent can have context from previous interactions and provide a truly personalized experience for our learners. With long-term memory, our agent is like a tutor who remembers you from previous sessions, including what you learned and where you usually struggle. So, luckily, ADK provides functionality that allows us to do this. One of which is called memory service. This service is responsible for storing and retrieving information across multiple sessions. While there's a simple in-memory version for local development, the real power comes from the Vert.ex AI memory bank service. Instead of just saving entire raw conversations which can become long and tedious, memory bank uses Gemini to intelligently process a conversation and extract and summarize the most important facts. This is efficient because it gives the agent just the key information it needs without overwhelming it with the full chat history. So when we pull it all together and define our final intelligent agent, we use the same LLM agent function from ADK, but now we enhance it with our new memory components. We add our memory instructions to the prompt, include our new search memory tool, and most importantly, we register our autosave to memory callback function that allows memory bank to store the important information. This callback is the key to automating our memory. It'll run after each interaction to save the session's events. So finally, this creates a new, more intelligent flow for our agent. When a conversation starts, the agent follows its new instructions. First, it asks for the user's name so it can personalize the session. Once it has a name, it calls the search memory tool to check for any history with that user. Then it proceeds with the quiz. The crucial final step is the call back. After the quiz is complete, our autos save to memory callback function automatically runs, sending the session to memory bank to be summarized and stored for the future. The result of this is a seamless experience. The agent guides a user, let's say Megan, for example, through the quiz and gives them a final score of 75%. But the magic is what happens under the hood. What did Memory Bank actually save from that session? It didn't just store the raw chat log. Instead, it used its intelligence to process the conversation and extract key summarized facts. My name is Megan. I took a quiz about Python dictionaries and I scored 75% on the dictionaries quiz. You can see how the usage of a smart LLM allows memory bank to store only the relevant most important contextual information for our Python tutor to get its job done. So, let's recap. We've seen how state and memory create more personalized and contextaware agents. For short-term memory, ADK uses a session and its state, which acts as a temporary scratch pad for a single conversation. For long-term memory, ADK uses a memory service. We focused on the Vert.ex AI memory bank, which intelligently summarizes conversations, allowing the agent to recall key facts from past interactions. So now you have the building blocks to go and create your own powerful, personalized, memoryful AI agents. Hope this one helped. See you all in. [Music]

Original Description

Discover how to build smarter, more powerful AI agents that can remember past conversations and user context. In this video, we'll show you how to implement both short-term and long-term memory using the Agent Development Kit (ADK) on Google Cloud. Follow along as we walk through a practical "Python Tutor" agent, demonstrating state management and how to persist data with different storage backends like SQL or Vertex AI. By the end, you'll have the skills to create more intelligent and personalized conversational AI experiences. Check out the source code on GitHub → http://goo.gle/4lHTDOC Read the full blog post → http://goo.gle/3JsC9ID Subscribe to Google Cloud Tech → https://goo.gle/GoogleCloudTech #aiagents #AgentDevelopmentKit #googlecloud #statemanagement #machinelearning #vertexai #adk Speaker: Amit Maraj Products Mentioned: AI Agents, Vertex AI, ADK
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Google Cloud Tech · Google Cloud Tech · 0 of 60

← Previous Next →
1 I’m going for it #GoogleCloudCertified
I’m going for it #GoogleCloudCertified
Google Cloud Tech
2 I had to get #GoogleCloudCertified
I had to get #GoogleCloudCertified
Google Cloud Tech
3 Be better overall at what you do #GoogleCloudCertified
Be better overall at what you do #GoogleCloudCertified
Google Cloud Tech
4 Cloud Monitoring on our radar #Analysis #Uptime
Cloud Monitoring on our radar #Analysis #Uptime
Google Cloud Tech
5 Introduction to Generative AI Studio
Introduction to Generative AI Studio
Google Cloud Tech
6 How to use Github Actions with Google's Workload Identity Federation
How to use Github Actions with Google's Workload Identity Federation
Google Cloud Tech
7 Introduction to Responsible AI
Introduction to Responsible AI
Google Cloud Tech
8 Networking updates and CDMC-certified architecture
Networking updates and CDMC-certified architecture
Google Cloud Tech
9 Create and use a Cloud Storage bucket
Create and use a Cloud Storage bucket
Google Cloud Tech
10 How to digitize text from documents
How to digitize text from documents
Google Cloud Tech
11 Faster analytical queries with AlloyDB
Faster analytical queries with AlloyDB
Google Cloud Tech
12 Next ‘23 sessions and FaaS Wave
Next ‘23 sessions and FaaS Wave
Google Cloud Tech
13 Introduction to Assured Open Source Software
Introduction to Assured Open Source Software
Google Cloud Tech
14 BigQuery Cost Optimization: Storage
BigQuery Cost Optimization: Storage
Google Cloud Tech
15 BigQuery Cost Optimization: Compute
BigQuery Cost Optimization: Compute
Google Cloud Tech
16 BigQuery Cost Optimization: Select Queries
BigQuery Cost Optimization: Select Queries
Google Cloud Tech
17 Remote Field Equipment Management with Manufacturing Data Engine
Remote Field Equipment Management with Manufacturing Data Engine
Google Cloud Tech
18 Supercharging your applications with Cloud SQL Enterprise Plus
Supercharging your applications with Cloud SQL Enterprise Plus
Google Cloud Tech
19 Vector Support on our radar #GenAI
Vector Support on our radar #GenAI
Google Cloud Tech
20 Architecting a blockchain startup with Google Cloud
Architecting a blockchain startup with Google Cloud
Google Cloud Tech
21 Kubernetes and multitasking updates!
Kubernetes and multitasking updates!
Google Cloud Tech
22 GKE: Using Kubernetes Events
GKE: Using Kubernetes Events
Google Cloud Tech
23 How to configure firewall rules for Cloud Composer
How to configure firewall rules for Cloud Composer
Google Cloud Tech
24 Vertex AI Embeddings API + Matching Engine: Grounding LLMs made easy
Vertex AI Embeddings API + Matching Engine: Grounding LLMs made easy
Google Cloud Tech
25 Geospatial analytics on our radar #EarthEngine #BigQuery
Geospatial analytics on our radar #EarthEngine #BigQuery
Google Cloud Tech
26 Ensuring requests are set in Kubernetes
Ensuring requests are set in Kubernetes
Google Cloud Tech
27 Cloud Next 2023, Google research program, and more!
Cloud Next 2023, Google research program, and more!
Google Cloud Tech
28 How to migrate projects between organizations with Resource Manager
How to migrate projects between organizations with Resource Manager
Google Cloud Tech
29 How to run #MySQL in Google Cloud
How to run #MySQL in Google Cloud
Google Cloud Tech
30 #GenerativeAI for enterprises and #Next2023
#GenerativeAI for enterprises and #Next2023
Google Cloud Tech
31 How Google Photos scales to store 4 trillion photos and videos
How Google Photos scales to store 4 trillion photos and videos
Google Cloud Tech
32 Google Cross-Cloud Interconnect (Demo 2)
Google Cross-Cloud Interconnect (Demo 2)
Google Cloud Tech
33 GKE Cost Optimization Golden Signals: Introduction
GKE Cost Optimization Golden Signals: Introduction
Google Cloud Tech
34 GKE Cost Optimization Golden Signals: Workload Rightsizing
GKE Cost Optimization Golden Signals: Workload Rightsizing
Google Cloud Tech
35 GKE Load Balancing: Overview
GKE Load Balancing: Overview
Google Cloud Tech
36 GKE Load Balancing: Best Practices
GKE Load Balancing: Best Practices
Google Cloud Tech
37 Disaster Recovery in GKE
Disaster Recovery in GKE
Google Cloud Tech
38 How to configure IP masquerade agent in GKE Standard clusters
How to configure IP masquerade agent in GKE Standard clusters
Google Cloud Tech
39 Enable and use GKE Control plane logs
Enable and use GKE Control plane logs
Google Cloud Tech
40 Compliance in Australia with Assured Workloads
Compliance in Australia with Assured Workloads
Google Cloud Tech
41 Creating budgets and budget alerts in Google Cloud #FinOps
Creating budgets and budget alerts in Google Cloud #FinOps
Google Cloud Tech
42 Cloud SQL Enterprise Plus on our radar #mySQL
Cloud SQL Enterprise Plus on our radar #mySQL
Google Cloud Tech
43 What's Next for Google Cloud?
What's Next for Google Cloud?
Google Cloud Tech
44 How Loveholidays scaled with Contact Center AI
How Loveholidays scaled with Contact Center AI
Google Cloud Tech
45 What is fleet team management in GKE?
What is fleet team management in GKE?
Google Cloud Tech
46 Troubleshoot VPC Network Peering
Troubleshoot VPC Network Peering
Google Cloud Tech
47 Introduction to DocAI and Contact Center AI
Introduction to DocAI and Contact Center AI
Google Cloud Tech
48 Cloud Run Direct VPC egress explained
Cloud Run Direct VPC egress explained
Google Cloud Tech
49 Database deployment options in GKE
Database deployment options in GKE
Google Cloud Tech
50 Analyze cloud billing data with #BigQuery
Analyze cloud billing data with #BigQuery
Google Cloud Tech
51 Tips to becoming a world-class Prompt Engineer
Tips to becoming a world-class Prompt Engineer
Google Cloud Tech
52 Serverless is simple. Do I need CI/CD?
Serverless is simple. Do I need CI/CD?
Google Cloud Tech
53 Accelerating model deployment with MLOps
Accelerating model deployment with MLOps
Google Cloud Tech
54 How Hawaii's Department of Human Services scaled with CCAI
How Hawaii's Department of Human Services scaled with CCAI
Google Cloud Tech
55 Pricing API on our #Radar
Pricing API on our #Radar
Google Cloud Tech
56 How Recommendations AI for Media can boost customer retention
How Recommendations AI for Media can boost customer retention
Google Cloud Tech
57 Troubleshooting: Node Not Ready Status
Troubleshooting: Node Not Ready Status
Google Cloud Tech
58 One weekend until Cloud Next 2023!
One weekend until Cloud Next 2023!
Google Cloud Tech
59 #GoogleCloudNext starts tomorrow!
#GoogleCloudNext starts tomorrow!
Google Cloud Tech
60 #GoogleCloudNext will be demand!
#GoogleCloudNext will be demand!
Google Cloud Tech

This video teaches how to build smarter AI agents using ADK on Google Cloud, implementing short-term and long-term memory to remember past conversations and user context. It covers the use of ADK's session concept, state, and memory service, as well as integration with tools like Gemini and Vert.ex AI memory bank. By following this lesson, viewers can learn how to create more powerful and personalized AI agents.

Key Takeaways
  1. Configure agent with system prompt
  2. Give agent a brain with Gemini model
  3. Equip agent with tools like start quiz and submit answer
  4. Define agent using LLM agent function provided by ADK
  5. Use short-term memory to have agent remember things within a single conversation
  6. Use ADK's database session service to store session data
  7. Use ADK's memory service to store and retrieve information across multiple sessions
  8. Register an autosave to memory callback function to automate memory saving
💡 The use of ADK's memory service and Vert.ex AI memory bank allows for the creation of personalized and context-aware AI agents that can recall key facts from past interactions.

Related Reads

📰
FLUX 3 Learned to Predict Movement. Now the Factory Has to Give It Hands
FLUX 3, a generative AI model, can predict movement and is being integrated with robotics, requiring the development of physical hands for interaction
Medium · AI
📰
Stop your Grok 4.5 agents from blowing past the context window
Learn to prevent Grok 4.5 agents from exceeding the context window, ensuring efficient conversation handling
Dev.to · Christo
📰
More AI Agents Don’t Always Mean Better Results: What Google DeepMind’s Latest Research Reveals
Google DeepMind's research reveals that adding more AI agents doesn't always lead to better results, highlighting the importance of efficient multi-agent systems design
Medium · Machine Learning
📰
How to run Hermes, a self-improving personal AI agent, fully local with QVAC
Run a self-improving personal AI agent, Hermes, locally with QVAC and learn how it differs from traditional task-oriented AI tools
Dev.to · Thomas
Up next
Build Agentic AI End-to-End Real-Time Projects | 2026
Rajeev Kanth | BEPEC
Watch →