Memori icon indicating copy to clipboard operation
Memori copied to clipboard

[Bug] Multi-turn conversation ingestion only records first turn for AzureOpenAI

Open lindseystead opened this issue 2 weeks ago • 0 comments

First Check

  • [x] I added a very descriptive title to this issue.
  • [x] I searched existing issues and documentation.

Memori Version

3.1.0

OS / Python Version

macOS / Python 3.12

LLM Provider

OpenAI

LLM Model & Version

gpt-4o-mini

Database

SQLite

Description

When using AzureOpenAI with Memori, only the first conversation turn is being ingested into memory. Subsequent user messages and assistant responses are not being recorded.

Expected Behavior: All conversation turns should be ingested:

  • Every user message on every turn
  • Every assistant response on every turn
  • All messages written to the same conversation

Actual Behavior: Only the first conversation turn is recorded. Subsequent turns are not ingested.

Root Cause: conversation_id was not being resolved early enough in the request lifecycle on subsequent API calls, preventing previous messages from being injected and new messages from being written to the same conversation.

Fix: See PR #231 which resolves this issue.

Minimal Reproducible Example

from openai import AzureOpenAI
from memori import Memori
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

# Setup AzureOpenAI client
client = AzureOpenAI(
    api_key=os.environ["AZURE_OPENAI_API_KEY"],
    api_version=os.environ["AZURE_OPENAI_API_VERSION"],
    azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
)

# Setup Memori with SQLite
engine = create_engine("sqlite:///azure_openai_memory.db")
Session = sessionmaker(bind=engine)
mem = Memori(conn=Session).llm.register(client)
mem.attribution(entity_id="user-123", process_id="my-app")
mem.config.storage.build()

# First call - works ✅
response1 = client.chat.completions.create(
    model=os.environ["AZURE_OPENAI_DEPLOYMENT_NAME"],
    messages=[{"role": "user", "content": "Hello"}],
)
# Messages are recorded

# Second call - doesn't work ❌
response2 = client.chat.completions.create(
    model=os.environ["AZURE_OPENAI_DEPLOYMENT_NAME"],
    messages=[{"role": "user", "content": "What did I say?"}],
)
# Messages are NOT recorded - bug!

Log Output / Stack Trace

No errors - the issue is silent. Messages simply aren't being written to the database after the first turn.

Participation

  • [x] I am willing to submit a pull request for this issue.

lindseystead avatar Dec 12 '25 23:12 lindseystead