From 4f6fed56d86b69ecde17112f6c7ae616a57b0bdc Mon Sep 17 00:00:00 2001 From: Haiping Chen <101423@smsassist.com> Date: Wed, 4 Sep 2024 10:01:40 -0500 Subject: [PATCH] Fix router history dialogs. --- .../Conversations/Models/RoleDialogModel.cs | 3 ++- .../Services/ConversationService.SendMessage.cs | 2 +- .../Routing/RoutingService.GetConversationContent.cs | 10 +++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs index ca240061..2018d6a7 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs @@ -30,7 +30,7 @@ public class RoleDialogModel : ITrackableMessage public string? SecondaryContent { get; set; } /// - /// Postback content + /// Postback of previous round payload /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonPropertyName("payload")] @@ -131,6 +131,7 @@ public class RoleDialogModel : ITrackableMessage ToolCallId = source.ToolCallId, PostbackFunctionName = source.PostbackFunctionName, RichContent = source.RichContent, + Payload = source.Payload, StopCompletion = source.StopCompletion, Instruction = source.Instruction, Data = source.Data, diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs index 29f9e3f2..c9c5c4a2 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs @@ -41,7 +41,7 @@ public partial class ConversationService routing.Context.SetMessageId(_conversationId, message.MessageId); routing.Context.Push(agent.Id, reason: "request started"); - // Save payload + // Save payload in order to assign the payload before hook is invoked if (replyMessage != null && !string.IsNullOrEmpty(replyMessage.Payload)) { message.Payload = replyMessage.Payload; diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetConversationContent.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetConversationContent.cs index f8efab46..f95b3f37 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetConversationContent.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetConversationContent.cs @@ -16,7 +16,15 @@ public partial class RoutingService role = agent.Name; } - conversation += $"{role}: {dialog.Payload ?? dialog.Content}\r\n"; + if (role == AgentRole.User) + { + conversation += $"{role}: {dialog.Payload ?? dialog.Content}\r\n"; + } + else + { + // Assistant reply deosn't need help with payload + conversation += $"{role}: {dialog.Content}\r\n"; + } } return conversation;