diff --git a/src/Infrastructure/BotSharp.Abstraction/Loggers/Models/ConversationStateLogModel.cs b/src/Infrastructure/BotSharp.Abstraction/Loggers/Models/ConversationStateLogModel.cs index 98624759f..7033d73b0 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Loggers/Models/ConversationStateLogModel.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Loggers/Models/ConversationStateLogModel.cs @@ -4,10 +4,16 @@ public class ConversationStateLogModel { [JsonPropertyName("conversation_id")] public string ConversationId { get; set; } + + [JsonPropertyName("agent_id")] + public string AgentId { get; set; } + [JsonPropertyName("message_id")] public string MessageId { get; set; } + [JsonPropertyName("states")] public Dictionary States { get; set; } + [JsonPropertyName("created_at")] public DateTime CreateTime { get; set; } = DateTime.UtcNow; } diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs index aecce9131..410589e7f 100644 --- a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs +++ b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs @@ -188,7 +188,8 @@ public override async Task OnResponseGenerated(RoleDialogModel message) if (string.IsNullOrEmpty(conversationId)) return; var conv = _services.GetRequiredService(); - await SendStateLog(conv.ConversationId, _state.GetStates(), message); + var routingCtx = _services.GetRequiredService(); + await SendStateLog(conv.ConversationId, routingCtx.EntryAgentId, _state.GetStates(), message); if (message.Role == AgentRole.Assistant) { @@ -438,9 +439,9 @@ private async Task SendContentLog(ContentLogInputModel input) await _chatHub.Clients.User(_user.Id).SendAsync(CONTENT_LOG_GENERATED, BuildContentLog(input)); } - private async Task SendStateLog(string conversationId, Dictionary states, RoleDialogModel message) + private async Task SendStateLog(string conversationId, string agentId, Dictionary states, RoleDialogModel message) { - await _chatHub.Clients.User(_user.Id).SendAsync(STATE_LOG_GENERATED, BuildStateLog(conversationId, states, message)); + await _chatHub.Clients.User(_user.Id).SendAsync(STATE_LOG_GENERATED, BuildStateLog(conversationId, agentId, states, message)); } private async Task SendAgentQueueLog(string conversationId, string log) @@ -479,11 +480,12 @@ private string BuildContentLog(ContentLogInputModel input) return json; } - private string BuildStateLog(string conversationId, Dictionary states, RoleDialogModel message) + private string BuildStateLog(string conversationId, string agentId, Dictionary states, RoleDialogModel message) { var log = new ConversationStateLogModel { ConversationId = conversationId, + AgentId = agentId, MessageId = message.MessageId, States = states, CreateTime = DateTime.UtcNow diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDialogDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDialogDocument.cs index b71ae40c3..12442cdcf 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDialogDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDialogDocument.cs @@ -3,5 +3,6 @@ namespace BotSharp.Plugin.MongoStorage.Collections; public class ConversationDialogDocument : MongoBase { public string ConversationId { get; set; } + public string AgentId { get; set; } public List Dialogs { get; set; } } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationStateDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationStateDocument.cs index c6068a1b9..7b5156168 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationStateDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationStateDocument.cs @@ -3,6 +3,7 @@ namespace BotSharp.Plugin.MongoStorage.Collections; public class ConversationStateDocument : MongoBase { public string ConversationId { get; set; } + public string AgentId { get; set; } public List States { get; set; } = new List(); public List Breakpoints { get; set; } = new List(); } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationStateLogDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationStateLogDocument.cs index c17c86c8d..131ef60c6 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationStateLogDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationStateLogDocument.cs @@ -3,6 +3,7 @@ namespace BotSharp.Plugin.MongoStorage.Collections; public class ConversationStateLogDocument : MongoBase { public string ConversationId { get; set; } + public string AgentId { get; set; } public string MessageId { get; set; } public Dictionary States { get; set; } public DateTime CreateTime { get; set; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs index 656ee8901..c83ccf17d 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs @@ -29,6 +29,7 @@ public void CreateNewConversation(Conversation conversation) { Id = Guid.NewGuid().ToString(), ConversationId = convDoc.Id, + AgentId = conversation.AgentId, Dialogs = new List() }; @@ -36,6 +37,7 @@ public void CreateNewConversation(Conversation conversation) { Id = Guid.NewGuid().ToString(), ConversationId = convDoc.Id, + AgentId = conversation.AgentId, States = new List(), Breakpoints = new List() }; diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Log.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Log.cs index 316312306..f053177f3 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Log.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Log.cs @@ -113,6 +113,7 @@ public void SaveConversationStateLog(ConversationStateLogModel log) var logDoc = new ConversationStateLogDocument { ConversationId = log.ConversationId, + AgentId= log.AgentId, MessageId = log.MessageId, States = log.States, CreateTime = log.CreateTime @@ -129,6 +130,7 @@ public List GetConversationStateLogs(string conversat .Select(x => new ConversationStateLogModel { ConversationId = x.ConversationId, + AgentId = x.AgentId, MessageId = x.MessageId, States = x.States, CreateTime = x.CreateTime