Fix multi-turn conversation ingestion for AzureOpenAI
Fixes #83
This PR fixes an issue where only the first conversation turn was being ingested when using AzureOpenAI with Memori.
Root cause
On subsequent invocations, conversation_id was not reliably resolved early
enough in the request lifecycle. This prevented prior messages from being
injected and caused new messages to not consistently be written to the same
conversation.
Changes
- Ensured
session_idandconversation_idare resolved early ininject_conversation_messagesso prior messages can be injected correctly - Used idempotent
conversation.create()to safely retrieve or create the active conversation within the timeout window - Ensured only new messages are written while injected history is excluded to prevent duplication
- Added logging to surface when memory is written and which conversation/session is used
- Added test coverage verifying all conversation turns are ingested
Result
- Every user message is ingested on every turn
- Every assistant response is ingested on every turn
- Previous messages are injected for context without duplication
- Public APIs and AzureOpenAI usage remain unchanged
Hi @lindseystead Thanks for catching this and making a contribution. Do you mind creating an issue(bug) for this PR? We will review the issue and PR and provide feedback if necessary.
Thanks again!
Created issue #233 as requested. The issue documents the bug and links to this PR.