<?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 Shehan Jayasinghe on Medium]]></title>
        <description><![CDATA[Stories by Shehan Jayasinghe on Medium]]></description>
        <link>https://medium.com/@jayasingheshehan1995?source=rss-a0928b2a3ff9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dm-NdhQ5e5rT-9rK-_Eghg.png</url>
            <title>Stories by Shehan Jayasinghe on Medium</title>
            <link>https://medium.com/@jayasingheshehan1995?source=rss-a0928b2a3ff9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 10:24:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jayasingheshehan1995/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[Building Human-Like Memory for AI Agents (Part 2): Mastering Long-Term Memory]]></title>
            <link>https://medium.com/@jayasingheshehan1995/building-human-like-memory-for-ai-agents-part-2-mastering-long-term-memory-830a53b29e74?source=rss-a0928b2a3ff9------2</link>
            <guid isPermaLink="false">https://medium.com/p/830a53b29e74</guid>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[generative-ai]]></category>
            <category><![CDATA[memories]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Shehan Jayasinghe]]></dc:creator>
            <pubDate>Thu, 13 Aug 2026 18:20:14 GMT</pubDate>
            <atom:updated>2026-08-13T18:20:14.762Z</atom:updated>
            <content:encoded><![CDATA[<p>Learn how vector stores, semantic memory, episodic memory, entity memory, and procedural memory help AI agents remember information across conversations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gROXryf2wcXwAS18znmjUw.png" /><figcaption>How AI agents store and retrieve long-term memories across conversations using different memory systems.</figcaption></figure><h3>Introduction</h3><p>In Part 1, we explored how AI agents use <strong>short-term memory</strong> to maintain context during an ongoing conversation. Techniques such as Conversation Buffer, Sliding Window, Summary Memory, Summary Buffer, and Token Buffer help agents remember what has been discussed within the current interaction.</p><p>But what happens when the conversation ends?</p><p>If an AI agent starts a new conversation tomorrow, it shouldn’t have to start from zero. It may need to remember important facts about the user, previous experiences, learned information, or how certain tasks should be performed.</p><p>This is where <strong>long-term memory</strong> becomes important.</p><p>Long-term memory allows AI agents to <strong>store and retrieve information across conversations and sessions</strong>. Instead of keeping everything in the current context window, agents can persist important information and retrieve it when needed.</p><p>In this article, we’ll explore the main long-term memory techniques used in modern AI agents, including <strong>Vector Store Memory, Semantic Memory, Episodic Memory, Entity Memory, and Procedural Memory</strong>.</p><p>We’ll also compare these approaches and see how they can work together to build AI agents that maintain context and become more useful over time.</p><h3>From Short-Term to Long-Term Memory</h3><p>Part 1 focused on <strong>short-term memory</strong>, which helps AI agents maintain context during an ongoing conversation. But this memory is not enough when important information needs to remain available after the conversation ends.</p><p>For example, an agent may need to remember a user’s preferences, previous interactions, important facts, or information learned from earlier conversations. This requires <strong>persistent memory</strong> that can store information and retrieve it when needed.</p><p>That is where <strong>long-term memory</strong> comes in.</p><h3>What is Long-Term Memory?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*al7msmiesCozhSsaDoPDzQ.png" /><figcaption>Long-Term Memory allows AI agents to store and retrieve important information across conversations and sessions.</figcaption></figure><p>Instead of keeping everything inside the current context window, the agent can persist useful information and retrieve relevant memories when required.</p><p>The main difference is simple: <strong>short-term memory maintains the current conversation, while long-term memory preserves information beyond the current interaction.</strong></p><h3>Vector Store Memory</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GhnGQN4ekGJF5C3yhYpvVg.png" /><figcaption>Vector Store Memory stores information as embeddings and retrieves relevant memories through semantic similarity.</figcaption></figure><p>Vector Store Memory allows AI agents to store important information as <strong>vector embeddings</strong> and retrieve relevant memories based on semantic similarity.</p><p>When information is stored, it is converted into an embedding and saved in a vector store. When a new request arrives, the agent searches for similar memories and retrieves the most relevant information for the LLM.</p><p>For example, if a user previously mentioned that they prefer Python and FastAPI, the agent can retrieve that information when the user later asks for a backend technology recommendation.</p><h4>Advantages</h4><p><em>Enables semantic search based on meaning</em></p><p><em>Stores information across conversations and sessions</em></p><p><em>Can handle large amounts of information</em></p><p><em>Useful for user preferences, conversations, documents, and knowledge</em></p><h4>Limitations</h4><p><em>Retrieved memories may sometimes be irrelevant</em></p><p><em>Creating embeddings adds processing and API costs</em></p><p><em>Requires vector storage infrastructure</em></p><p><em>Retrieved memories still consume context tokens</em></p><p>Vector Store Memory provides a powerful way to <strong>retrieve relevant information</strong>, but not all memories are simply pieces of text. AI agents also need to remember <strong>facts and knowledge</strong> about users, systems, and the world. This is where <strong>Semantic Memory</strong> becomes useful.</p><h3>Semantic Memory</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EVHkQhOKtTx7DHLFy7s8rA.png" /><figcaption>Semantic Memory stores important facts and knowledge that an AI agent can recall when needed.</figcaption></figure><p>Instead of remembering an entire conversation, the agent focuses on important information such as a user’s preferences, project details, or known facts. This information can then be retrieved when it becomes relevant to a future interaction.</p><p>For example, an agent may remember that a user prefers <strong>Python and FastAPI</strong> for backend development. Later, when the user asks for a backend recommendation, the agent can use this stored knowledge to provide a more personalized response.</p><h4>Advantages</h4><p><em>Preserves important facts and knowledge</em></p><p><em>Useful across multiple conversations</em></p><p><em>Enables more personalized responses</em></p><p><em>Avoids storing unnecessary conversation details</em></p><h4>Limitations</h4><p><em>Deciding what information is worth remembering can be difficult</em></p><p><em>Stored facts can become outdated</em></p><p><em>Incorrect information can lead to incorrect responses</em></p><p><em>Requires a mechanism to update or remove old information</em></p><p>Semantic Memory helps agents remember <strong>what they know</strong>, but knowing a fact is different from remembering <strong>what happened</strong>. To preserve previous interactions and experiences, AI agents can use <strong>Episodic Memory</strong>.</p><h3>Episodic Memory</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4fd60xgIUwzzW9fzOy35ZQ.png" /><figcaption>Episodic Memory helps AI agents remember specific past events, interactions, and experiences.</figcaption></figure><p>Episodic Memory allows AI agents to remember <strong>what happened in previous interactions</strong>. Instead of storing only general facts, it preserves specific experiences, such as a previous conversation, task, decision, or outcome.</p><p>For example, an AI coding assistant may remember that a user previously encountered a <strong>Docker deployment error</strong> and how it was resolved. When a similar problem appears later, the agent can retrieve that past experience and use it to provide a more relevant response.</p><h4>Advantages</h4><p><em>Preserves important past experiences</em></p><p><em>Helps agents learn from previous interactions</em></p><p><em>Enables more personalized responses</em></p><p><em>Useful for recalling previous tasks and decisions</em></p><h4>Limitations</h4><p><em>Storing every interaction can create unnecessary memories</em></p><p><em>Past experiences may become outdated</em></p><p><em>Retrieving the wrong experience can lead to poor responses</em></p><p><em>Requires a mechanism to identify which events are worth remembering</em></p><p>Episodic Memory helps an agent remember <strong>what happened</strong>, while another important question is <strong>who or what was involved</strong>. To maintain information about users, projects, products, and other important entities, agents can use <strong>Entity Memory</strong>.</p><h3>Entity Memory</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WFtQYOtNrqOhmn4BzKuGwA.png" /><figcaption>Entity Memory helps AI agents maintain information about important people, projects, products, and other entities across conversations.</figcaption></figure><p>Entity Memory allows AI agents to maintain information about <strong>important entities</strong> and their relationships over time. Instead of remembering an entire conversation, the agent keeps useful information associated with specific entities such as users, projects, companies, products, or technologies.</p><p>For example, an AI coding assistant might remember that a particular project uses <strong>React, FastAPI, PostgreSQL, and AWS</strong>. When the user discusses that project later, the agent can retrieve these details and provide more relevant responses.</p><h4>Advantages</h4><p><em>Keeps information organized around important entities</em></p><p><em>Helps maintain context across conversations</em></p><p><em>Enables more personalized responses</em></p><p><em>Useful for users, projects, products, and organizations</em></p><h4>Limitations</h4><p><em>Entity information can become outdated</em></p><p><em>Incorrect entity associations can cause confusion</em></p><p><em>Requires identifying and updating entities correctly</em></p><p><em>Complex relationships may require more structured storage</em></p><p>Entity Memory helps agents remember <strong>who or what is involved</strong>, but agents also need to remember <strong>how to perform tasks</strong>. This leads to the final memory type in this article: <strong>Procedural Memory</strong>, which focuses on rules, instructions, and learned workflows.</p><h3>Procedural Memory</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*80iUiUWzhBwYxziePskbFA.png" /><figcaption>Procedural Memory helps AI agents remember rules, instructions, and workflows for performing tasks consistently.</figcaption></figure><p>Procedural Memory allows AI agents to remember <strong>how to perform tasks</strong>. Instead of storing facts or past experiences, it stores reusable instructions, rules, workflows, and procedures that guide the agent when performing a task.</p><p>For example, an AI deployment agent may remember a workflow such as <strong>run tests → build the Docker image → push it to the registry → deploy to Kubernetes</strong>. When the same type of task is requested later, the agent can retrieve the procedure and follow the established workflow.</p><h4>Advantages</h4><p><em>Reuses proven workflows and instructions</em></p><p><em>Helps agents perform tasks consistently</em></p><p><em>Reduces the need to provide the same instructions repeatedly</em></p><p><em>Useful for automation and multi-step agent workflows</em></p><h4>Limitations</h4><p><em>Procedures can become outdated</em></p><p><em>Incorrect instructions can lead to repeated mistakes</em></p><p><em>Complex workflows may require frequent updates</em></p><p><em>The agent still needs to decide when and which procedure to apply</em></p><p>With Procedural Memory, we have now covered the five major long-term memory concepts: <strong>Vector Store, Semantic, Episodic, Entity, and Procedural Memory</strong>. Next, we’ll compare them and see how different memory types can work together inside a modern AI agent.</p><h3>Comparison of Long-Term Memory Techniques</h3><p>After exploring the five major <strong>long-term memory types</strong>, it’s clear that no single approach is best for every AI application. Each memory type serves a different purpose, from retrieving relevant information to remembering facts, experiences, entities, and reusable procedures.</p><p>The comparison below highlights what each memory type remembers and where it is most useful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3JjsPjmqM5S8TrcrIDMSww.png" /><figcaption>Comparison of five long-term memory types and the information each one helps an AI agent remember.</figcaption></figure><p>Now that we’ve compared the different approaches, the next question is: <strong>Which long-term memory should you use for your AI application?</strong> Let’s answer that with a simple decision guide.</p><h3>Which Long-Term Memory Should You Choose?</h3><p>Choosing the right <strong>long-term memory strategy</strong> depends on what your AI agent needs to remember. Different applications may require facts, past experiences, entity information, reusable workflows, or semantic retrieval.</p><p>The following decision guide provides a simple way to select the most appropriate memory approach for your AI application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MGwUcezMQp59bM-7OWHPpA.png" /><figcaption>Decision guide for choosing the most appropriate long-term memory strategy based on an AI agent’s requirements.</figcaption></figure><p>In practice, production AI agents often <strong>combine multiple memory types</strong> rather than relying on a single approach. For example, an agent might use semantic memory for user preferences, episodic memory for previous interactions, and procedural memory for reusable workflows.</p><p>Now that we’ve explored the major <strong>long-term memory types</strong>, let’s summarize the key concepts before looking at how these memory systems work together.</p><h3>Key Takeaways</h3><p>In this article, we explored how <strong>long-term memory</strong> allows AI agents to retain useful information across conversations and sessions.</p><p>The key points to remember are:</p><ul><li><strong>Long-Term Memory</strong> allows AI agents to retain information beyond the current conversation.</li><li><strong>Vector Store Memory</strong> helps retrieve relevant information using semantic similarity.</li><li><strong>Semantic Memory</strong> stores important facts and knowledge.</li><li><strong>Episodic Memory</strong> remembers previous events and experiences.</li><li><strong>Entity Memory</strong> maintains information about people, projects, products, and other entities.</li><li><strong>Procedural Memory</strong> stores rules, instructions, and reusable workflows.</li><li>There is <strong>no one-size-fits-all solution</strong> — production agents can combine multiple memory types depending on their requirements.</li></ul><h3>What’s Next?</h3><p>In Part 2, we explored how AI agents can <strong>remember information across conversations and sessions</strong> using different long-term memory techniques.</p><p>But storing memories is only part of the problem.</p><p>In <strong>Part 3</strong>, we’ll explore how AI agents can <strong>manage, retrieve, update, consolidate, and forget memories</strong> as they become more complex.</p><p>We’ll look at topics such as <strong>memory retrieval, memory routing, memory consolidation, memory decay, self-reflection, and hybrid memory architectures</strong>.</p><p>Stay tuned for <strong>Building Human-Like Memory for AI Agents (Part 3): Managing Memory in Production AI Agents</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=830a53b29e74" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Human-Like Memory for AI Agents (Part 1): Mastering Short-Term Memory]]></title>
            <link>https://medium.com/@jayasingheshehan1995/building-human-like-memory-for-ai-agents-part-1-mastering-short-term-memory-53f7db973b9f?source=rss-a0928b2a3ff9------2</link>
            <guid isPermaLink="false">https://medium.com/p/53f7db973b9f</guid>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[generative-ai]]></category>
            <category><![CDATA[langchain]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Shehan Jayasinghe]]></dc:creator>
            <pubDate>Thu, 06 Aug 2026 18:15:06 GMT</pubDate>
            <atom:updated>2026-08-07T03:21:35.205Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Learn how conversation buffers, sliding windows, summaries, and token-aware memory enable AI agents to remember context beyond a single promp</em>t.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AaEHc73mbuhgB66Rgu0Y9A.png" /><figcaption><strong>Short-Term Memory in Modern AI Agents</strong></figcaption></figure><h3>Introduction</h3><p>Imagine you’re chatting with an AI assistant.</p><p>You ask it to help plan your vacation. A few minutes later, you ask it to book a hotel. Then you ask it to recommend restaurants near your hotel.</p><p>Now imagine the AI suddenly replies:</p><blockquote>“Which hotel are you talking about?”</blockquote><p>Even though <strong>you already mentioned the hotel</strong>, the AI has forgotten because it doesn’t automatically remember previous conversations.</p><p>This is one of the biggest limitations of a standard <strong>Large Language Model (LLM)</strong>. By default, an LLM treats every request as a <strong>new interaction</strong>, making it impossible to maintain long conversations or build personalized experiences on its own.</p><p>To overcome this limitation, modern <strong>AI agents</strong> introduce different types of <strong>memory systems</strong>. These systems allow agents to retain context, remember previous interactions, and produce more consistent and intelligent responses.</p><p>In this article, we’ll explore <strong>short-term memory</strong>, the first building block of agent memory. You’ll learn how techniques such as <strong>Conversation Buffer</strong>, <strong>Sliding Window</strong>, <strong>Summary Memory</strong>, <strong>Summary Buffer</strong>, and <strong>Token Buffer</strong> help AI agents remember context beyond a single prompt.</p><h3>Why LLMs Forget</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dnNRw9LSUAe2WqIn6DM_wg.png" /><figcaption>A standard LLM processes each prompt independently without retaining previous interactions.</figcaption></figure><p>As shown in the figure above, an <strong>LLM is stateless</strong>. It receives a <strong>user prompt</strong>, predicts the <strong>next most likely tokens</strong>, generates a <strong>response</strong>, and then completes the interaction.</p><p>Unlike humans, an LLM <strong>doesn&#39;t remember previous conversations</strong>. Once the response is generated, the conversation is <strong>not automatically stored</strong>. Every new prompt is treated as a <strong>completely new request</strong>.</p><p>In other words, an LLM only knows <strong>what is inside the current prompt</strong>. If you don&#39;t provide previous context again, the model has <strong>no memory</strong> of earlier interactions.</p><p>This is the reason <strong>modern AI agents</strong> introduce <strong>memory systems</strong>. By storing and retrieving relevant information, they can maintain <strong>context</strong>, remember <strong>past interactions</strong>, and provide more <strong>consistent and personalized responses</strong>.</p><p>Now that we understand why LLMs forget, let&#39;s compare <strong>how humans remember information</strong> and <strong>how AI agents manage memory</strong>.</p><h3>Why AI Agents Need Memory</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8587ZP328xX9E8zygUXaJA.png" /><figcaption>Memory enables AI agents to retain context, recall previous interactions, and deliver more personalized responses.</figcaption></figure><p>If LLMs naturally forget every interaction, <strong>how do AI agents hold meaningful conversations that span multiple requests or even multiple sessions?</strong></p><p>The answer is <strong>memory</strong>.</p><p>Just as humans rely on different types of memory to remember recent conversations, past experiences, facts, and skills, AI agents use specialized memory mechanisms to store and retrieve information whenever it’s needed.</p><p>For example, an AI coding assistant can remember the project you’re working on, a customer support agent can recall previous issues reported by a user, and a personal assistant can remember your preferences across multiple conversations.</p><p>Without memory, an AI behaves like someone experiencing every conversation for the <strong>first time</strong>. With memory, it can maintain context, provide personalized responses, and reason more effectively over longer interactions.</p><p>Before exploring the different short-term memory techniques, let’s first compare <strong>how humans remember information</strong> and <strong>how AI agents manage memory</strong>.</p><h3><strong>Human Memory vs AI Memory</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W34hn1k_pufX591XdcghHQ.png" /><figcaption>Human memory and AI memory share similar concepts, but they are implemented in fundamentally different ways.</figcaption></figure><p>Before exploring the different <strong>short-term memory techniques</strong>, it’s helpful to understand how <strong>humans remember information</strong> and how <strong>AI agents manage memory</strong>.</p><p>Humans don’t rely on a single type of memory. We use different memory systems for different purposes — remembering a conversation we just had, recalling facts we learned years ago, or performing tasks we’ve practiced many times.</p><p>Modern <strong>AI agents</strong> follow a similar principle. Instead of a biological brain, they use specialized memory mechanisms to <strong>store</strong>, <strong>retrieve</strong>, and <strong>organize</strong> information. Some memories maintain the current conversation, while others preserve knowledge, experiences, user preferences, or reusable workflows.</p><p>Although the implementation is completely different, the objective is the same: <strong>remember the right information at the right time</strong>.</p><p>In the rest of this article, we’ll focus on <strong>Short-Term Memory</strong>, the foundation of every modern AI agent. It enables agents to maintain conversational context before information is summarized, discarded, or stored as long-term memory.</p><h3>What is Short-Term Memory?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TANCLTkyKZQJUA3qSg4YGQ.png" /><figcaption>Short-term memory enables AI agents to maintain context throughout an ongoing conversation.</figcaption></figure><p><strong>Short-term memory</strong> is the <strong>working memory</strong> of an AI agent. It temporarily stores the information needed to understand and respond to the current conversation.</p><p>Unlike <strong>long-term memory</strong>, which preserves information across multiple sessions, short-term memory exists only while the interaction is active. It helps the agent remember recent messages, maintain context, and generate more coherent responses without repeatedly asking for the same information.</p><p>Modern AI frameworks implement short-term memory using different strategies, each optimized for specific use cases and resource constraints. The most common approaches include <strong>Conversation Buffer</strong>, <strong>Sliding Window</strong>, <strong>Summary Memory</strong>, <strong>Summary Buffer</strong>, and <strong>Token Buffer</strong>.</p><p>In the following sections, we’ll explore each of these techniques, understand how they work, and learn when to use them in real-world AI applications.</p><h3>Conversation Buffer Memory</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v3eU3y9CwTNWyXn2ZoWoAw.png" /><figcaption>Conversation Buffer stores the complete conversation history and sends it to the LLM with every new request.</figcaption></figure><p><strong>Conversation Buffer Memory</strong> is the simplest short-term memory strategy used by AI agents. Every user message and AI response is stored in chronological order, creating a complete conversation history. Whenever a new request is made, the <strong>entire conversation</strong> is sent back to the LLM along with the latest prompt. This allows the model to understand previous questions, maintain context, and generate coherent responses without asking the user to repeat information.</p><p>Because the conversation history continuously grows, this approach is best suited for <strong>short conversations</strong>, prototypes, and chatbots where maintaining complete context is more important than optimizing token usage.</p><h4>Advantages</h4><p><em>Simple and easy to implement</em></p><p><em>Preserves the complete conversation history</em></p><p><em>Excellent context retention</em></p><p><em>Great for short conversations and prototypes</em></p><h4>Limitations</h4><p><em>Conversation history continuously grows</em></p><p><em>Higher token consumption and API costs</em></p><p><em>May exceed the model’s context window</em></p><p><em>Less efficient for long-running conversations</em></p><h4>LangChain Example</h4><p>LangChain provides a built-in ConversationBufferMemory class that automatically stores the complete conversation history.</p><pre>from langchain.memory import ConversationBufferMemory<br>from langchain.chains import ConversationChain<br>from langchain_openai import ChatOpenAI<br><br>llm = ChatOpenAI(model=&quot;gpt-4.1&quot;)<br><br>memory = ConversationBufferMemory()<br><br>conversation = ConversationChain(<br>    llm=llm,<br>    memory=memory<br>)<br><br>conversation.predict(input=&quot;My name is Shehan.&quot;)<br>conversation.predict(input=&quot;I live in Sri Lanka.&quot;)<br>conversation.predict(input=&quot;What&#39;s my name?&quot;)</pre><p><strong>Conversation Buffer Memory</strong> provides excellent context retention, but its continuously growing history increases <strong>token usage</strong>, <strong>API costs</strong>, and can eventually exceed the model’s <strong>context window</strong>. To overcome this limitation, <strong>Sliding Window Memory</strong> keeps only the <strong>most recent messages</strong>, providing a better balance between <strong>context retention</strong> and <strong>efficiency</strong>.</p><h3>Sliding Window Memory</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sYWHPPTg000_xGYf-mgO2Q.png" /><figcaption>Sliding Window Memory retains only the most recent messages, automatically removing older ones to stay within the model’s context window.</figcaption></figure><p><strong>Sliding Window Memory</strong> stores only the <strong>last N messages</strong> instead of the entire conversation history. As new messages arrive, the oldest messages are automatically removed, creating a moving window that always contains the most recent context. This significantly reduces <strong>token usage</strong> while preserving enough context for the AI agent to generate relevant responses, making it a popular choice for <strong>chatbots</strong>, <strong>AI assistants</strong>, and <strong>production applications</strong>.</p><h4>Advantages</h4><p><em>Lower token usage than Conversation Buffer</em></p><p><em>Faster response times</em></p><p><em>Lower API costs</em></p><p><em>Ideal for long-running conversations</em></p><p><em>Easy to configure by choosing the window size</em></p><h4>Limitations</h4><p><em>Older conversation history is discarded</em></p><p><em>May lose important context from earlier messages</em></p><p><em>Window size must be chosen carefully</em></p><p><em>Not suitable when the entire conversation is required</em></p><h4>LangChain Example</h4><p>angChain provides ConversationBufferWindowMemory, which retains only the most recent <em>N</em> message pairs.</p><pre>from langchain.memory import ConversationBufferWindowMemory<br><br>memory = ConversationBufferWindowMemory(<br>    k=5<br>)</pre><p>The k parameter specifies the number of recent message pairs to retain. As new messages are added, the oldest ones are automatically removed from memory.</p><p>Although <strong>Sliding Window Memory</strong> is more efficient, it can discard valuable information from earlier in the conversation. <strong>Summary Memory</strong> solves this problem by compressing older conversations into a concise summary, allowing the AI agent to retain important context while using significantly fewer tokens.</p><h3>Summary Memory</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BXjdNxdwAKSr_4N9TkPoaw.png" /><figcaption>Summary Memory compresses older conversations into a concise summary while preserving important context for future interactions.</figcaption></figure><p>Unlike <strong>Conversation Buffer</strong> and <strong>Sliding Window Memory</strong>, <strong>Summary Memory</strong> doesn’t keep the entire conversation history. Instead, it periodically <strong>summarizes older messages</strong> and stores only the summary along with the most recent conversation.</p><p>This approach significantly reduces <strong>token usage</strong> while preserving the key information needed for future responses. As conversations grow longer, the AI agent continuously updates the summary, allowing it to remember important details without exceeding the model’s <strong>context window</strong>.</p><h4>Advantages</h4><p><em>Simple way to handle long conversations</em></p><p><em>Significantly reduces token usage</em></p><p><em>Preserves important context through summaries</em></p><p><em>Well suited for long-running AI assistants</em></p><h4>Limitations</h4><p><em>Fine-grained conversation details may be lost</em></p><p><em>Summary quality depends on the LLM</em></p><p><em>Summaries can accumulate small inaccuracies over time</em></p><p><em>Requires additional processing to generate summaries</em></p><h4>LangChain Example</h4><p>LangChain provides <strong>ConversationSummaryMemory</strong>, which automatically summarizes older conversations and updates the summary as the chat progresses.</p><pre>from langchain.memory import ConversationSummaryMemory<br>from langchain_openai import ChatOpenAI<br><br>llm = ChatOpenAI(model=&quot;gpt-4.1&quot;)<br><br>memory = ConversationSummaryMemory(<br>    llm=llm<br>)</pre><p>While <strong>Summary Memory</strong> greatly reduces token usage, it replaces older conversations with a summary. This means the AI may lose access to recent message details that haven’t yet been summarized. <strong>Summary Buffer Memory</strong> solves this by combining a <strong>conversation summary</strong> with the <strong>most recent messages</strong>, providing a balance between <strong>context retention</strong> and <strong>token efficiency</strong>.</p><h3>Summary Buffer Memory</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ozKWXG0t2AS8mY-787AK6Q.png" /><figcaption>Summary Buffer Memory combines a conversation summary with the most recent messages, balancing context retention and token efficiency.</figcaption></figure><p><strong>Summary Buffer Memory</strong> combines the strengths of <strong>Summary Memory</strong> and <strong>Sliding Window Memory</strong>. Instead of relying only on a summary or only on recent messages, it stores a <strong>summary of older conversations</strong> while keeping the <strong>most recent messages</strong> in their original form.</p><p>When a new request arrives, the AI agent sends <strong>both the conversation summary and the recent messages</strong> to the LLM. This allows the model to retain long-term context while preserving the fine details of the current conversation, making it one of the most balanced short-term memory strategies.</p><h4>Advantages</h4><p><em>Preserves important long-term context</em></p><p><em>Retains detailed recent conversations</em></p><p><em>Lower token usage than Conversation Buffer</em></p><p><em>Better context retention than Summary Memory</em></p><p><em>Ideal for long-running AI assistants</em></p><h4>Limitations</h4><p><em>More complex than other memory strategies</em></p><p><em>Requires generating and maintaining summaries</em></p><p><em>Summary quality depends on the LLM</em></p><p><em>Slightly higher processing overhead</em></p><h4>LangChain Example</h4><p>LangChain provides <strong>ConversationSummaryBufferMemory</strong>, which automatically maintains a conversation summary while keeping the most recent messages available.</p><pre>from langchain.memory import ConversationSummaryBufferMemory<br>from langchain_openai import ChatOpenAI<br><br>llm = ChatOpenAI(model=&quot;gpt-4.1&quot;)<br><br>memory = ConversationSummaryBufferMemory(<br>    llm=llm,<br>    max_token_limit=1000<br>)</pre><p>The max_token_limit controls when older messages are summarized while recent messages remain available in the conversation buffer.</p><p>While <strong>Summary Buffer Memory</strong> provides an excellent balance between <strong>context retention</strong> and <strong>token efficiency</strong>, it still manages memory using conversation history. <strong>Token Buffer Memory</strong> takes a different approach by monitoring the <strong>number of tokens</strong> instead of the number of messages, ensuring the conversation always remains within the model’s context window.</p><h3>Token Buffer Memory</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tLZtIsYz192GUVTIkmOFHQ.png" /><figcaption>Token Buffer Memory manages conversation history based on the model’s token limit, automatically removing older messages to stay within the context window.</figcaption></figure><p>Unlike the previous memory strategies, <strong>Token Buffer Memory</strong> doesn’t track the <strong>number of messages</strong>. Instead, it monitors the <strong>total number of tokens</strong> in the conversation.</p><p>Whenever a new message causes the conversation to exceed the configured <strong>token limit</strong>, the oldest messages are automatically removed until the total token count falls within the allowed context window. This ensures the AI agent always sends the maximum amount of relevant context without exceeding the model’s limits.</p><p>Because different messages consume different numbers of tokens, this approach makes more efficient use of the available context window than simply keeping a fixed number of messages.</p><h4>Advantages</h4><p><em>Automatically stays within the model’s context window</em></p><p><em>Makes efficient use of available tokens</em></p><p><em>Better than fixed-size message windows</em></p><p><em>Reduces context window overflow errors</em></p><p><em>Ideal for production AI applications</em></p><h4>Limitations</h4><p><em>Older messages are permanently removed</em></p><p><em>Important context may be discarded</em></p><p><em>Token counting adds slight processing overhead</em></p><p><em>Doesn’t preserve long-term conversation history</em></p><h4>LangChain Example</h4><p>LangChain provides <strong>ConversationTokenBufferMemory</strong>, which automatically manages conversation history based on a configurable token limit.</p><pre>from langchain.memory import ConversationTokenBufferMemory<br>from langchain_openai import ChatOpenAI<br><br>llm = ChatOpenAI(model=&quot;gpt-4.1&quot;)<br><br>memory = ConversationTokenBufferMemory(<br>    llm=llm,<br>    max_token_limit=1000<br>)</pre><p>The max_token_limit determines how many tokens can be stored before older messages are automatically removed from the conversation history.</p><p>We’ve now explored the five most common <strong>short-term memory techniques</strong> used in modern AI agents. Each approach makes different trade-offs between <strong>context retention</strong>, <strong>token usage</strong>, and <strong>computational efficiency</strong>. Before deciding which one to use, let’s compare them side by side and understand where each technique performs best.</p><h3>Comparison of Short-Term Memory Techniques</h3><p>After exploring the five most common <strong>short-term memory techniques</strong>, it’s clear that <strong>no single approach is best for every application</strong>. Each strategy makes different trade-offs between <strong>context retention</strong>, <strong>token usage</strong>, <strong>computational efficiency</strong>, and <strong>conversation length</strong>.</p><p>The comparison below highlights the strengths of each technique and helps you understand where each memory strategy performs best.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uf2Uqh-4rytWkkEhbTBbOA.png" /></figure><p>Now that we’ve compared the available approaches, the next question is:<strong>Which memory strategy should you choose for your AI application?</strong>Let’s answer that with a simple decision guide.</p><h3>Which Memory Should You Choose?</h3><p>Choosing the right <strong>short-term memory strategy</strong> depends on your application’s requirements. There isn’t a single memory technique that’s ideal for every scenario. Instead, the best choice depends on factors such as <strong>conversation length</strong>, <strong>token budget</strong>, <strong>context retention</strong>, and <strong>performance requirements</strong>.</p><p>The following decision guide provides a simple way to select the most appropriate memory strategy for your AI application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b0j9KyDSf24FWp3igi_iRA.png" /></figure><p>Understanding these trade-offs allows you to choose the most appropriate <strong>short-term memory strategy</strong> for your AI application. In practice, many production AI systems combine multiple memory techniques to achieve the best balance between <strong>performance</strong>, <strong>cost</strong>, and <strong>user experience</strong>.</p><p>Now that we’ve explored the most common <strong>short-term memory techniques</strong>, let’s summarize the key concepts before moving on to <strong>Long-Term Memory</strong> in <strong>Part 2</strong>.</p><h3>Key Takeaways</h3><p>In this article, we explored how <strong>short-term memory</strong> enables AI agents to maintain context throughout an ongoing conversation. While Large Language Models are <strong>stateless by default</strong>, memory strategies allow AI agents to remember previous interactions and generate more coherent, context-aware responses.</p><p>The key points to remember are:</p><ul><li><strong>LLMs are stateless</strong> and don’t remember previous conversations by default.</li><li><strong>Short-Term Memory</strong> helps AI agents maintain context during an active conversation.</li><li>Different memory techniques make different trade-offs between <strong>context retention</strong>, <strong>token usage</strong>, and <strong>performance</strong>.</li><li>There is <strong>no one-size-fits-all</strong> solution — the best memory strategy depends on your application’s requirements.</li><li>Production AI systems often combine multiple memory techniques to achieve the best balance between <strong>cost</strong>, <strong>performance</strong>, and <strong>user experience</strong>.</li></ul><h3>What’s Next?</h3><p>In this article, we focused on <strong>Short-Term Memory</strong>, which helps AI agents maintain context within an ongoing conversation.</p><p>In <strong>Part 2</strong>, we’ll explore <strong>Long-Term Memory</strong>, where AI agents learn to remember information across multiple conversations and sessions. We’ll cover <strong>Vector Stores</strong>, <strong>Semantic Memory</strong>, <strong>Episodic Memory</strong>, <strong>Entity Memory</strong>, and <strong>Procedural Memory</strong>, and see how these techniques enable AI agents to build personalized, context-aware experiences over time.</p><p>Stay tuned for <strong>Building Human-Like Memory for AI Agents (Part 2): Mastering Long-Term Memory</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53f7db973b9f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>