โ† Back|AI-AGENTSโ€บSection 1/16
0 of 16 completed

Memory in agents

Intermediateโฑ 10 min read๐Ÿ“… Updated: 2026-02-17

๐Ÿง  Introduction โ€“ Why Memory Matters

Imagine every time you talk to someone, they forget everything about you. Frustrating right? ๐Ÿ˜ค


Same problem AI agents ku irukku โ€“ memory illama every conversation fresh start!


Without Memory:

  • โŒ "Who are you?" โ€“ every time kekkum
  • โŒ Past conversations remember pannaadhu
  • โŒ User preferences theriyaadhu
  • โŒ Learned patterns lost

With Memory:

  • โœ… Knows your name, preferences, history
  • โœ… Builds on past conversations
  • โœ… Personalizes responses
  • โœ… Gets smarter over time

Memory = What makes an agent truly intelligent! ๐Ÿง ๐Ÿ’พ

๐Ÿ“Š Types of Agent Memory

Agent memory 4 main types la varum:


Memory TypeDurationWhat It StoresHuman Equivalent
**Working Memory**Current taskActive context, variablesRAM
**Short-term**SessionConversation historyToday's events
**Long-term**PermanentFacts, preferences, patternsLife experiences
**Episodic**PermanentSpecific past events"Remember that time..."

1. Working Memory ๐Ÿ”„

  • Current task-oda variables and state
  • LLM context window la irukku
  • Task complete aanaa clear aagum

2. Short-term Memory ๐Ÿ“

  • Current conversation history
  • Last few interactions
  • Session end aanaa gone (usually)

3. Long-term Memory ๐Ÿ’พ

  • User preferences, facts, knowledge
  • Persists across sessions
  • Stored in databases

4. Episodic Memory ๐Ÿ“ธ

  • Specific past interactions/events
  • "Last week nee flight book panniya"
  • Rich context with timestamps

๐Ÿ—๏ธ Agent Memory Architecture

