tezvyn:

Agent Memory: Short-Term vs. Long-Term Recall

AI-drafted, machine-checkedSource: docs.langchain.comintermediate

Agent memory gives an LLM a sense of history, separating fleeting conversation context from persistent knowledge. Short-term memory tracks the current chat, while long-term memory recalls user facts across sessions.

WHY IT EXISTS Without memory, every interaction with an AI agent is stateless and isolated. To handle complex, multi-turn tasks, learn from feedback, and adapt to user preferences, agents need a system to remember previous interactions. Memory provides the continuity required for both efficiency and a satisfying user experience.

THE MENTAL MODEL Think of agent memory like a human's, split into two systems. Short-term memory is your working memory for a single conversation—what you're talking about right now. Long-term memory is your brain's permanent storage—facts you know about a person that you can recall in any future conversation with them.

HOW IT WORKS Short-term memory is "thread-scoped," tied to a single, ongoing conversation. It tracks the message history and other session-specific data like uploaded files. This state is often persisted via checkpoints so a conversation can be resumed. Long-term memory is stored in custom "namespaces" (e.g., by user ID) and is accessible across all conversations. This allows an agent to recall user-specific facts or application-level data at any time, in any thread.

WHEN TO USE IT Use short-term memory for any multi-turn conversation to maintain immediate context. Use long-term memory when you need an agent to personalize responses based on past interactions, learn user preferences, or remember key facts across different sessions. This is critical for building adaptive, stateful assistants that feel intelligent over time.

WHEN NOT TO USE IT For simple, one-shot tasks where no context is needed, a memory system is overkill. The primary footgun is using short-term memory without a strategy to manage its size. Simply appending the full history to the LLM's context will eventually cause errors, increase costs, and degrade performance as the model gets distracted by stale information.

ONE CANONICAL EXAMPLE In LangGraph, short-term memory is the agent's state within a specific thread. If a user uploads a file, that context is part of the short-term state. Long-term memory might store a user's preference, like "always respond in JSON," in a namespace tied to their user ID. This fact can be recalled in any new conversation thread started by that user.

Read the original → docs.langchain.com

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.