# Memori Integration (/examples/integrations/memory/memori-integration)



Demonstrates conversational memory persistence with Memori and Agno.

```python title="memori_integration.py"
"""
Memori Integration
==================

Demonstrates conversational memory persistence with Memori and Agno.
"""

import os

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from dotenv import load_dotenv
from memori import Memori
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
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")

# Initialize Memori and register with LLM client
mem = Memori(conn=Session).llm.register(model.get_client())
mem.attribution(entity_id="cookbook-agent", process_id="demo-session")
mem.config.storage.build()


# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
    model=model,
    instructions=[
        "You are a helpful assistant.",
        "Remember customer preferences and history from previous conversations.",
    ],
    markdown=True,
)


# ---------------------------------------------------------------------------
# Run Example
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    print("Customer: I'm a Python developer and I love building web applications")
    response1 = agent.run("I'm a Python developer and I love building web applications")
    print(f"Agent: {response1.content}\n")

    print("Customer: What do you remember about my programming background?")
    response2 = agent.run("What do you remember about my programming background?")
    print(f"Agent: {response2.content}\n")

    print("Customer: I prefer working in the morning hours, around 8-11 AM")
    response3 = agent.run("I prefer working in the morning hours, around 8-11 AM")
    print(f"Agent: {response3.content}\n")

    print("Customer: What were my productivity preferences again?")
    response4 = agent.run("What were my productivity preferences again?")
    print(f"Agent: {response4.content}")
```

## Memory timing and attribution [#memory-timing-and-attribution]

This uses [Memori BYODB](https://memorilabs.ai/docs/memori-byodb/): the registered OpenAI client is the same cached client the agent uses, and SQLite stores the memory data. Fact augmentation runs in the background, so an immediate follow-up can precede newly extracted facts. Inspect the stored result before treating the printed answers as a recall test.

All four turns use the same `entity_id`. Use the actual user's identifier when adapting this example for multiple users; `process_id` identifies the application process or workflow.

## Run the Example [#run-the-example]

<Steps>
    <Step title="Set up your virtual environment">
      <CodeBlockTabs defaultValue="Mac">
        <CodeBlockTabsList>
          <CodeBlockTabsTrigger value="Mac">
            Mac
          </CodeBlockTabsTrigger>

          <CodeBlockTabsTrigger value="Windows">
            Windows
          </CodeBlockTabsTrigger>
        </CodeBlockTabsList>

        <CodeBlockTab value="Mac">
          ```bash
          uv venv --python 3.12
          source .venv/bin/activate
          ```
        </CodeBlockTab>

        <CodeBlockTab value="Windows">
          ```bash
          uv venv --python 3.12
          .venv\Scripts\activate
          ```
        </CodeBlockTab>
      </CodeBlockTabs>
    </Step>

  <Step title="Install dependencies">
    ```bash
    uv pip install -U agno memori openai python-dotenv sqlalchemy
    ```
  </Step>

  <Step title="Export your OpenAI API key">
    <CodeBlockTabs defaultValue="Mac/Linux">
      <CodeBlockTabsList>
        <CodeBlockTabsTrigger value="Mac/Linux">
          Mac/Linux
        </CodeBlockTabsTrigger>

        <CodeBlockTabsTrigger value="Windows">
          Windows
        </CodeBlockTabsTrigger>
      </CodeBlockTabsList>

      <CodeBlockTab value="Mac/Linux">
        ```bash
        export OPENAI_API_KEY="your_openai_api_key_here"
        ```
      </CodeBlockTab>

      <CodeBlockTab value="Windows">
        ```bash
        $Env:OPENAI_API_KEY="your_openai_api_key_here"
        ```
      </CodeBlockTab>
    </CodeBlockTabs>
  </Step>

  <Step title="Run the example">
    Save the code above as `memori_integration.py`, then run:

    ```bash
    python memori_integration.py
    ```
  </Step>
</Steps>

Full source: [cookbook/11\_memory/integrations/memori\_integration.py](https://github.com/agno-agi/agno/blob/8f36eaf2d18e91afa7b327eec66a3cd3685dcb87/cookbook/11_memory/integrations/memori_integration.py)
