Agent Memory Systems System
Enterprise-grade skill for memory, cornerstone, intelligent, agents. Includes structured workflows, validation checks, and reusable patterns for ai research.
Agent Memory Systems
Overview
A skill for implementing memory management systems in AI agents ā covering working memory, conversation history, persistent storage, and memory-augmented generation. Provides patterns for building agents that maintain state, recall past interactions, and learn from experience across sessions.
When to Use
- Designing agents with persistent state
- Building chatbots that remember user preferences
- Implementing conversation history management
- Creating knowledge-accumulating agents
- Managing context window limits efficiently
Quick Start
# Implement basic memory claude "Add conversation memory to this chatbot agent" # Persistent memory store claude "Create a persistent memory system using SQLite for this agent"
Memory Tiers
Tier 1: Working Memory (In-Context)
Current conversation messages within the context window:
class WorkingMemory { private messages: Message[] = []; private maxTokens: number; add(message: Message) { this.messages.push(message); this.trim(); } private trim() { while (this.tokenCount() > this.maxTokens) { // Remove oldest non-system messages const idx = this.messages.findIndex(m => m.role !== 'system'); if (idx >= 0) this.messages.splice(idx, 1); } } }
Tier 2: Session Memory (Short-Term)
Summarized conversation history for the current session:
class SessionMemory { private summaries: string[] = []; async summarizeAndStore(messages: Message[]) { const summary = await llm.call( `Summarize the key points from this conversation:\n${messages.map(m => `${m.role}: ${m.content}`).join('\n')}` ); this.summaries.push(summary); } }
Tier 3: Persistent Memory (Long-Term)
Stored across sessions in a database:
class PersistentMemory { async store(key: string, value: any, metadata?: Record<string, any>) { await db.memories.upsert({ key, value: JSON.stringify(value), embedding: await embed(JSON.stringify(value)), ...metadata, updatedAt: new Date(), }); } async recall(query: string, limit = 5): Promise<Memory[]> { const embedding = await embed(query); return db.memories.similaritySearch(embedding, limit); } }
Memory Operations
| Operation | Description | When |
|---|---|---|
| Store | Save new information | After decisions, new facts |
| Retrieve | Find relevant past info | Before responding |
| Update | Modify existing memory | When facts change |
| Summarize | Compress verbose memories | When approaching limits |
| Forget | Remove outdated info | During maintenance |
| Consolidate | Merge related memories | Periodically |
Context Window Strategy
Total budget: 200K tokens
āāā System prompt: 2K (1%)
āāā Retrieved memory: 20K (10%)
āāā Recent messages: 40K (20%)
āāā Current context: 118K (59%)
āāā Response reserve: 20K (10%)
Best Practices
- Tiered storage ā Use working memory for current context, persistent for long-term
- Semantic retrieval ā Use embeddings, not keyword matching
- Summarize aggressively ā Compress old context to save tokens
- Relevance scoring ā Only inject memories above a similarity threshold
- Decay unused memories ā Reduce priority of memories not accessed recently
- Separate concerns ā Keep user preferences, project facts, and conversation history separate
- Handle staleness ā Mark memory update timestamps, prefer recent over old
- Test recall ā Verify your retrieval system returns actually relevant results
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Full-Stack Code Reviewer
Comprehensive code review skill that checks for security vulnerabilities, performance issues, accessibility, and best practices across frontend and backend code.
Test Suite Generator
Generates comprehensive test suites with unit tests, integration tests, and edge cases. Supports Jest, Vitest, Pytest, and Go testing.
Pro Architecture Workspace
Battle-tested skill for architectural, decision, making, framework. Includes structured workflows, validation checks, and reusable patterns for development.