Long-Term Memory for AI Agents: Persistent Context and Semantic Memory Architectures
Current AI assistants suffer from session amnesia — every conversation starts from zero. Long-term memory enables agents to remember user preferences, past interactions, and learned facts across sessions.
1. Three Types of Agent Memory
| Memory Type | Purpose | Storage |
|---|---|---|
| Episodic Memory | Remember specific past interactions | Vector DB + timestamps |
| Semantic Memory | Store learned facts and preferences | Key-value store + embeddings |
| Procedural Memory | Remember how to do tasks | Workflow templates + tool configs |
2. Implementation Architecture
class AgentLongTermMemory {
private vectorStore: VectorDB;
private factStore: KeyValueStore;
async remember(conversation: Message[]): Promise<void> {
// Extract and store key facts
const facts = await extractFacts(conversation);
for (const fact of facts) {
await this.factStore.set(fact.key, fact.value);
await this.vectorStore.upsert(fact.embedding, fact.metadata);
}
}
async recall(query: string): Promise<MemoryContext> {
// Retrieve relevant episodic memories
const episodes = await this.vectorStore.search(query, { topK: 5 });
// Retrieve relevant facts
const facts = await this.factStore.getRelated(query);
return { episodes, facts };
}
}
// Usage: Agent remembers user preferences across sessions
const memory = new AgentLongTermMemory();
const context = await memory.recall("What programming language does this user prefer?");
// Returns: "User prefers TypeScript with strict mode, mentioned on June 15"
Long-term memory transforms AI from a stateless tool into a persistent collaborator that genuinely knows you over time.



















