Memory
Persistent Memory with SQLite
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
Persistent Memory with SQLite
Code
cookbook/agent_concepts/memory/02_persistent_memory.py
"""
This example shows how to use the Memory class to create a persistent memory.
Every time you run this, the `Memory` object will be re-initialized from the DB.
"""
from typing import List
from agno.memory.v2.db.schema import MemoryRow
from agno.memory.v2.db.sqlite import SqliteMemoryDb
from agno.memory.v2.memory import Memory
from agno.memory.v2.schema import UserMemory
memory_db = SqliteMemoryDb(table_name="memory", db_file="tmp/memory.db")
memory = Memory(db=memory_db)
john_doe_id = "john_doe@example.com"
# Run 1
memory.add_user_memory(
memory=UserMemory(memory="The user's name is John Doe", topics=["name"]),
user_id=john_doe_id,
)
# Run this the 2nd time
# memory.add_user_memory(
# memory=UserMemory(memory="The user works at a softward company called Agno", topics=["name"]),
# user_id=john_doe_id,
# )
memories: List[MemoryRow] = memory_db.read_memories()
print("All the DB memories:")
for i, m in enumerate(memories):
print(f"{i}: {m.memory['memory']} ({m.last_updated})")
Usage
1
Create a virtual environment
Open the Terminal
and create a python virtual environment.
python3 -m venv .venv
source .venv/bin/activate
2
Install libraries
pip install -U agno
3
Run Example
python cookbook/agent_concepts/memory/02_persistent_memory.py