6.2.5 · HinglishAI Agents & Tool Use

Memory systems for agents

4,127 words19 min readRead in English

6.2.5 · AI-ML › AI Agents & Tool Use

What Is Agent Memory?

The Three-Layer Memory Architecture

Modern agent memory systems ek three-tier hierarchy use karte hain, jo human memory se inspired hai:

1. Working Memory (Short-Term)

2. Episodic Memory (Mid-Term)

3. Semantic Memory (Long-Term)

Memory Operations: The Four Primitives

Saare memory systems chaar core operations implement karte hain:

Derivation: When to Forget?

Problem: Infinite memory → cost explosion + noise (irrelevant purana data).

Solution: Ek forgetting policy implement karo.

Approach 1: Recency-Based (Sliding Window) Jahan episode ka timestamp hai, retention period hai (jaise 30 days).

WHY: Purana data relevant hone ki probability kam hoti hai. Implement karna simple hai.

Approach 2: Importance-Based Importance score ke hisaab se top-K rakho.

WHY THIS STEP? AccessCount → frequently use hone wale facts valuable hote hain. UserFeedback → user-starred items persist hone chahiye.

Approach 3: Semantic Redundancy Agar naye episode ka embedding hai aur existing episode ka hai:

WHY: Near-duplicate information store karne se bacho. Space bachata hai + retrieval noise kam karta hai.

Retrieval Strategies: How to Find the Right Memory

Derivation from First Principles:

  1. WHY RELEVANCE? Agar agent "Python errors" discuss kar raha hai, toh "dinner recipes" ke baare mein memories retrieve karna context waste karta hai. Semantic similarity topical match ensure karti hai.

  2. WHY RECENCY? Information decay hoti hai. Kal ki user preference ek saal purani preference se zyada reliable hai. Exponential decay human forgetting curve model karta hai.

  3. WHY IMPORTANCE? Kuch facts evergreen hote hain. "Hamare company ka policy on X" persist hona chahiye chahe recently access na hua ho. Access frequency yeh signal karta hai.

  4. HOW TO COMBINE? Linear combination simple, interpretable, aur fast hai. Har term ko [0,1] mein normalize karo, phir weight lagao.

Step-by-step scoring:

Memory Architectures in Practice

Pattern 1: Conversation Buffer Memory

Pattern 2: Summary Memory

Pattern 3: Vector Store Memory

Pattern 4: Hybrid Memory (Combining All Three)

Common Mistakes & How to Avoid Them

Connections

  • Retrieval-Augmented Generation (RAG): Memory systems relevant context fetch karne ke liye RAG principles use karte hain.
  • Vector Databases: Episodic aur semantic memory aksar vector DBs (Pinecone, Chroma) mein store hoti hai.
  • LM Context Window Management: Working memory context window constraints ke andar fit hoti hai.
  • Knowledge Graphs: Semantic memory aksar knowledge graphs (entities + relations) ke roop mein structured hoti hai.
  • Prompt Engineering: Memory retrieval results ko effective prompts mein format karna padta hai.
  • Agent Planning and Reasoning: Memory woh "experience" provide karta hai jis par planning rely karti hai.
  • Multi-Agent Systems: Agents semantic memory share kar sakte hain (common knowledge base) jabki apni alag episodic memory maintain karte hain.

Recall Ek 12-Saal Ke Bachche Ko Explain Karo

Socho tum apne homework ke liye ek robot assistant bana rahe ho. Har baar jab tum usse kuch poochte ho, woh jawab deta hai, phir sab kuch bhool jaata hai. Toh agli baar jab tum poochho "What was my math homework?", woh bolta hai "I don't know, I just woke up!" Yeh annoying hoga na? Memory systems tumhare robot ko ek notebook dene jaisa hai:

  • Working memory = woh page jis par robot abhi likh raha hai (aaj ka homework)
  • Episodic memory = notebook ke purane pages (pichle hafte tumne kya homework kiya)
  • Semantic memory = ek cheat sheet jो robot ne useful facts ki banayi (jaise "math homework hamesha page 45 par hota hai")

Jab tum koi sawaal poochte ho, robot:

  1. Current page dekhta hai (working memory)
  2. Related cheez dhundne ke liye purane pages palatta hai (episodic memory)
  3. General rules ke liye cheat sheet check karta hai (semantic memory) Is tarah, robot yaad karta hai ki tum pehle kya baat kar chuke ho, past mistakes se seekhta hai, aur waqt ke saath smarter hota jaata hai. Yeh aisa hai jaise ek study buddy ho jo actually dhyan deta hai!

