diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/Dtos/ChatResponseDto.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/Dtos/ChatResponseDto.cs index 030bae239..e68738070 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/Dtos/ChatResponseDto.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/Dtos/ChatResponseDto.cs @@ -36,6 +36,10 @@ public class ChatResponseDto : InstructResult [JsonPropertyName("indication")] public string? Indication { get; set; } + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("message_label")] + public string? MessageLabel { get; set; } + [JsonPropertyName("has_message_files")] public bool HasMessageFiles { get; set; } diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs index 5ffdf1877..675c0885a 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs @@ -98,6 +98,10 @@ public class DialogMetaData [JsonPropertyName("message_type")] public string MessageType { get; set; } = default!; + [JsonPropertyName("message_label")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? MessageLabel { get; set; } + [JsonPropertyName("function_name")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? FunctionName { get; set; } diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs index 5794e3326..ed9d68a5e 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs @@ -19,6 +19,11 @@ public class RoleDialogModel : ITrackableMessage /// public string MessageType { get; set; } = MessageTypeName.Plain; + /// + /// The message label + /// + public string? MessageLabel { get; set; } + /// /// user, system, assistant, function /// @@ -167,6 +172,7 @@ public static RoleDialogModel From(RoleDialogModel source, CurrentAgentId = source.CurrentAgentId, MessageId = source.MessageId, MessageType = source.MessageType, + MessageLabel = source.MessageLabel, FunctionArgs = source.FunctionArgs, FunctionName = source.FunctionName, ToolCallId = source.ToolCallId, diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs index 5c4bff476..26020da38 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs @@ -1,4 +1,3 @@ -using BotSharp.Abstraction.Conversations.Models; using BotSharp.Abstraction.Messaging; using BotSharp.Abstraction.Messaging.Models.RichContent; using BotSharp.Abstraction.Options; @@ -67,11 +66,7 @@ public List GetDialogs(string conversationId) var secondaryContent = dialog.SecondaryContent; var payload = string.IsNullOrEmpty(dialog.Payload) ? null : dialog.Payload; var role = meta.Role; - var currentAgentId = meta.AgentId; - var messageId = meta.MessageId; - var messageType = meta.MessageType; - var senderId = role == AgentRole.Function ? currentAgentId : meta.SenderId; - var createdAt = meta.CreatedTime; + var senderId = role == AgentRole.Function ? meta?.AgentId : meta?.SenderId; var richContent = !string.IsNullOrEmpty(dialog.RichContent) ? JsonSerializer.Deserialize>(dialog.RichContent, _options.JsonSerializerOptions) : null; var secondaryRichContent = !string.IsNullOrEmpty(dialog.SecondaryRichContent) ? @@ -79,14 +74,15 @@ public List GetDialogs(string conversationId) var record = new RoleDialogModel(role, content) { - CurrentAgentId = currentAgentId, - MessageId = messageId, - MessageType = messageType, - CreatedAt = createdAt, + CurrentAgentId = meta?.AgentId ?? string.Empty, + MessageId = meta?.MessageId ?? string.Empty, + MessageType = meta?.MessageType ?? string.Empty, + MessageLabel = meta?.MessageLabel, + CreatedAt = meta?.CreatedTime ?? default, SenderId = senderId, - FunctionName = meta.FunctionName, - FunctionArgs = meta.FunctionArgs, - ToolCallId = meta.ToolCallId, + FunctionName = meta?.FunctionName, + FunctionArgs = meta?.FunctionArgs, + ToolCallId = meta?.ToolCallId, RichContent = richContent, SecondaryContent = secondaryContent, SecondaryRichContent = secondaryRichContent, @@ -120,6 +116,7 @@ public List GetDialogs(string conversationId) AgentId = dialog.CurrentAgentId, MessageId = dialog.MessageId, MessageType = dialog.MessageType, + MessageLabel = dialog.MessageLabel, FunctionName = dialog.FunctionName, FunctionArgs = dialog.FunctionArgs, ToolCallId = dialog.ToolCallId, @@ -146,6 +143,7 @@ public List GetDialogs(string conversationId) AgentId = dialog.CurrentAgentId, MessageId = dialog.MessageId, MessageType = dialog.MessageType, + MessageLabel = dialog.MessageLabel, SenderId = dialog.SenderId, FunctionName = dialog.FunctionName, CreatedTime = dialog.CreatedAt diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs index b1246b58b..5b378a24f 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs @@ -59,6 +59,7 @@ public async Task InvokeAgent( message.Indication = response.Indication; message.CurrentAgentId = agent.Id; message.IsStreaming = response.IsStreaming; + message.MessageLabel = response.MessageLabel; message.AdditionalMessageWrapper = null; await InvokeFunction(message, dialogs, options); @@ -75,6 +76,7 @@ public async Task InvokeAgent( message = RoleDialogModel.From(message, role: AgentRole.Assistant, content: response.Content); message.CurrentAgentId = agent.Id; message.IsStreaming = response.IsStreaming; + message.MessageLabel = response.MessageLabel; message.AdditionalMessageWrapper = null; dialogs.Add(message); Context.SetDialogs(dialogs); diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs index 45b65c7eb..f23f150cb 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs @@ -65,6 +65,7 @@ public async Task InvokeFunction(string name, RoleDialogModel message, Inv message.StopCompletion = clonedMessage.StopCompletion; message.RichContent = clonedMessage.RichContent; message.Data = clonedMessage.Data; + message.MessageLabel = clonedMessage.MessageLabel; message.AdditionalMessageWrapper = clonedMessage.AdditionalMessageWrapper; } catch (JsonException ex) diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs index 2f127b100..13fb51990 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs @@ -109,6 +109,7 @@ public async Task> GetDialogs([FromRoute] string { ConversationId = conversationId, MessageId = message.MessageId, + MessageLabel = message.MessageLabel, CreatedAt = message.CreatedAt, Text = !string.IsNullOrEmpty(message.SecondaryContent) ? message.SecondaryContent : message.Content, Data = message.Data, @@ -124,6 +125,7 @@ public async Task> GetDialogs([FromRoute] string { ConversationId = conversationId, MessageId = message.MessageId, + MessageLabel = message.MessageLabel, CreatedAt = message.CreatedAt, Text = !string.IsNullOrEmpty(message.SecondaryContent) ? message.SecondaryContent : message.Content, Function = message.FunctionName, diff --git a/src/Plugins/BotSharp.Plugin.ChartHandler/Functions/PlotChartFn.cs b/src/Plugins/BotSharp.Plugin.ChartHandler/Functions/PlotChartFn.cs index 7db394e07..870566e07 100644 --- a/src/Plugins/BotSharp.Plugin.ChartHandler/Functions/PlotChartFn.cs +++ b/src/Plugins/BotSharp.Plugin.ChartHandler/Functions/PlotChartFn.cs @@ -79,8 +79,9 @@ public async Task Execute(RoleDialogModel message) new(AgentRole.Assistant, obj.ReportSummary) { MessageId = message.MessageId, - CurrentAgentId = message.CurrentAgentId, + MessageLabel = "chart_report_summary", Indication = "Summarizing", + CurrentAgentId = message.CurrentAgentId, FunctionName = message.FunctionName, FunctionArgs = message.FunctionArgs, CreatedAt = DateTime.UtcNow diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs index 6ffa49648..e00340014 100644 --- a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs +++ b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs @@ -107,6 +107,7 @@ public override async Task OnResponseGenerated(RoleDialogModel message) { ConversationId = conv.ConversationId, MessageId = message.MessageId, + MessageLabel = message.MessageLabel, Text = !string.IsNullOrEmpty(message.SecondaryContent) ? message.SecondaryContent : message.Content, Function = message.FunctionName, RichContent = message.SecondaryRichContent ?? message.RichContent, @@ -139,6 +140,7 @@ public override async Task OnResponseGenerated(RoleDialogModel message) { ConversationId = conv.ConversationId, MessageId = item.MessageId, + MessageLabel = item.MessageLabel, Indication = item.Indication, Sender = sender }; diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/DialogMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/DialogMongoElement.cs index b67fc53cb..7dd7ece77 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/DialogMongoElement.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/DialogMongoElement.cs @@ -46,6 +46,7 @@ public class DialogMetaDataMongoElement public string AgentId { get; set; } = default!; public string MessageId { get; set; } = default!; public string MessageType { get; set; } = default!; + public string? MessageLabel { get; set; } public string? FunctionName { get; set; } public string? FunctionArgs { get; set; } public string? ToolCallId { get; set; } @@ -60,6 +61,7 @@ public static DialogMetaData ToDomainElement(DialogMetaDataMongoElement meta) AgentId = meta.AgentId, MessageId = meta.MessageId, MessageType = meta.MessageType, + MessageLabel = meta.MessageLabel, FunctionName = meta.FunctionName, FunctionArgs = meta.FunctionArgs, ToolCallId = meta.ToolCallId, @@ -76,6 +78,7 @@ public static DialogMetaDataMongoElement ToMongoElement(DialogMetaData meta) AgentId = meta.AgentId, MessageId = meta.MessageId, MessageType = meta.MessageType, + MessageLabel = meta.MessageLabel, FunctionName = meta.FunctionName, FunctionArgs = meta.FunctionArgs, ToolCallId = meta.ToolCallId,