๐Ÿ—๏ธ Architecture Diagram
```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              AGENT CORE                     โ”‚
โ”‚                                             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚  ๐Ÿ”„ WORKING MEMORY                     โ”‚ โ”‚
โ”‚  โ”‚  Current task state, active variables  โ”‚ โ”‚
โ”‚  โ”‚  LLM Context Window (128K tokens)      โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚                                             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚  ๐Ÿ“ SHORT-TERM MEMORY                  โ”‚ โ”‚
โ”‚  โ”‚  Conversation buffer (last N messages) โ”‚ โ”‚
โ”‚  โ”‚  Session-scoped                        โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚                 โ”‚ Save important info       โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚  ๐Ÿ’พ LONG-TERM MEMORY                   โ”‚ โ”‚
โ”‚  โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ Vector   โ”‚  โ”‚ Key-Value Store   โ”‚   โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ Database โ”‚  โ”‚ (Preferences,     โ”‚   โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ (Semanticโ”‚  โ”‚  Facts, Rules)    โ”‚   โ”‚ โ”‚
โ”‚  โ”‚  โ”‚  Search) โ”‚  โ”‚                   โ”‚   โ”‚ โ”‚
โ”‚  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚ โ”‚
โ”‚  โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ ๐Ÿ“ธ Episodic Memory              โ”‚  โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ Past interactions with context   โ”‚  โ”‚ โ”‚
โ”‚  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

๐Ÿ” Memory Storage Technologies

How to actually store agent memory?


TechnologyTypeBest ForExample
**In-memory array**WorkingCurrent conversationJavaScript array
**Redis**Short-termSession data, cacheRedis Cloud
**Vector DB**Long-termSemantic searchPinecone, ChromaDB
**SQL Database**Long-termStructured dataPostgreSQL
**Document DB**EpisodicEvent logsMongoDB
**File System**Long-termSimple persistenceJSON files

Vector Database โ€“ The Star โญ


Vector DB agent memory la game changer:

  1. Text โ†’ Embedding (mathematical vector) aa convert
  2. Similar embeddings cluster aagum
  3. Query time la semantically similar content retrieve

code
User says: "I like spicy food"
โ†’ Embedding: [0.23, 0.87, 0.12, ...]
โ†’ Stored in Vector DB

Later, user asks: "Suggest restaurant"
โ†’ Agent retrieves: "User prefers spicy food"
โ†’ Suggests: "Try Saravana Bhavan's spicy specials! ๐ŸŒถ๏ธ"

๐ŸŽฌ Memory in Action โ€“ Personal Assistant

โœ… Example

Day 1:

User: "I'm Ravi, I work at TCS, I like South Indian food"

Agent: *Stores to long-term memory*

- Name: Ravi

- Company: TCS

- Food preference: South Indian

Day 5:

User: "Book lunch for me"

Agent: *Retrieves from memory*

"Hi Ravi! ๐Ÿ‘‹ Since you like South Indian food, I found Murugan Idli Shop near your TCS office. Table for 1 at 12:30 PM?"

Day 15:

User: "Same as last time"

Agent: *Retrieves episodic memory*

"Booking Murugan Idli Shop again? Same time 12:30 PM? Last time you ordered the special thali โ€“ want that again? ๐Ÿฝ๏ธ"

See how memory makes the agent feel human? ๐Ÿค

๐Ÿ“ Memory Management Strategies

Too much memory = noise. Too little = forgetful. Balance venum!


1. Summarization ๐Ÿ“‹

  • Long conversations โ†’ condensed summaries
  • Keep key facts, discard filler
  • Periodically summarize and compress

2. Relevance Scoring โญ

  • Each memory item ku relevance score
  • High relevance โ†’ keep, Low relevance โ†’ archive/delete
  • Recency + frequency + importance = score

3. Forgetting Mechanism ๐Ÿ—‘๏ธ

  • Old, unused memories slowly decay
  • Like human forgetting โ€“ natural and necessary!
  • Prevents context window overflow

4. Memory Tiers ๐Ÿ“Š

TierContentRetention
**Hot**Recent, frequently usedAlways loaded
**Warm**Important but not frequentLoad on demand
**Cold**Old, rarely usedArchive, retrieve if needed
**Delete**Irrelevant, outdatedRemove permanently

5. Selective Storage ๐ŸŽฏ

  • Store facts and decisions, not raw conversation
  • "User likes pizza" โœ…
  • "User said 'hmm let me think about pizza'" โŒ

๐Ÿ”„ Memory Read/Write Cycle

Agent memory epdi use pannum? Read-Write cycle follow pannum:


WRITE (Storing memories):

code
1. Agent detects important information
2. Classify: fact / preference / event / decision
3. Generate embedding (for semantic search)
4. Store in appropriate memory tier
5. Index for quick retrieval

READ (Retrieving memories):

code
1. New user message arrives
2. Generate query embedding
3. Search relevant memories (semantic search)
4. Rank by relevance + recency
5. Inject top-K memories into LLM context
6. Agent responds with memory context

Key metrics:

MetricTarget
Retrieval accuracy>90% relevant memories
Retrieval latency<200ms
Memory freshnessUpdated within session
Context utilization<70% of context window

Don't fill entire context window with memories! Leave room for reasoning! ๐Ÿง 

๐Ÿ› ๏ธ Implementation Approaches

Approach 1: Conversation Buffer (Simple)

code
memory = []
memory.append({"role": "user", "content": "..."})
memory.append({"role": "assistant", "content": "..."})
# Send last N messages to LLM

โœ… Easy | โŒ No long-term persistence


Approach 2: Summary Memory (Medium)

code
# After every 10 messages, summarize
summary = llm.summarize(last_10_messages)
memory.append(summary)
# Keep summaries + recent messages

โœ… Compact | โŒ Loses details


Approach 3: Vector Memory (Advanced)

code
# Store each important fact as embedding
embedding = embed("User works at TCS")
vector_db.store(embedding, metadata)
# Retrieve relevant memories per query
results = vector_db.search(query_embedding, top_k=5)

โœ… Semantic search | โœ… Scalable | โŒ More complex


Approach 4: Hybrid (Production) โญ

code
Working: Current conversation buffer
Short-term: Last session summary
Long-term: Vector DB for facts + preferences
Episodic: Document DB for past events

โœ… Best of all worlds | โŒ Most complex to build

๐Ÿงช Try It โ€“ Memory-Aware Agent

๐Ÿ“‹ Copy-Paste Prompt
```
You are a Personal Assistant with MEMORY capabilities.

