diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs index 33717410..7711c37b 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs @@ -38,6 +38,13 @@ public class ConversationStorage : IConversationStorage var db = _services.GetRequiredService(); var dialogElements = new List(); + // Prevent duplicate record to be inserted + var dialogs = db.GetConversationDialogs(conversationId); + if (dialogs.Any(x => x.MetaData.MessageId == dialog.MessageId && x.Content == dialog.Content)) + { + return; + } + if (dialog.Role == AgentRole.Function) { var meta = new DialogMetaData