Memory
Agent Memory Management
Examples
- Introduction
- Getting Started
- Agents
- Teams
- Workflows
- Applications
Agent Concepts
- Multimodal
- RAG
- Knowledge
- Memory
- Basic Memory Operations
- Persistent Memory with SQLite
- Agentic Memory Creation
- Basic Memory Search
- Agentic Memory Search
- Agent Memory Creation
- Agent Memory Management
- Agent with Session Summaries
- Multiple Agents Sharing Memory
- Multi-User Multi-Session Chat
- MongoDB Memory Storage
- PostgreSQL Memory Storage
- Redis Memory Storage
- Mem0 Memory
- Async
- Hybrid Search
- Storage
- Tools
- Vector Databases
- Embedders
Models
- Anthropic
- AWS Bedrock
- AWS Bedrock Claude
- Azure AI Foundry
- Azure OpenAI
- Cohere
- DeepInfra
- DeepSeek
- Fireworks
- Gemini
- Groq
- Hugging Face
- Mistral
- NVIDIA
- Ollama
- OpenAI
- Perplexity
- Together
- xAI
- IBM
- LM Studio
- LiteLLM
- LiteLLM OpenAI
Memory
Agent Memory Management
Code
cookbook/agent_concepts/memory/07_agent_manages_memories.py
from agno.agent.agent import Agent
from agno.memory.v2.db.sqlite import SqliteMemoryDb
from agno.memory.v2.memory import Memory
from agno.models.openai.chat import OpenAIChat
memory_db = SqliteMemoryDb(table_name="memory", db_file="tmp/memory.db")
memory = Memory(db=memory_db)
# Reset the memory for this example
memory.clear()
john_doe_id = "john_doe@example.com"
agent = Agent(
model=OpenAIChat(id="gpt-4o"),
memory=memory,
enable_agentic_memory=True,
)
agent.print_response(
"My name is John Doe and I like to hike in the mountains on weekends.",
stream=True,
user_id=john_doe_id,
)
agent.print_response("What are my hobbies?", stream=True, user_id=john_doe_id)
memories = memory.get_user_memories(user_id=john_doe_id)
print("Memories about John Doe:")
for i, m in enumerate(memories):
print(f"{i}: {m.memory}")
agent.print_response(
"Remove all existing memories of me. Completely clear the DB.",
stream=True,
user_id=john_doe_id,
)
memories = memory.get_user_memories(user_id=john_doe_id)
print("Memories about John Doe:")
for i, m in enumerate(memories):
print(f"{i}: {m.memory}")
agent.print_response(
"My name is John Doe and I like to paint.", stream=True, user_id=john_doe_id
)
memories = memory.get_user_memories(user_id=john_doe_id)
print("Memories about John Doe:")
for i, m in enumerate(memories):
print(f"{i}: {m.memory}")
agent.print_response("Remove any memory of my name.", stream=True, user_id=john_doe_id)
memories = memory.get_user_memories(user_id=john_doe_id)
print("Memories about John Doe:")
for i, m in enumerate(memories):
print(f"{i}: {m.memory}")
Usage
1
Create a virtual environment
Open the Terminal
and create a python virtual environment.
python3 -m venv .venv
source .venv/bin/activate
2
Set your API key
export OPENAI_API_KEY=xxx
3
Install libraries
pip install -U agno openai
4
Run Example
python cookbook/agent_concepts/memory/07_agent_manages_memories.py