MEMORY SYSTEM:
- You can STORE facts using [STORE: key=value]
- You can RECALL facts using [RECALL: key]
- You maintain a memory log below

CURRENT MEMORY:
- name: (empty)
- preferences: (empty)
- past_actions: (empty)

INSTRUCTIONS:
1. When user shares information, STORE it
2. When answering, RECALL relevant memories
3. Show your memory operations explicitly

CONVERSATION:
User: "Hi! I'm Kavitha. I'm a teacher and I love reading 
Tamil novels. I'm vegetarian."

Process this message:
1. What will you STORE?
2. How will you respond using memory?
3. Show your updated memory state.
```

Watch how explicit memory management works! ๐Ÿ“š

โš ๏ธ Memory Pitfalls to Avoid

โš ๏ธ Warning

Common memory mistakes:

1. Storing everything ๐Ÿ’พ

- Not all info important. Be selective!

- "User said hi" โ€“ don't store this!

2. No memory expiry โฐ

- Old memories can mislead agent

- "User lived in Chennai" (but moved to Bangalore 6 months ago)

3. Privacy violations ๐Ÿ”’

- Sensitive data (passwords, medical info) needs special handling

- GDPR/privacy compliance essential

4. Memory conflicts โš”๏ธ

- "User likes coffee" vs "User switched to tea"

- Latest info should override old info

5. Context window flooding ๐ŸŒŠ

- Too many memories injected = no room for reasoning

- Limit to top 5-10 most relevant memories per query

๐Ÿ’ก Memory Best Practices

๐Ÿ’ก Tip

Production-ready memory tips:

- ๐ŸŽฏ Store structured data โ€“ JSON > free text

- ๐Ÿ“… Timestamp everything โ€“ when was this learned?

- ๐Ÿท๏ธ Tag memories โ€“ category, importance, source

- ๐Ÿ”„ Regular cleanup โ€“ archive old, merge duplicates

- ๐Ÿ”’ Encrypt sensitive data โ€“ user privacy first

- ๐Ÿ“Š Monitor memory usage โ€“ track size, retrieval quality

- ๐Ÿงช Test retrieval โ€“ does the right memory come back?

๐ŸŒ Real-World Memory Systems

How popular agents handle memory:


Agent/ProductMemory ApproachDetails
**ChatGPT**Memory featureUser facts stored, toggleable
**Claude**Project knowledgeFiles as long-term context
**Mem0**AI memory layerOpen-source memory framework
**LangChain**Memory modulesBuffer, Summary, Vector options
**Notion AI**Workspace contextUses your Notion pages as memory

Mem0 (formerly OpenMemory) is particularly interesting โ€“ it provides a standalone memory layer any agent can use! ๐Ÿง 

๐Ÿ“ Summary

Key Takeaways:


โœ… 4 Memory types: Working, Short-term, Long-term, Episodic

โœ… Vector DB enables semantic memory search โ€“ game changer!

โœ… Memory management: Summarize, Score, Forget, Tier, Select

โœ… Read/Write cycle: Detect โ†’ Store โ†’ Index โ†’ Retrieve โ†’ Inject

โœ… Implementation: Buffer (simple) โ†’ Summary โ†’ Vector โ†’ Hybrid (best)

โœ… Avoid pitfalls: Over-storing, no expiry, privacy issues, conflicts

โœ… Best practices: Structured data, timestamps, encryption, monitoring


Next article la AI Task Automation deep dive paapom โ€“ agents use panni complex tasks automate! โš™๏ธ

๐Ÿ ๐ŸŽฎ Mini Challenge

Challenge: Design Memory System for Personal Shopping Agent


Agent-laa memory systems implement panna practical exercise:


Scenario: Customer shopping assistant agent โ€“ purchases track, preferences remember panna-onum


Step 1: Working Memory (3 mins)

Current shopping session ma active variables:

  • Current items browsing
  • Budget remaining
  • Session start time

How irukku, when clear aagum? (On session end)


Step 2: Short-term Memory (4 mins)

This session's conversation:

  • Customer: "Show me blue shirts under โ‚น1000"
  • Agent: "Found 5 items..."
  • Customer: "Add medium size to cart"

How store? (Conversation buffer)

How long keep? (Session duration)


Step 3: Long-term Memory (4 mins)

Persistent user profile:

  • Favorite brands: Nike, Adidas
  • Preferred sizes: M, L
  • Budget range: โ‚น500-3000
  • Past purchases: List

How store? (Database, vector DB)

How retrieve? (Semantic search)


Step 4: Episodic Memory (2 mins)

Specific past events:

  • "Last week nee sports shoes buy pannya"
  • "2 months ago return request file panniya"

How track? (Timestamped events)


Step 5: Implement (2 mins)

Pseudo-code write pannunga:

code
On new customer:
1. Load long-term memory (preferences)
2. Initialize working memory (session)
3. Start short-term buffer (conversation)
4. Log episodic events (history)
On session end:
1. Save important info to long-term
2. Clear working memory
3. Log summary to episodic

Memory architecture complete! ๐Ÿง ๐Ÿ’พ

๐Ÿ’ผ Interview Questions

Q1: AI Agent memory โ€“ human memory maari work pannuma?

A: Inspired by human memory, but implementation different. Humans: biological storage, chemical transfers. AI: database storage, vector embeddings, retrieval algorithms. Same concepts, different substrate!


Q2: Vector database why important agent memory-ku?

A: Text-a mathematical vectors convert panni similar content quickly find panna. Example: "flight booking" + "airline reservation" similar vectors (semantically close). Similarity search fast, relevant memories quickly retrieve, retrieval accurate!


Q3: Memory too much irundha problems enna?

A:

  • Context window overflow (token limit exceed)
  • Retrieval slow (too much search)
  • Irrelevant info mix (noise increase)
  • Cost increase (more tokens = more API calls)

Solution: Memory management โ€“ relevant info keep, obsolete info delete, summarization use!


Q4: Long-term memory ku best storage technology?

A:

  • Vector DB (semantic search): Pinecone, Weaviate, Chroma
  • Key-value store (fast retrieval): Redis
  • SQL DB (structured): PostgreSQL
  • Graph DB (relationships): Neo4j

Most agents: Vector DB (semantic) + Cache (speed) combination use!


Q5: Memory privacy security โ€“ user data protection?

A:

  • Encrypt data rest-la (at-rest encryption)
  • Encrypt transmission-la (TLS)
  • Access control (who read/write panna-onum)
  • Data retention policy (delete after X days)
  • Compliance (GDPR, privacy laws)

User data sacred! Proper handling essential! ๐Ÿ”’

โ“ Frequently Asked Questions

โ“ AI Agent ku memory edhuku?
Memory illama every conversation fresh start. Past interactions, user preferences, learned patterns ellaam lost aagum. Memory irundha personalized, context-aware responses kodukka mudiyum.
โ“ Vector database enna?
Text-a mathematical vectors (numbers) aa convert panni store pannum database. Similar content-a quickly find panna helpful. Pinecone, Weaviate, ChromaDB popular options.
โ“ Memory too much aanaa enna aagum?
Context window overflow aagum, irrelevant info mix aagum, response quality drop aagum. Memory management โ€“ what to remember, what to forget โ€“ important skill!
โ“ Human memory maari AI memory work pannuma?
Inspired by human memory, but not identical. Short-term (working memory), long-term (stored knowledge), episodic (specific events) โ€“ similar concepts but different implementations.
๐Ÿง Knowledge Check
Quiz 1 of 1

Test your memory knowledge:

0 of 1 answered