Your AI agent is forgetful. Here’s how to give it a brain.
Google Cloud Tech
0:00 MARTIN OMANDER: Hi, agent.
0:01 I'm planning a two-day trip to Tokyo, and I love historic sites.
0:06 ANNIE WANG: Great.
0:07 I'll plan a visit to the imperial palace.
0:09 MARTIN OMANDER: Perfect.
0:10 Can you send me the itinerary, agent?
0:13 ANNIE WANG: Hi.
0:14 How can I help you plan a trip today?
0:15 MARTIN OMANDER: What?
0:16 [CHUCKLING] ANNIE WANG: Yeah.
0:19 This is a goldfish memory problem.
0:22 So even if our AI agent is brilliant,
0:25 it will look dumb if it doesn't remember anything.
0:28 And let's see how we can fix that.
0:30 [MUSIC PLAYING] MARTIN OMANDER: Welcome back to the show, Annie.
0:41 What's your story at Google?
0:43 ANNIE WANG: Oh, thanks, Martin.
0:44 I spent years as a software engineer here,
0:47 but I realized that my real passion is AI education.
0:51 So now, I'm over on the other side, helping developers, building AI agents.
0:55 MARTIN OMANDER: Yeah.
0:56 And you've been deep in the world of AI agents, right?
0:59 ANNIE WANG: Yeah.
1:00 I've noticed a pattern.
1:01 Everyone thinks AI intelligence is just about model and tooling.
1:06 And they're forgetting the other important piece that is memory.
1:10 MARTIN OMANDER: Guilty.
1:11 I definitely focus on the model first when I'm building AI apps.
1:14 ANNIE WANG: Yeah.
1:15 Most people do.
1:16 But if you want to build an app that actually impresses people,
1:19 you need an agent that uses a full brain.
1:23 And here, we have six patterns for adding agent memories.
1:26 Let's talk about each one and when you should use it.
1:30 I also built a Codelab for this so that you can try it out yourself.
1:33 MARTIN OMANDER: OK.
1:34 We'll add a link to your Codelab, Annie.
1:36 Let's dive in.
1:37 ANNIE WANG: All right.
1:38 So when you talk with a person,
1:40 it will be weird if they forgot what you just told them a minute ago, right?
1:44 So the same goes for agents.
1:47 That's why your agent needs sessions to hold all the conversation history.
1:52 MARTIN OMANDER: Makes sense.
1:53 And how do you implement that?
1:55 ANNIE WANG: Yeah.
1:55 If you're using Google Agent Development Kit, ADK, it's fairly easy.
2:00 Just create and use a session object.
2:04 MARTIN OMANDER: So now the agent will remember where the user wants to go?
2:07 ANNIE WANG: Yeah.
2:08 And let's try it.
2:09 As you can see, I will enter that I
2:12 am going to Tokyo and that I like historical sites.
2:18 And then, I will ask for an itinerary.
2:22 And you can see that the agent will give a plan for each day.
2:27 And after I confirm for each day,
2:29 it will eventually give me the three-days plan.
2:33 MARTIN OMANDER: And it worked.
2:34 ANNIE WANG: Yay.
2:34 MARTIN OMANDER: The agent does not have the memory of a goldfish anymore.
2:38 ANNIE WANG: Yeah.
2:38 So session is the most basic type of agent memory.
2:42 But in complex apps, you often have a team of agents working together.
2:47 MARTIN OMANDER: So the agents, they need to share memory between them somehow?
2:51 ANNIE WANG: Yeah, exactly.
2:52 So here is we use state to share context among agents.
2:58 And that state is basically a shared digital folder for the entire session.
3:04 And here is an example.
3:06 I will ask for the best sushi in Palo Alto.
3:10 And behind the scene, there is a foodie agent that finds a restaurant
3:15 and a navigation agent that gets direction to it.
3:20 You can see the state value on the ADK web UI.
3:24 MARTIN OMANDER: And what does the code look like for this?
3:26 ANNIE WANG: Sure.
3:27 Here is the definition of the foodie agent.
3:31 And here's the definition of the transportation agent.
3:35 Martin, do you see the destination string in both of them?
3:38 MARTIN OMANDER: Mm-hmm, I do.
3:39 ANNIE WANG: Yeah?
3:40 So the foodie agent saves its result to the key called destination.
3:45 And then, the transportation agent uses
3:47 that key in its prompt with curly brackets.
3:49 MARTIN OMANDER: OK.
3:50 So we have two agents.
3:52 How do we now put them together?
3:54 ANNIE WANG: So we create a route agent of type, sequential agent,
3:57 that calls the foodie agent first and the navigation agent second.
4:01 MARTIN OMANDER: OK.
4:02 So our agents are now talking to each other.
4:04 But what happens if I close the app or the server reboots?
4:08 ANNIE WANG: Oh, that would be total memory loss.
4:11 Everything we've done so far has been in-memory.
4:14 If the script stops, the agent forgets that you ever existed.
4:18 MARTIN OMANDER: Oh, no!
4:20 And how do we make memory stick between restarts?
4:23 ANNIE WANG: So we swap the in-memory session service for a persistent database.
4:27 By using a database session service,
4:30 the agent can look back at the conversations you had days,
4:34 weeks, or even months ago.
4:35 MARTIN OMANDER: And I'm guessing that's how we get that personal assistant feel?
4:40 It remembers my preferences over time?
4:43 ANNIE WANG: Exactly.
4:44 And here is how to implement it.
4:46 So first, we retrieve the old session from the session service.
4:51 And then, we build a previous context from the session object.
4:56 And now that we have the previous context, we can add it to the query.
5:01 MARTIN OMANDER: Very nice.
5:02 ANNIE WANG: Yeah.
5:03 And those were the first three ways of giving your agent memory.
5:08 Let's talk about the other three in our next video.
5:11 MARTIN OMANDER: Excellent, Annie.
5:12 Can you give us a quick recap, please?
5:15 ANNIE WANG: Of course, Martin.
5:16 So first, we use session memory to hold a conversation without forgetting.
5:21 And secondly, we use multi-agent state to share notes between agents.
5:27 And lastly, we use persistence to remember things even after a system reboots.
5:32 MARTIN OMANDER: That's a great list.
5:34 Thank you for sharing this with us, Annie.
5:36 And I guess we'll see each other in the next video.
5:38 ANNIE WANG: Yeah.
5:39 Thanks for having me, Martin.
5:40 MARTIN OMANDER: And thank you, everyone, for watching.
5:43 If you have any questions for Annie or me, please let us know in the comments.
5:47 Also, do let me know what you thought of today's episode.
5:51 I read every single comment.
5:54 Until next time.
5:55 [MUSIC PLAYING]