Loading...
Loading...
Implement agent memory - short-term, long-term, semantic storage, and retrieval
npx skill4agent add pluginagentmarketplace/custom-plugin-ai-agents agent-memory| Parameter | Type | Required | Description | Default |
|---|---|---|---|---|
| string | Yes | Memory goal | - |
| enum | No | | |
| enum | No | | |
from langchain.memory import ConversationBufferWindowMemory
# Simple buffer (last k messages)
memory = ConversationBufferWindowMemory(k=10)
# With summarization
from langchain.memory import ConversationSummaryBufferMemory
memory = ConversationSummaryBufferMemory(llm=llm, max_token_limit=2000)
# Vector store memory
from langchain.memory import VectorStoreRetrieverMemory
memory = VectorStoreRetrieverMemory(retriever=vectorstore.as_retriever())| Type | Use Case | Pros | Cons |
|---|---|---|---|
| Buffer | Short chats | Simple | No compression |
| Summary | Long chats | Compact | Loses detail |
| Vector | Semantic recall | Relevant | Slower |
| Hybrid | Production | Best of all | Complex |
class ProductionMemory:
def __init__(self):
self.short_term = BufferMemory(k=10) # Recent
self.summary = SummaryMemory() # Compressed
self.long_term = VectorMemory() # Semantic| Issue | Solution |
|---|---|
| Context overflow | Add summarization |
| Slow retrieval | Cache, reduce k |
| Irrelevant recall | Improve embeddings |
| Memory not persisting | Check storage backend |
rag-systemsllm-integrationai-agent-basics