Without memory, an agent is a newcomer in every conversation. With memory, it can carry on a dialogue, remember preferences, and learn from the past.
Remember these points first
- Working memory: the key information needed for the current step, like scratch paper.
- Short-term memory: the context within one session. It is gone once the session ends or the program restarts.
- Long-term memory: preferences, history, and knowledge saved across sessions. It must be stored in a database or vector store.
- Memory makes an agent more reliable, more personalized, and better at improving itself.
Going deeper
The difference between the three kinds of memory. When a user says 'I want to go to Paris', that is working memory. When they then ask 'how is the accommodation there?', 'there' refers to Paris, which relies on short-term memory. When they come back next week and the agent still knows you like skiing and enjoy coffee, that relies on long-term memory.
How to store them. Short-term memory is handled by the framework's session object. Long-term memory has to be stored yourself: a database, a vector index, or a graph-structured knowledge base. You can also use an off-the-shelf memory service. The key question is 'what to store': don't store everything. Pick summaries, preferences, and valuable conclusions.
How to make it get better over time. After each task, distill the successes and failures into rules and save them. Next time, check memory first before acting.
Note. Memory raises privacy concerns, so users should be able to view, edit, and delete it.
![]()
Image from the course repository.
Try it yourself
At the end of a conversation, ask the model to summarize 'the three preferences you remembered about me', then manually use those three items to start the next conversation.
Let your agent teach you
Give the text below to your agent (Claude Code, ChatGPT, and Gemini all work), and it will guide you step by step like a mentor.
Sign in to unlock this key section
New accounts get 10 free credits, plus 1 more for each daily check-in. Spend 1 credit to unlock and it stays open for you.
References
- Content adapted from Lesson 13 (
13-agent-memory) of microsoft/ai-agents-for-beginners, an MIT-licensed project. - For the original and full code: 13-agent-memory
- For all courses, see the Agent course roadmap


Comments (0)
No comments yet. Start the conversation.