QA
Intermediate LevelAI, LLMs, Embeddings & MCP

How do AI Agents manage Short-Term, Long-Term, and Episodic Memory?

❓ Interview Prompt: Compare short-term context window memory, long-term vector DB memory, and episodic session reflection.

Autonomous AI Agents require memory systems to maintain context across multi-turn user interactions:

1. Short-Term Memory:

Stored directly inside the LLM Context Window. Maintains recent conversation history and active tool results. Pruned or summarized when token limits are reached.

2. Long-Term Memory:

Stored in Vector Databases or Key-Value stores. Holds persistent facts, user preferences, and domain knowledge retrieved via semantic search.

3. Episodic / Working Memory:

Stores structured logs of past agent problem-solving sessions. Allows agents to reflect on previous mistakes and reuse proven action plans.

Code Implementation Example

typescript
class AgentMemoryManager {
  private shortTermContext: Message[] = [];
  private longTermVectorStore: VectorStore;

  async rememberUserPreference(userId: string, preference: string) {
    const vector = await embedText(preference);
    await this.longTermVectorStore.upsert({ id: userId, vector, metadata: { preference } });
  }

  async recallPreferences(userId: string, query: string): Promise<string[]> {
    const queryVec = await embedText(query);
    const results = await this.longTermVectorStore.query({ vector: queryVec, filter: { userId } });
    return results.map(r => r.metadata.preference);
  }
}
💡Agent memory manager separating short-term context messages from long-term vector store preferences.
🎯 Interview Key Takeaway

Agents combine short-term context window memory with long-term vector store persistence and episodic session reflection.

#Agent Memory#Vector Search#Short-Term#Long-Term#Intermediate
Back to all AI, LLMs, Embeddings & MCP Questions→

More AI, LLMs, Embeddings & MCP Interview Questions

Beginner LevelAI, LLMs, Embeddings & MCP

What are Vector Embeddings and Cosine Similarity in AI Semantic Search?

Beginner LevelAI, LLMs, Embeddings & MCP

What is the Model Context Protocol (MCP) and how does it connect LLMs to external tools?

Beginner LevelAI, LLMs, Embeddings & MCP

What is Retrieval-Augmented Generation (RAG) and how does it prevent LLM hallucinations?