Memori
Memori is an open-source memory layer for AI. It automatically captures conversations, extracts meaningful facts, and makes them searchable across entities, processes, and sessions.
Prerequisites
The following example requires the memori library.
1uv pip install -U memori sqlalchemy python-dotenvExample
The following agent uses Memori to maintain persistent memory across conversations with SQLite:
1import os23from kern.agent import Agent4from kern.models.openai import OpenAIResponses5from dotenv import load_dotenv6from sqlalchemy import create_engine7from sqlalchemy.orm import sessionmaker89from memori import Memori1011load_dotenv()1213db_path = os.getenv("DATABASE_PATH", "memori_agno.db")14engine = create_engine(f"sqlite:///{db_path}")15Session = sessionmaker(bind=engine)1617model = OpenAIResponses(id="gpt-5.2")1819mem = Memori(conn=Session).kern.register(openai_chat=model)20mem.attribution(entity_id="customer-456", process_id="support-agent")21mem.config.storage.build()2223agent = Agent(24 model=model,25 instructions=[26 "You are a helpful customer support agent.",27 "Remember customer preferences and history from previous conversations.",28 ],29 markdown=True,30)3132if __name__ == "__main__":33 print("Customer: Hi, I'd like to order a large pepperoni pizza with extra cheese")34 response1 = agent.run(35 "Hi, I'd like to order a large pepperoni pizza with extra cheese"36 )37 print(f"Agent: {response1.content}\n")3839 print("Customer: Actually, can you remind me what I just ordered?")40 response2 = agent.run("Actually, can you remind me what I just ordered?")41 print(f"Agent: {response2.content}\n")4243 print("Customer: Perfect! And what size was that again?")44 response3 = agent.run("Perfect! And what size was that again?")45 print(f"Agent: {response3.content}")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: AI-powered memory augmentation with no latency impact
- 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 Kern agent using
.kern.register() - Set Attribution: Define entity and process IDs for memory tracking
- Build Storage: Initialize the database schema with
.config.storage.build()