<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Viraj Mhadgut | Msc Data Science on Medium]]></title>
        <description><![CDATA[Stories by Viraj Mhadgut | Msc Data Science on Medium]]></description>
        <link>https://medium.com/@virajmhadgut77?source=rss-8db646a55038------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ntpQK7j1tDMQq1Q4MncwBA.jpeg</url>
            <title>Stories by Viraj Mhadgut | Msc Data Science on Medium</title>
            <link>https://medium.com/@virajmhadgut77?source=rss-8db646a55038------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 10:33:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@virajmhadgut77/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Your AI Agent Has Amnesia: Agent Memory Design Visual Guide]]></title>
            <link>https://medium.com/@virajmhadgut77/your-ai-agent-has-amnesia-agent-memory-designvisual-guide-6faac6144a5b?source=rss-8db646a55038------2</link>
            <guid isPermaLink="false">https://medium.com/p/6faac6144a5b</guid>
            <category><![CDATA[agentic-ai-memory]]></category>
            <category><![CDATA[agentic-ai]]></category>
            <category><![CDATA[agentic-ai-architecture]]></category>
            <category><![CDATA[agentic-ai-systems]]></category>
            <category><![CDATA[agentic-ai-framework]]></category>
            <dc:creator><![CDATA[Viraj Mhadgut | Msc Data Science]]></dc:creator>
            <pubDate>Fri, 09 Oct 2026 17:38:57 GMT</pubDate>
            <atom:updated>2026-10-09T17:46:43.397Z</atom:updated>
            <content:encoded><![CDATA[<p>On Monday, a patient named Priya chats with a dental clinic’s AI booking assistant. She says she’s allergic to penicillin, she likes morning appointments, and she’d like a cleaning with Dr. Rao. The assistant books October 14 at 9:00.</p><p>The next Tuesday she opens a new chat and asks: <em>“Why isn’t my cleaning on the 14th anymore?”</em></p><p>The assistant has no idea who Priya is. It can’t say what she booked, why it moved, or that she’s allergic to penicillin. It may guess, and a guess can sound fine, which is worse.</p><p>Nothing is broken. The real question is where Monday’s and Wednesday’s knowledge was supposed to live. I’ll use this one dental booking agent all the way through.</p><h3>What does the model actually see?</h3><p><em>A basic chatbot. Everything inside the dashed box lives and dies with one session.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yyLqTjtrVNJYdQNCMsPauw.png" /></figure><p>Each time Priya sends a message, the app builds a prompt from three things: her message, the chat so far, and the clinic’s instructions. The model reads that prompt and writes a reply. Anthropic’s docs describe the context window as everything the model can look at when it writes a reply, separate from the data it was trained on [1]. Anything outside that block doesn’t exist for the model during that call.</p><p>I’ll call the step that builds the prompt context assembly. The prompt it builds is the working memory. Once the agent has long-term memory, one prompt might look like this:</p><pre>[system]     You are the booking assistant for Bright Smile Dental.<br>             Check the calendar before confirming any time.<br>[retrieved]  Fact: Priya is allergic to penicillin.<br>[retrieved]  Fact: Priya&#39;s next visit is a cleaning on Oct 16, 9:00.<br>[retrieved]  Episode, Oct 7: moved cleaning from Oct 14 to Oct 16<br>             at Priya&#39;s request (traveling on the 14th).<br>[history]    ...last few turns of this chat...<br>[user]       Why isn&#39;t my cleaning on the 14th anymore?</pre><p>First, the window is not a database. It is built fresh for each call and holds only what the app puts in it. The app can store whole conversations, and ending a session doesn’t have to delete them. They just aren’t in the window unless something puts them there.</p><p>Second, more isn’t always better. The same docs say accuracy and recall can get worse as the context grows, so what you put in matters as much as how much fits [1]. “Include everything” is a weak plan.</p><p>You can think of the window as RAM and stored memory as a disk. That breaks at one point: a computer can read any file from disk when it wants, but a model can only read what you put in front of it. Fetching the right memory is your code’s job.</p><h3>Not everything belongs in the same memory</h3><p>If something outside the window must remember things, what kinds of things? Priya’s two chats produced three kinds, and each behaves differently.</p><p>The names come from the CoALA paper on organizing language agents [2].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oAIQqF8Hnz7vaw8wu5wglQ.png" /></figure><p><em>The three kinds of long-term memory, and how each one reaches the prompt.</em></p><p><strong>Procedural memory</strong> is how the agent should work. “Check the calendar before confirming a time.” “Ask for name and date of birth before changing a booking.” “Don’t give medical advice; hand over to staff.” This often lives in plain files. Claude Code, for example, loads CLAUDE.md files each session, and its docs say these are context, not forced rules [3]. The CoALA authors also note that changing procedural memory is riskier than adding to the other kinds, because it changes behavior [2]. So the clinic manager should review it.</p><p><strong>Semantic memory</strong> is what is true right now. Priya is allergic to penicillin. She prefers mornings. Her next visit is October 16 at 9:00. You’d want these facts in any future chat, and they should change when her situation changes.</p><p><strong>Episodic memory</strong> is what happened. On October 5 she booked a cleaning for the 14th. On October 7 she asked to move it to the 16th because she’s traveling. Episodes have dates and context, and they answer the “why” questions that a plain fact can’t.</p><p>The last two are where most trouble starts. “Next visit: October 16” is true until the day it changes. “On October 7 Priya moved her cleaning because she’s traveling” is a past event, so it doesn’t expire. One is the current state. The other is history. Priya’s Tuesday question needs the episode. “When should we send a reminder?” needs the fact.</p><p>These categories don’t each need their own database. Procedural memory can be a folder of Markdown files. Episodes can be rows in a table or lines in a log. Facts can sit in a simple table or in a vector index. The categories say what the information is for, not where to store it.</p><h3>Draw the architecture</h3><p>Here’s the diagram I’d draw.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S0nh9axTMQdgM7kwXQaVmg.png" /></figure><p><em>The three zones: the request in progress (top), persistent memory (middle), and memory upkeep (bottom).</em></p><p><strong>Top zone, the request.</strong> The patient’s message, the relevant chat history, and the clinic’s instructions flow into the prompt-building box (context assembly). The LLM reads only that prompt. The model doesn’t connect to your databases. Your code does, and it decides what to pass along.</p><p><strong>Middle zone, persistent memory.</strong> Three arrows run up into the prompt box. Procedural memory is loaded, since it’s small and always useful. Semantic and episodic memory are <em>searched</em>, because a clinic has thousands of patients and only Priya’s few entries matter right now.</p><p><strong>Bottom zone, upkeep.</strong> After the reply, the exchange is <em>selectively</em> logged, because not every message is worth keeping. A selected exchange is saved as a dated episode. Separately, a summarizing step (consolidation) can suggest lasting facts, and those pass through a check before they reach semantic memory.</p><h3>Follow one request through</h3><p>Let’s trace Priya’s question: <em>“Why isn’t my cleaning on the 14th anymore?”</em></p><ol><li><strong>Retrieval.</strong> The app always loads the clinic’s rules. It then searches only Priya’s records, filtering by her patient ID first, so another patient’s data can never leak in. It looks for facts and episodes about her appointment.</li><li><strong>Selection.</strong> Search returns candidates. The app keeps the best few, the top-k, and drops the rest.</li><li><strong>Assembly.</strong> The chosen pieces go into the prompt, like the example above.</li><li><strong>Reply.</strong> The model answers from what it was given: “You asked us to move it on October 7 because you’re traveling on the 14th. It’s now October 16 at 9:00. Want to change it again?”</li><li><strong>Recording.</strong> The exchange is logged. It probably doesn’t become an episode, since nothing happened except a question.</li></ol><p>Retrieval can repeat, too: search, read, search again.</p><p>This is retrieval-augmented generation (RAG) in small form. The original paper paired a text generator with a retriever that searched an outside index [4]. Ours searches Priya’s records instead of Wikipedia, but the shape is the same.</p><p><strong>How top-k works, and where it misleads.</strong> Text can be turned into embeddings, which are lists of numbers where similar meanings end up close together. To search, you turn the question into numbers and ask the index for the <em>k</em> closest entries. That finds things <em>related</em> to the question. It can’t tell if they are <em>correct</em>, <em>current</em>, or <em>about the right patient</em>.</p><h3>When memory goes wrong</h3><p>A few days later Priya asks, “What time is my appointment?” The agent retrieves two facts:</p><ul><li>Next visit: cleaning, Oct 14, 9:00 (saved Oct 5)</li><li>Next visit: cleaning, Oct 16, 9:00 (saved Oct 7)</li></ul><p>Both are close in meaning to the question. The older one is shorter and matches a bit better, so it ranks first. The agent says, “See you on the 14th!” and Priya shows up on the wrong day.</p><p>Nothing broke. The index returned similar text, and nothing told it one fact had been replaced. A few habits lower this risk:</p><ul><li><strong>Give facts a life cycle.</strong> Store a valid_from date, a status such as current or replaced, and a link to what replaced it. Search only current facts by default.</li><li><strong>Record where each fact came from.</strong> Each fact should point to the episode or record behind it.</li><li><strong>Trust the real source.</strong> The clinic’s booking calendar beats any remembered note. A good rule for the agent: <em>check the calendar before confirming a time.</em></li><li><strong>Don’t let ranking decide what’s true.</strong> Similarity finds candidates. Conflicts need a rule, a date comparison, or a question to staff.</li></ul><p>The Generative Agents work didn’t rank memories by similarity alone, either. It mixed recency, an importance score, and relevance [5].</p><h3>From chat to knowledge: consolidation</h3><p>Consolidation turns experience into reusable knowledge. Take Priya’s October 7 message:</p><blockquote><em>“I’m traveling on the 14th. Can you move my cleaning to the 16th? Mornings are best.”</em></blockquote><p>It becomes three different things.</p><p><strong>The raw message</strong> sits in the chat log. It’s evidence, and most of it will never be read again.</p><p><strong>The episode</strong> is a dated event with its context:</p><pre>{<br>  &quot;id&quot;: &quot;ep_1007_02&quot;,<br>  &quot;patient_id&quot;: &quot;p_1042&quot;,<br>  &quot;timestamp&quot;: &quot;2026-10-07T10:15:00Z&quot;,<br>  &quot;event&quot;: &quot;Moved cleaning from Oct 14 to Oct 16, 9:00&quot;,<br>  &quot;context&quot;: &quot;Patient is traveling on Oct 14&quot;,<br>  &quot;source&quot;: &quot;chat 2, messages 3-5&quot;<br>}</pre><p><strong>The fact</strong> says what is true now, and comes from the episode:</p><pre>{<br>  &quot;patient_id&quot;: &quot;p_1042&quot;,<br>  &quot;fact&quot;: &quot;Next visit: cleaning on Oct 16, 9:00 with Dr. Rao&quot;,<br>  &quot;valid_from&quot;: &quot;2026-10-07&quot;,<br>  &quot;status&quot;: &quot;current&quot;,<br>  &quot;supersedes&quot;: &quot;Next visit: cleaning on Oct 14, 9:00&quot;,<br>  &quot;source&quot;: &quot;ep_1007_02&quot;<br>}</pre><p><strong>Procedural memory</strong> might get a new rule, but only if the clinic has chosen one: <em>“Before confirming any time, check the booking calendar.”</em> The manager should approve it; a summary shouldn’t write it alone.</p><p>A model can do the consolidating: summarize episodes and suggest facts. But a summary is a claim, not a record. A model that reads “my sister is allergic to penicillin” might write “Priya is allergic to penicillin.” Health facts like allergies are the last thing to guess about. So the diagram has a check between the suggestion and the save. That check can compare with current facts, look at the source episode and dates, look at the booking calendar, and for health details, ask staff to confirm. The episode stays even after the fact changes, so you can see what changed and why.</p><h3>Do you need all of this?</h3><p>Probably not at first. A bot that only answers opening hours and prices needs a system prompt and the last few turns. An agent that only books visits might do well with the booking system plus one notes file read at the start of each chat. Anthropic’s memory tool works in a similar file-based way: Claude asks for file actions and the app carries them out on storage it controls [6]. Each layer adds parts to maintain, old entries to clean up, and personal data to protect.</p><p>Privacy is easy to put off and hard to add later, and patient details are sensitive. Depending on where the clinic is, health-privacy rules such as HIPAA in the US may apply, so ask someone who knows them. The memory tool docs say the app must handle sensitive data, file size limits, and expiry itself [6]. Decide how long to keep chats and how a patient can have them deleted.</p><h3>Workshop exercise: design a small memory system</h3><p>Take your own agent and answer these:</p><ol><li><strong>What must survive the session?</strong> List five things. Sort each as procedural, semantic, or episodic.</li><li><strong>Which can go out of date?</strong> What would you check each one against?</li><li><strong>Who can write?</strong> Can the agent save memory directly, or does it suggest and a person approves?</li><li><strong>How will you search?</strong> Load always, filter by field, keyword search, or embeddings? Start with the simplest.</li><li><strong>When does an entry expire or get reviewed?</strong></li></ol><p>A sensible starting design for the dental agent:</p><ul><li>One CLINIC_RULES.md, loaded every chat and edited by the manager.</li><li>A facts table with patient_id, fact, valid_from, status, source.</li><li>An append-only episodes table with patient_id, timestamp, event, context.</li><li>Search by plain filters first (patient, then topic). Add embeddings only when filters aren’t enough.</li><li>A weekly job that suggests fact changes into a review queue, with staff approving anything about health.</li></ul><h3>What I’d keep from all this</h3><p>An episode and a fact look alike on paper, but they promise different things. An episode says “this happened,” and a past event doesn’t go stale. A fact says “this is true now,” and it can quietly stop being true. So give every fact a way to be wrong: a date, a source, and a check against the real booking calendar.</p><h3>References</h3><ol><li>Sumers, T. R., Yao, S., Narasimhan, K., Griffiths, T. L. (2023). <em>Cognitive Architectures for Language Agents.</em> arXiv:2309.02427. <a href="https://arxiv.org/abs/2309.02427">https://arxiv.org/abs/2309.02427</a></li><li>Lewis, P. et al. (2020). <em>Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks.</em> NeurIPS 2020. <a href="https://arxiv.org/abs/2005.11401">https://arxiv.org/abs/2005.11401</a></li><li>Park, J. S. et al. (2023). <em>Generative Agents: Interactive Simulacra of Human Behavior.</em> arXiv:2304.03442. <a href="https://arxiv.org/abs/2304.03442">https://arxiv.org/abs/2304.03442</a></li></ol><p><em>Note on the example:</em> The dental clinic, patient, dates, and records in this article are invented for illustration. They aren’t from a real system.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6faac6144a5b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>