Remember this: Agent state and memory with ADK
Skills:
Agent Foundations90%Tool Use & Function Calling80%Multi-Agent Systems60%Autonomous Workflows50%
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
I’m going for it #GoogleCloudCertified
Google Cloud Tech
I had to get #GoogleCloudCertified
Google Cloud Tech
Be better overall at what you do #GoogleCloudCertified
Google Cloud Tech
Cloud Monitoring on our radar #Analysis #Uptime
Google Cloud Tech
Introduction to Generative AI Studio
Google Cloud Tech
How to use Github Actions with Google's Workload Identity Federation
Google Cloud Tech
Introduction to Responsible AI
Google Cloud Tech
Networking updates and CDMC-certified architecture
Google Cloud Tech
Create and use a Cloud Storage bucket
Google Cloud Tech
How to digitize text from documents
Google Cloud Tech
Faster analytical queries with AlloyDB
Google Cloud Tech
Next ‘23 sessions and FaaS Wave
Google Cloud Tech
Introduction to Assured Open Source Software
Google Cloud Tech
BigQuery Cost Optimization: Storage
Google Cloud Tech
BigQuery Cost Optimization: Compute
Google Cloud Tech
BigQuery Cost Optimization: Select Queries
Google Cloud Tech
Remote Field Equipment Management with Manufacturing Data Engine
Google Cloud Tech
Supercharging your applications with Cloud SQL Enterprise Plus
Google Cloud Tech
Vector Support on our radar #GenAI
Google Cloud Tech
Architecting a blockchain startup with Google Cloud
Google Cloud Tech
Kubernetes and multitasking updates!
Google Cloud Tech
GKE: Using Kubernetes Events
Google Cloud Tech
How to configure firewall rules for Cloud Composer
Google Cloud Tech
Vertex AI Embeddings API + Matching Engine: Grounding LLMs made easy
Google Cloud Tech
Geospatial analytics on our radar #EarthEngine #BigQuery
Google Cloud Tech
Ensuring requests are set in Kubernetes
Google Cloud Tech
Cloud Next 2023, Google research program, and more!
Google Cloud Tech
How to migrate projects between organizations with Resource Manager
Google Cloud Tech
How to run #MySQL in Google Cloud
Google Cloud Tech
#GenerativeAI for enterprises and #Next2023
Google Cloud Tech
How Google Photos scales to store 4 trillion photos and videos
Google Cloud Tech
Google Cross-Cloud Interconnect (Demo 2)
Google Cloud Tech
GKE Cost Optimization Golden Signals: Introduction
Google Cloud Tech
GKE Cost Optimization Golden Signals: Workload Rightsizing
Google Cloud Tech
GKE Load Balancing: Overview
Google Cloud Tech
GKE Load Balancing: Best Practices
Google Cloud Tech
Disaster Recovery in GKE
Google Cloud Tech
How to configure IP masquerade agent in GKE Standard clusters
Google Cloud Tech
Enable and use GKE Control plane logs
Google Cloud Tech
Compliance in Australia with Assured Workloads
Google Cloud Tech
Creating budgets and budget alerts in Google Cloud #FinOps
Google Cloud Tech
Cloud SQL Enterprise Plus on our radar #mySQL
Google Cloud Tech
What's Next for Google Cloud?
Google Cloud Tech
How Loveholidays scaled with Contact Center AI
Google Cloud Tech
What is fleet team management in GKE?
Google Cloud Tech
Troubleshoot VPC Network Peering
Google Cloud Tech
Introduction to DocAI and Contact Center AI
Google Cloud Tech
Cloud Run Direct VPC egress explained
Google Cloud Tech
Database deployment options in GKE
Google Cloud Tech
Analyze cloud billing data with #BigQuery
Google Cloud Tech
Tips to becoming a world-class Prompt Engineer
Google Cloud Tech
Serverless is simple. Do I need CI/CD?
Google Cloud Tech
Accelerating model deployment with MLOps
Google Cloud Tech
How Hawaii's Department of Human Services scaled with CCAI
Google Cloud Tech
Pricing API on our #Radar
Google Cloud Tech
How Recommendations AI for Media can boost customer retention
Google Cloud Tech
Troubleshooting: Node Not Ready Status
Google Cloud Tech
One weekend until Cloud Next 2023!
Google Cloud Tech
#GoogleCloudNext starts tomorrow!
Google Cloud Tech
#GoogleCloudNext will be demand!
Google Cloud Tech
More on: Agent Foundations
View skill →Related Reads
📰
📰
📰
📰
FLUX 3 Learned to Predict Movement. Now the Factory Has to Give It Hands
Medium · AI
Stop your Grok 4.5 agents from blowing past the context window
Dev.to · Christo
More AI Agents Don’t Always Mean Better Results: What Google DeepMind’s Latest Research Reveals
Medium · Machine Learning
How to run Hermes, a self-improving personal AI agent, fully local with QVAC
Dev.to · Thomas
🎓
Tutor Explanation
DeepCamp AI