Examples
- Examples
- Getting Started
- Agents
- Teams
- Workflows
- Applications
- Streamlit Apps
- Evals
Agent Concepts
- Reasoning
- Multimodal
- RAG
- User Control Flows
- Knowledge
- Memory
- Built-in Memory
- Standalone Memory Operations
- Persistent Memory with SQLite
- Custom Memory Creation
- Memory Search
- Agent With Memory
- Agentic Memory
- Agent with Session Summaries
- Multiple Agents Sharing Memory
- Custom Memory
- Multi-User Multi-Session Chat
- Multi-User Multi-Session Chat Concurrent
- Memory References
- Session Summary References
- Mem0 Memory
- DB
- Async
- Hybrid Search
- Storage
- Tools
- Vector Databases
- Context
- Embedders
- Agent State
- Observability
- Miscellaneous
Models
- Anthropic
- AWS Bedrock
- AWS Bedrock Claude
- Azure AI Foundry
- Azure OpenAI
- Cerebras
- Cerebras OpenAI
- Cohere
- DeepInfra
- DeepSeek
- Fireworks
- Gemini
- Groq
- Hugging Face
- IBM
- LM Studio
- LiteLLM
- LiteLLM OpenAI
- Meta
- Mistral
- NVIDIA
- Ollama
- OpenAI
- Perplexity
- Together
- XAI
- Vercel
DB
SQLite Memory Storage
Code
cookbook/agent_concepts/memory/sqlite_memory.py
Copy
"""
This example shows how to use the Memory class with SQLite storage.
"""
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 import OpenAIChat
from agno.storage.sqlite import SqliteStorage
# Create SQLite memory database
memory_db = SqliteMemoryDb(
table_name="agent_memories", # Table name to use in the database
db_file="tmp/memory.db", # Path to SQLite database file
)
# Create memory instance with SQLite backend
memory = Memory(db=memory_db)
# This will create the table if it doesn't exist
memory.clear()
# Session and user identifiers
session_id = "sqlite_memories"
user_id = "sqlite_user"
# Create agent with memory and SQLite storage
agent = Agent(
model=OpenAIChat(id="gpt-4o-mini"),
memory=memory,
storage=SqliteStorage(
table_name="agent_sessions",
db_file="tmp/memory.db"
),
enable_user_memories=True,
enable_session_summaries=True,
)
# First interaction - introducing personal information
agent.print_response(
"My name is John Doe and I like to hike in the mountains on weekends.",
stream=True,
user_id=user_id,
session_id=session_id,
)
# Second interaction - testing if memory was stored
agent.print_response(
"What are my hobbies?",
stream=True,
user_id=user_id,
session_id=session_id
)
# Display the memories stored in SQLite
memories = memory.get_user_memories(user_id=user_id)
print("Memories stored in SQLite:")
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.
Copy
python3 -m venv .venv
source .venv/bin/activate
2
Set environment variables
Copy
export OPENAI_API_KEY=xxx
3
Install libraries
Copy
pip install -U agno openai
4
Run Example
Copy
python cookbook/agent_concepts/memory/sqlite_memory.py
Was this page helpful?
Assistant
Responses are generated using AI and may contain mistakes.