Learn/Generative AI, RAG & Agents/MODULE 3: AGENTIC AI
Lesson 26 of 37 · 2 min read

3.5 Memory in Agents

Agents that work on long or recurring tasks need memory.

There are several kinds.

Short-Term Memory (Within a Session)

This is essentially the LLM's context window: it "remembers" everything that's happened in the current task because all of it is in the prompt.

As the conversation gets longer, older parts may get dropped or summarized to fit.

Long-Term Memory (Across Sessions)

If you want the agent to remember information across separate sessions — your preferences, past tasks, relationships, project history — you need to store that information somewhere and retrieve it when relevant.

Sound familiar?

It should: this is essentially RAG applied to the agent's own past experiences.

Past interactions get embedded and stored in a vector database.

When a new task begins, relevant memories are retrieved and added to the context.

For example, if an agent helped you plan a vacation six months ago, it might "remember" (via retrieval) that you prefer aisle seats, dislike layovers in certain cities, and have a TSA PreCheck number — without you having to repeat that information.

Working Memory

For complex tasks, agents often maintain a scratchpad — a structured place where they record intermediate results, partial plans, things to do later.

This is essentially memory the agent writes to and reads from during a task.

Many agent frameworks (LangChain and LangGraph, LlamaIndex, and others) have built-in support for various memory types.

Keep going with a free account

A free account saves your progress across lessons and lets you pick up where you left off.