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-dotenv

Example

The following agent uses Memori to maintain persistent memory across conversations with SQLite:

1import os
2
3from kern.agent import Agent
4from kern.models.openai import OpenAIResponses
5from dotenv import load_dotenv
6from sqlalchemy import create_engine
7from sqlalchemy.orm import sessionmaker
8
9from memori import Memori
10
11load_dotenv()
12
13db_path = os.getenv("DATABASE_PATH", "memori_agno.db")
14engine = create_engine(f"sqlite:///{db_path}")
15Session = sessionmaker(bind=engine)
16
17model = OpenAIResponses(id="gpt-5.2")
18
19mem = Memori(conn=Session).kern.register(openai_chat=model)
20mem.attribution(entity_id="customer-456", process_id="support-agent")
21mem.config.storage.build()
22
23agent = 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)
31
32if __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")
38
39 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")
42
43 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

  1. Create Database Engine: Use SQLAlchemy to create a database connection
  2. Initialize Memori: Create a Memori instance with the database session
  3. Register with Model: Register Memori with your Kern agent using .kern.register()
  4. Set Attribution: Define entity and process IDs for memory tracking
  5. Build Storage: Initialize the database schema with .config.storage.build()

Developer Resources