Memori
Integrate Agno with Memori to give agents persistent, searchable conversation memory.
Prerequisites
The example uses Memori BYODB with a local SQLite database.
uv pip install -U agno memori openai sqlalchemy python-dotenv
export OPENAI_API_KEY="your_openai_api_key"Example
The following agent uses Memori to maintain persistent memory across conversations with SQLite:
import os
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from dotenv import load_dotenv
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from memori import Memori
load_dotenv()
db_path = os.getenv("DATABASE_PATH", "memori_agno.db")
engine = create_engine(f"sqlite:///{db_path}")
Session = sessionmaker(bind=engine)
model = OpenAIChat(id="gpt-5.2")
mem = Memori(conn=Session).llm.register(model.get_client())
mem.attribution(entity_id="customer-456", process_id="support-agent")
mem.config.storage.build()
agent = Agent(
model=model,
instructions=[
"You are a helpful customer support agent.",
"Remember customer preferences and history from previous conversations.",
],
markdown=True,
)
if __name__ == "__main__":
print("Customer: Hi, I'd like to order a large pepperoni pizza with extra cheese")
response1 = agent.run(
"Hi, I'd like to order a large pepperoni pizza with extra cheese"
)
print(f"Agent: {response1.content}\n")
print("Customer: Actually, can you remind me what I just ordered?")
response2 = agent.run("Actually, can you remind me what I just ordered?")
print(f"Agent: {response2.content}\n")
print("Customer: Perfect! And what size was that again?")
response3 = agent.run("Perfect! And what size was that again?")
print(f"Agent: {response3.content}")Newly augmented memories may not be ready for the immediately following call. The three calls demonstrate the integration; they do not guarantee immediate recall of each new fact.
Key Features
- LLM Agnostic: OpenAI, Anthropic, Bedrock, Gemini, Grok (xAI) - all modes (streamed, unstreamed, sync, async)
- Smart Attribution: Track memories by entity (e.g., customer) and process (e.g., support agent)
- Advanced Augmentation: Background memory augmentation; capture and recall still operate on the response path
- Database Flexibility: Supports PostgreSQL, MySQL/MariaDB, SQLite, MongoDB, CockroachDB, Neon, Supabase, Oracle, and more
Setup
- Create Database Engine: Use SQLAlchemy to create a database connection
- Initialize Memori: Create a Memori instance with the database session
- Register with Model: Register Memori with your model's client using
.llm.register() - Set Attribution: Define entity and process IDs for memory tracking
- Build Storage: Initialize the database schema with
.config.storage.build()