Latest / AI Fire Daily / #71 Max: Unlock the Next Evolution of Agents with Human-like Memory (n8n + Zep)
Transcript
- 0:00So imagine you're talking to someone, right?
- 0:04And maybe five minutes after you tell them your
- 0:06name, they forget it. Oh, yeah. Or, you know,
- 0:08you poured your heart out last week about your
- 0:10big life goals, and today, blank stare, like
- 0:14you've never even met. It's kind of like that
- 0:16movie Memento. but for your AI assistant. Exactly.
- 0:20Honestly, that's probably the biggest thing holding
- 0:22AI agents back right now, this goldfish memory
- 0:26problem. Most just have this tiny temporary buffer.
- 0:29It really stops them from becoming true partners,
- 0:31doesn't it? Or collaborators. Definitely. Welcome
- 0:34to the Deep Dive. Today we're... taking a plunge
- 0:38into fixing that, giving AI real, actual, long
- 0:41-term memory. And it's not just about remembering
- 0:43the last two chat messages, not at all. No, it's
- 0:46much bigger than that. It's about building AIs
- 0:47that genuinely understand you. You know, your
- 0:50preferences, past talks, goals. That's how they
- 0:52give you that really personal evolving help.
- 0:54So our mission today is to unpack this core problem.
- 0:57We're going to look at how these relational knowledge
- 1:00graphs, something like this open source tool
- 1:02called Zep, can offer a real solution. Zep's
- 1:06basically a database made for AI memory. Exactly.
- 1:10And we're going to walk you through how this
- 1:11memory gets built from scratch. And the big one.
- 1:15How you do it without racking up some crazy huge
- 1:18bill from your AI provider. Yeah, the cost thing
- 1:21is key. We'll also get into some advanced tricks,
- 1:24the ethics side of things, privacy. Super important.
- 1:27And even give you a kind of four week plan to
- 1:30try this yourself. The goal is you'll understand
- 1:32how to take your AI agents from, well, forgetful
- 1:35assistants to really powerful collaborators.
- 1:38All right, let's get to it. So when you first
- 1:40start with an AI agent, its memory is. Well,
- 1:42pretty basic. Mm -hmm. Very basic. It usually
- 1:44just remembers the last few things said, maybe
- 1:46five to 15 messages back and forth. It's all
- 1:48in this temporary digital space. If you say,
- 1:51hi, my name is AI Fire, sure, it can say your
- 1:53name back. But, and this is the crucial part,
- 1:56the fatal flaw, really, it's just reading a transcript.
- 2:00The AI isn't learning anything deep. It's just
- 2:02looking back a few lines. So if the chat goes
- 2:04on too long. Or you start a new one later. Yeah.
- 2:07Poof. That old context is just gone. It doesn't
- 2:10understand AI fire as a person. It just knows
- 2:13those words were typed recently. It remembers
- 2:16the words, not the person. Okay, so contrast
- 2:19that with real long -term memory. What does that
- 2:21look like? Maybe I ask, hey, remind me about
- 2:24that Paris trip plan from last month. Yeah. And
- 2:26the agent, without you feeding in any details
- 2:28again, just comes back with, sure, here's that
- 2:30personalized plan for John Doe's Paris trip next
- 2:32month. Duration. Budget. Around $2 ,000. It pulls
- 2:37John Doe and the budget from its stored knowledge.
- 2:40Not from what I just typed. Exactly, from deep
- 2:42storage. Learn stuff. That difference, remembering
- 2:45words versus actually understanding a person,
- 2:47that seems huge. What's the fundamental difference
- 2:50there, inside the AI? It's remembering recent
- 2:53chat versus deeply understanding you. Okay, so
- 2:56how does it know all that stuff then? The John
- 2:58Doe details, the budget, the trip. It's this
- 3:02relational knowledge graph you mentioned. Yep,
- 3:04that's the core of it. And it's not just a simple
- 3:06list of facts. Think of it more like a mind palace,
- 3:10or maybe a really detailed visual map of how
- 3:13knowledge connects. For every single user, it's
- 3:15like their own personal Wikipedia. It stores
- 3:18facts, identifies the key things, the entities,
- 3:21like John Doe or Paris, and crucially, it maps
- 3:24the relationships between them, like John Doe
- 3:27plans trip to Paris. And I guess as you talk
- 3:29more, that map gets... Dense exactly grows new
- 3:33things get added like maybe the musee door say
- 3:35and new connections like John Doe is interested
- 3:37in art museums Interesting and it's not just
- 3:39the connections each thing in the graph each
- 3:42entity like John Doe or Hotel Paris Central Gets
- 3:44its own little summary generated by the AI something
- 3:48like John Doe user planning Paris trip budget
- 3:52$2 ,000 so this structured brain lets the AI
- 3:55quickly scan for the key ideas and links, makes
- 3:58its answers way faster and smarter, because it
- 4:01doesn't have to reread tons of old chat logs.
- 4:03So how does this mind map make the AI smarter,
- 4:05essentially? It's a structured brain for quick,
- 4:08precise knowledge retrieval. Let's try to picture
- 4:10this starting from zero. Imagine a totally new
- 4:13user. Let's call him Max. He talks to the agent
- 4:16for the first time. He says, my name is Max.
- 4:18I enjoy hiking, and I currently live in Vancouver,
- 4:20Canada. OK, boom. Instantly, behind the scenes,
- 4:24Zep kicks in. It creates a main thing, an entity,
- 4:27Max. Right. Then it starts drawing lines, the
- 4:29relationships. Yeah. Max likes hiking. Max lives
- 4:31in Canada. Maybe even AI assistant A's chatting
- 4:35with Max. It's like stacking Lego blocks of data,
- 4:39building up that context piece by piece. And
- 4:41then Max shares more. The graph gets richer.
- 4:44Maybe he adds, I usually hike on weekends. My
- 4:46favorite trail is Grousegrind. I also like taking
- 4:49photos of nature, but I'm not a pro photographer
- 4:51yet. OK. Graph expands again almost instantly.
- 4:54New lines, Max favorite trail, grouse grind,
- 4:58Max enjoys nature photos, Max skill level amateur
- 5:01photographer, and a new entity pops up, grouse
- 5:05grind, tagged as a hiking trail, Max likes. Okay,
- 5:08now for the payoff, the intelligence test. Max
- 5:10asks, got any ideas for what I could do this
- 5:13Saturday? Right, and the agent doesn't just give
- 5:15some generic stuff, it queries that knowledge
- 5:18graph it just built about Max. It pulls the pieces
- 5:21together. Just the size, is it? Yeah. The response
- 5:23might be something like, hi Max. Okay, since
- 5:26you like hiking and nature photos, here are some
- 5:28ideas for Saturday. One, hike a new trail, maybe
- 5:31try a different Vancouver trail, mix it up from
- 5:34Grau's Grind, like Lynn Canyon or Cypress Mountain.
- 5:37Ah, see, that's the magic, isn't it? It combined
- 5:40totally separate facts, the hiking, the photos,
- 5:42the location, his usual spot to give a really
- 5:44personalized recommendation. It didn't just recall,
- 5:47it connected things. Absolutely. What's the magic
- 5:49when the graph grows? Agent combines diverse
- 5:51facts for truly personalized results. So, this
- 5:55all sounds amazing, right? This AI that actually
- 5:57gets you. But, oh, here's the catch. The thing
- 6:00people don't always talk about up front. There's
- 6:02always a catch. As that memory gets smarter and
- 6:04deeper, Every single check can get way way more
- 6:08expensive. Ah the cost why it comes down to tokens
- 6:11That's how most AI models charge you think of
- 6:14a token as like roughly a word or sometimes part
- 6:17of a word Okay Every time you send a message
- 6:19the agent doesn't just send your message to the
- 6:21big brain the large language model or LLM It
- 6:25bundles up this whole context package. What's
- 6:27in the package usually a summary of you? the
- 6:30user, plus relevant facts pulled from that Knowledge
- 6:32Graph we talked about, and maybe the last few
- 6:34messages from the chat. Gotcha. So in our simple
- 6:36max example, asking about Saturday, how many
- 6:40tokens was that? Believe it or not, around 2
- 6:43,727 tokens, just for that simple question. Now,
- 6:46scale that up. Imagine a loyal customer you've
- 6:49interacted with for months. Their Knowledge Graph
- 6:51might have hundreds of facts. That context package
- 6:53could easily hit 3 ,000, 5 ,000, maybe even 10
- 6:56,000 tokens per message. Okay, let's do the math.
- 7:00If it's, say, 0 .002 tons per thousand tokens.
- 7:03Right. 3 ,000 tokens is 0 .006 cents. Six tenths
- 7:08of a cent. Doesn't sound like much. Quite. But
- 7:11if you have 1 ,000 users chatting daily... That's
- 7:14$6 a day, $180 a month, just for the memory piece.
- 7:18And that can easily balloon into thousands if
- 7:20your graph gets really big or you have lots of
- 7:22users. So why does having a smart AI memory get
- 7:24so expensive? AI models charged by tokens and
- 7:28long context uses many. Right. So the million
- 7:31dollar question, or maybe the thousand dollar
- 7:33a month question. How do we get this powerful
- 7:35memory without going broke? Method one. Smart
- 7:39context filtering the surgical approach as you
- 7:41called it. Yeah, because a lot of the off -the
- 7:43-shelf memory tools They kind of act like a blunt
- 7:45instrument. They just grab everything all the
- 7:47facts all the history It's frankly often just
- 7:49lazy engineering. Okay. So what's the fix? You
- 7:51got to take control instead of pulling everything
- 7:53blindly you use direct HTTP requests basically
- 7:56specific web commands to be like a surgeon You
- 7:59precisely select only the relevant info. So you're
- 8:01telling the system just give me the last 10 messages
- 8:03Exactly. Or, show me only the top three facts
- 8:07from the long -term memory that are really relevant
- 8:09to this specific question. Maybe you even add
- 8:11a filter, like ignore anything less than 70 %
- 8:14relevant. Okay, contrast the flows. Standard
- 8:17flow. User message block. Grab all facts plus
- 8:20entire history directs that stuff it all into
- 8:22the LLM. wasteful, super wasteful, optimized
- 8:25flow, user message block, targeted requests for
- 8:29say last 10 messages, smart search requests for
- 8:32top three relevant long -term facts, merge that
- 8:35small relevant package, then send to LLM. Much
- 8:38leaner, faster, focused. Totally. And you can
- 8:41get clever with the search query itself. Maybe
- 8:43use the LLM first to refine the user's raw message
- 8:45into a better search term before you even hit
- 8:47the knowledge graph. And I know you mentioned
- 8:49using tools like N8n's code node to handle some
- 8:52of the data formatting. That can be tricky. Oh,
- 8:54yeah. I mean, I still wrestle with prompt drift
- 8:56myself sometimes when trying to get AI to structure
- 8:58complex JSON data perfectly. It's not always
- 9:01easy. You might ask Claude or another AI to help
- 9:03write the JavaScript snippet to clean it up.
- 9:05That's a good tip. So the results of this surgical
- 9:08approach? Dramatic. Like we saw, you can go from
- 9:11maybe 2 ,700 tokens per interaction down to around
- 9:14670. Wow, that's a huge drop. Yeah, like a 76
- 9:17% reduction. Cuts your API costs by more than
- 9:20half. Easy. So how exactly does this surgical
- 9:24approach cut costs so dramatically? By sending
- 9:27only highly relevant filtered data to the AI.
- 9:30OK, method one sounds great. But sometimes, even
- 9:33being surgical hits a wall, right? You mentioned
- 9:36some APIs make it hard to get history in the
- 9:39right order. Yeah, exactly. Some systems, maybe
- 9:41they give you the whole history, but oldest first.
- 9:43So to get the last 10 messages, you have to pull
- 9:46everything and sort it yourself. Kind of defeats
- 9:48the purpose of being efficient. So that leads
- 9:50to method two, hybrid memory architecture. Right.
- 9:53The best of both worlds approach. The core idea
- 9:56is super simple, but really powerful. Different
- 9:58kinds of data belong in different kinds of databases.
- 10:00You know, you wouldn't use a hammer for a screw.
- 10:02Makes sense. So what's the two brains set up
- 10:05here? OK, so for your long term memory, that
- 10:07complex web of facts and relationships, you stick
- 10:10with Zep's knowledge graph. That's its superpower.
- 10:13It's built for that. Got it. And for short term.
- 10:15For the recent conversation history, the last
- 10:1810, 20 messages, use a standard Simple database
- 10:22like Postgresql. It's super fast and really efficient
- 10:25for just storing ordered lists with timestamps.
- 10:27Perfect for recent chat history. Ah, okay. So
- 10:30you get the deep understanding from Zepp, but
- 10:32the lightning fast recall of recent stuff from
- 10:35Postgresql. Exactly. The best of both worlds.
- 10:38How does the flow work then? Message comes in.
- 10:40Message arrives. Then at the same time, you fire
- 10:43off two requests. One API call to Zepp for the
- 10:46top. say three relevant long -term facts, and
- 10:49D, a super quick query to PostgreSQL for the
- 10:51last 10 messages. Okay, parallel requests. Yep.
- 10:54Then you quickly merge those two small relevant
- 10:56context packages together, send that combined
- 10:59package to the LLM. And after the LLM replies?
- 11:02You update both memories. Add the new exchange
- 11:04to PostgreSQL and let Zep process it to update
- 11:07the knowledge graph if needed. Let's picture
- 11:09it. User asks something complex like, where should
- 11:11I move? I need a place that fits my interest.
- 11:13Right. An agent with this hybrid setup can give
- 11:17a really nuanced answer. It uses ZEP, the long
- 11:20-term brain, to pull facts like enjoys hiking,
- 11:23knows about Lynn Canyon Park, interested in photography,
- 11:25and it uses Postgresco, the short -term brain,
- 11:28for the immediate context, like the user just
- 11:30mentioned, my future, or thinking about change.
- 11:33It combines both for a personalized insight without
- 11:36wasting tokens on stuff that's not relevant right
- 11:38now. What's the main advantage of this hybrid
- 11:41two -brain approach, then? It combines deep relational
- 11:45understanding with lightning -fast recent recall.
- 11:48This is where it gets really exciting. Moving
- 11:50from a single demo to something that works for
- 11:52tons of users. The key is session IDs, right?
- 11:55Absolutely. It's fundamental. The whole system
- 11:56hinges on this. Every unique user gets their
- 11:59own unique identifier, the session ID. Think
- 12:03of it as the key to their own private knowledge
- 12:05graph. So this could be their Telegram chat ID.
- 12:07Or their email address if it's an email bot or
- 12:09user account ID from your website. Anything unique
- 12:12to them. And the benefit. Massive scalability.
- 12:15Thousands, even millions of users can be talking
- 12:18to the agent at the same time. But each conversation
- 12:21is totally separate. Max's knowledge graph doesn't
- 12:24leak into mics. It's completely isolated. That's
- 12:27how you go from a chat bot to a real AI workforce.
- 12:30Think about the applications. Customer support.
- 12:32Oh, yeah. An agent that remembers your entire
- 12:34purchase history, pass support tickets, even
- 12:37your preferred way of communicating. You never
- 12:40have to repeat yourself. It feels like talking
- 12:42to a dedicated account manager who actually knows
- 12:44you. Or an educational tutor. Building a unique
- 12:47learning profile for every single student. Tracking
- 12:50their progress, spotting weaknesses, adapting
- 12:52teaching styles automatically. It's incredibly
- 12:55powerful. The sales assistant. Imagine. Detailed
- 12:58history for every prospect needs, objections
- 13:00raised before, personal interests they mentioned
- 13:02offhand. It's the perfect briefing for the human
- 13:05salesperson stepping in to close the deal. And
- 13:07even just onboarding new users. Remembering exactly
- 13:10where they left off in a complex setup process
- 13:13that could massively reduce churn. People hate
- 13:15starting over. Whoa. Just imagine the impact.
- 13:19A sales agent that knows hundreds of prospects
- 13:22intimately, instantly. or a support agent recalling
- 13:25every single detail. That really scales human
- 13:28-like intelligence. It's a total game changer
- 13:30for the user experience. So how do these AI agents
- 13:33manage to remember so many different users distinctly?
- 13:37Each user has a unique session ID and a private
- 13:40knowledge graph. Okay, so we've got the core
- 13:42methods down. What about taking it to the next
- 13:44level? Pro strategies. Definitely things you
- 13:47can do. For cost optimization, you can play with
- 13:50dynamic relevance scoring. Meaning? Adjusting
- 13:53that relevance threshold. Maybe lower it for
- 13:56creative brainstorming tasks where you want more
- 13:58tangential ideas, but crank it higher for technical
- 14:01support where accuracy is paramount. OK, that
- 14:03makes sense. You can also set up entity prioritization.
- 14:06Tell ZEP, hey, things like pass support ticket
- 14:09ID are way more important than favorite color.
- 14:11So it prioritizes retrieving the critical stuff.
- 14:15Nice. What about old information? Intelligent
- 14:17memory decay. Basically, if a fact hasn't been
- 14:20relevant or accessed in a long time, its important
- 14:22score gradually fades. It stops outdated info
- 14:25from cluttering things up. Smart. And for really
- 14:28big scale. You might look beyond just Postgresql
- 14:30for the short -term memory. Maybe Redis for absolutely
- 14:34blazing fast caching if you have users hitting
- 14:36the same topics repeatedly. Or Elasticsearch
- 14:39if your knowledge graphs become truly enormous.
- 14:42And managing the memory itself. Critical. You
- 14:44need limits. Set a max number of facts per user
- 14:47graph. Have a strategy to archive graphs for
- 14:50inactive users on a cheaper storage. Otherwise,
- 14:53costs and slowdowns are inevitable. It sounds
- 14:55like there are pitfalls, too. What are the common
- 14:57mistakes people make building these? The landmines
- 15:00to avoid. Oh yeah, plenty. Number one is probably
- 15:03over -storing. Saving every tiny detail makes
- 15:05the graph noisy and less useful. Use those relevance
- 15:08thresholds. Prioritize entities. Session ID collisions.
- 15:12Using ideas that aren't truly unique. Disaster.
- 15:15You mix up user data. Always use secure, unique
- 15:18IDs like UIDs or properly hashed identifiers.
- 15:21Unbounded memory growth. Just letting graphs
- 15:24grow forever without limits or archiving leads
- 15:27to slowdowns, ballooning costs, implement those
- 15:30limits. Poor relationship quality. Sometimes
- 15:32the AI extracting facts, it gets it wrong, creates
- 15:35weird or incorrect links like Maxi located in
- 15:38Panama when he's in Vancouver. You need to validate,
- 15:41maybe fine tune the prompts used for extraction.
- 15:44Good point. And the last one. Ignoring token
- 15:46optimization. Just assuming memory is worth any
- 15:49cost. You have to monitor usage and implement
- 15:51filtering like we discussed. Costs can sneak
- 15:54up on you fast. So what are the biggest mistakes
- 15:57people make when building AI memory systems?
- 16:00Over storing data, wrong IDs, unchecked growth,
- 16:03poor data quality, ignoring costs. Building these
- 16:06powerful memory systems isn't just tech though.
- 16:08There's a huge ethical dimension. Absolutely.
- 16:10With great memory comes great responsibility.
- 16:13A system that remembers so much about someone
- 16:15requires you to be a really careful guardian
- 16:18of their privacy. What are the key principles
- 16:19there? Transparency, number one. Tell users the
- 16:23agent remembers things to help them. Something
- 16:26simple like, to improve our chats, I'll remember
- 16:28key details. Goes a long way. And letting users
- 16:31control their data. Crucial. The right to be
- 16:34forgotten, like under GDPR. Users must be able
- 16:37to easily see their data. export it, and most
- 16:40importantly, delete it if they want to. And security,
- 16:42obviously. Non -negotiable. Especially if you're
- 16:45storing anything remotely sensitive, robust security
- 16:47is a must. And you mentioned performance benchmarks
- 16:50earlier. These optimizations aren't just theory,
- 16:53they have real impact. Huge impact. We looked
- 16:55at cost per 1 ,000 interactions. Basics app might
- 16:58be, say, $150 to $240. Okay. Our optimized HTTP
- 17:03filtering method. cuts that way down maybe $60
- 17:06to $90. Big improvement. But the hybrid architecture,
- 17:09that's the winner. We saw a cost between $48
- 17:11and $72. That's a massive saving compared to
- 17:13the basic setup. And user experience improves
- 17:15too. Dramatically. Response times drop from like
- 17:19three eight seconds down to one three seconds.
- 17:22Accuracy jumps from maybe six out of ten to eight
- 17:24point five out of ten. User feedback goes from
- 17:27yeah it's okay to wow this thing actually gets
- 17:30me. And it's fast. So what's the biggest tightrope
- 17:32walk for developers building these powerful AI
- 17:35memories? Balancing advanced memory capabilities
- 17:37with user privacy and data security. OK. So for
- 17:41listeners who are thinking, all right, I want
- 17:42to build this, you put together a kind of four
- 17:44-week plan. Yeah, a practical roadmap to get
- 17:47started. Week one, foundation setup. Meaning?
- 17:50Get Zepp installed. Get PostgreSQL running. Maybe
- 17:53grab a pre -built workflow template. Start having
- 17:55simple chats just to see the graph begin to form.
- 17:57Get the basics working. Week 2. Customization.
- 18:00Start tailoring it to your specific need. Adjust
- 18:02those relevant scores. Maybe define some custom
- 18:04types of entities you care about. And critically,
- 18:07set up proper session ID handling for how your
- 18:09users will connect. Week 3. Optimization. Now,
- 18:12implement those cost -saving tricks. Fine -tune
- 18:15the limits, the relevance filters. Double -check
- 18:17those PostgreSQL queries are running fast. Set
- 18:20up monitoring so you can actually see your token
- 18:23usage and costs. And weak for. Production deployment.
- 18:26Test it hard with simulated users to make sure
- 18:28everyone's data stays separate. Set up backups
- 18:31and a recovery plan. Then you're ready to go
- 18:34live. So the bottom line here, this isn't just
- 18:37about fancy or chatbots. No. Not at all. This
- 18:40is really the foundation for a whole new class
- 18:42of AI agents, agents that can actually form genuine,
- 18:47useful long -term relationships with people.
- 18:49They learn from the past, they understand what
- 18:51makes each user unique, and they provide value
- 18:54that actually gets better over time. Right. The
- 18:56core message is simple. The smartest AI model
- 18:59in the world is basically useless if it can't
- 19:01remember what actually matters to the person
- 19:03it's talking to. And building this kind of memory,
- 19:05this understanding, that's a real edge. Huge
- 19:07competitive advantage. While everyone else is
- 19:09building agents that forget everything tomorrow,
- 19:11you can build agents that learn and grow with
- 19:13your users. It's about remembering what matters,
- 19:16doing it securely and doing it respectfully.
- 19:18So here's a final thought to chew on. As AI gets
- 19:21more and more woven into our lives, how do you
- 19:24think our own human memories might adapt? when
- 19:27we can lean on these agents that, well, never
- 19:30forget. That's a deep question. And what does
- 19:33understanding even mean when an AI can perfectly
- 19:37recall every single thing you've ever said to
- 19:39it? Lots to think about there. We definitely
- 19:41encourage you to explore these possibilities,
- 19:43giving your AI agents memory that's intelligent,
- 19:46affordable, and ethical. That's our deep dive
- 19:48for today. Out, T -Pro Music.