diff --git a/src/Infrastructure/BotSharp.Abstraction/Loggers/Models/ConversationStateLogModel.cs b/src/Infrastructure/BotSharp.Abstraction/Loggers/Models/ConversationStateLogModel.cs index 98624759..7033d73b 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 aecce913..410589e7 100644 --- a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs +++ b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs @@ -188,7 +188,8 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR 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 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR 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 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR 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 b71ae40c..12442cdc 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 c6068a1b..7b515616 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 c17c86c8..131ef60c 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 656ee890..c83ccf17 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 partial class MongoRepository { Id = Guid.NewGuid().ToString(), ConversationId = convDoc.Id, + AgentId = conversation.AgentId, Dialogs = new List() }; @@ -36,6 +37,7 @@ public partial class MongoRepository { 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 31631230..f053177f 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 partial class MongoRepository var logDoc = new ConversationStateLogDocument { ConversationId = log.ConversationId, + AgentId= log.AgentId, MessageId = log.MessageId, States = log.States, CreateTime = log.CreateTime @@ -129,6 +130,7 @@ public partial class MongoRepository .Select(x => new ConversationStateLogModel { ConversationId = x.ConversationId, + AgentId = x.AgentId, MessageId = x.MessageId, States = x.States, CreateTime = x.CreateTime