Flashcards

#flashcards/ai-ml

Agent memory systems ki teeno layers kya hain? :: Working memory (short-term, current context), Episodic memory (mid-term, past interactions), Semantic memory (long-term, general knowledge).

Agents ko sirf conversation history se zyada memory kyun chahiye?
Interactions ke beech state maintain karne ke liye, experience se seekhne ke liye, long-term context build karne ke liye, aur sawaal ya galtiyan repeat karne se bachne ke liye.
Agent systems mein working memory kya hai?
Current task ke liye immediate context, LM ke context window mein stored, typically last few conversation turns plus active reasoning steps.
Episodic memory kya hai?
Past interaction sequences (episodes) ka ek store jo semantic search, temporal lookup, ya entity-based queries se retrieve kiya ja sakta hai. "Kab kya hua" archive karta hai.
Agents mein semantic memory kya hai?
Specific episodes se independent general facts, procedures, aur world knowledge ka long-term storage. Knowledge graphs ya key-value stores ke roop mein structured.
Chaar core memory operations kya hain?
Write (store), Read (retrieve), Update (modify), Forget (delete).
Memory systems mein forgetting important kyun hai?
Storage costs manage karne ke liye, irrelevant purane data se retrieval noise kam karne ke liye, performance improve karne ke liye, aur privacy requirements respect karne ke liye.
Memory retrieval scoring formula kya hai?
Score(m, C) = α·Relevance(m, C) + β·Recency(m) + γ·Importance(m), jahan α, β, γ weights hain (typically 0.7, 0.2, 0.1).
Conversation buffer memory kya hai?
Sabse simple memory type jo FIFO queue use karke working memory mein last N messages rakhti hai.
Summary memory kya hai?
Ek memory system jo raw messages ki jagah conversations ki compressed summaries store karta hai, space bachata hai lekin detail ki cost pe.
Vector store memory kya hai?
Embeddings ke roop mein vector database mein stored memory, jo nearest-neighbor retrieval ke zariye semantic search enable karti hai.
Hybrid memory architecture kya hai?
Ek system jo working memory (buffer), episodic memory (vector store), aur semantic memory (knowledge graph) ko smart retrieval routing ke saath combine karta hai.
Working memory ke liye capacity constraint kya hai?
Working Memory Size ≤ Context Window - System Prompt - Output Buffer
Recency-based forgetting kaise kaam karta hai?
Keep(e) = 1 agar t_now - t_e < T_window, warna 0. Retention window se purane memories delete karta hai.
Importance-based memory ranking kaise kaam karti hai?
Importance(e) = w1·AccessCount(e) + w2·Recency(e) + w3·UserFeedback(e). Importance score ke hisaab se top-K items rakhta hai.
Retrieval scoring mein relevance component kya hai?
Relevance(m, C) = cosine_similarity(embed(m), embed(C)), memory aur current context ke beech semantic similarity measure karta hai.

Retrieval scoring mein recency component kya hai? :: Recency(m) = e^(-λ(t_now - t_m)), human forgetting curves model karta hua ek exponential decay.

Semantic redundancy pruning kya hai?
Agar cosine_sim(v_new, v_old) > threshold (jaise 0.95) ho, toh duplicates store karne se bachne ke liye purani memory merge ya delete karo.
Saari history LM prompt mein kyun nahi daalni chahiye?
Context windows limited hain, irrelevant history noise add karti hai aur performance degrade karti hai, aur costs input token count ke saath linearly scale karti hain.
Sirf embedding similarity ki jagah hybrid scoring kyun use karein?
Pure similarity recency (outdated info) aur importance (rare lekin critical facts) miss karti hai. Hybrid scoring semantic match ko temporal aur usage signals ke saath balance karta hai.
Agar memories kabhi update na hon toh kya hota hai?
Stale facts persist karte hain (user preferences change hoti hain, APIs update hoti hain, facts outdated ho jaate hain), jis se agent khud se contradict karta hai ya galat information deta hai.

Concept Map

transforms stateless calls into

organized as

inspired by

tier 1

tier 2

constrained by

managed via

stores

recalled via

holds timestamp, summary, facts

Agent Memory

Stateful Context-Aware Agents

Three-Layer Architecture

Working Memory Short-Term

Episodic Memory Mid-Term

LM Context Window

Sliding Window / Token Budget

Episode Record

Semantic Search Retrieval

Human Memory