From 611f0feeedb04c9414d1dcd32fcbcf2c045642a4 Mon Sep 17 00:00:00 2001 From: "nick.yi" Date: Tue, 21 Apr 2026 08:54:21 +0800 Subject: [PATCH 1/2] optimize AI Context --- .../Conversations/Enums/MessageTypeName.cs | 4 ++++ .../Routing/RoutingService.GetConversationContent.cs | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/Enums/MessageTypeName.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/Enums/MessageTypeName.cs index e59622bb6..e87fa669b 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/Enums/MessageTypeName.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/Enums/MessageTypeName.cs @@ -3,6 +3,10 @@ namespace BotSharp.Abstraction.Conversations.Enums; public static class MessageTypeName { public const string Plain = "plain"; + /// + /// Persisted for record/audit but excluded from default LLM dialog history. + /// + public const string RecordOnly = "record_only"; public const string Notification = "notification"; public const string FunctionCall = "function"; public const string Audio = "audio"; diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetConversationContent.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetConversationContent.cs index 60e81bbe9..006d3e7b0 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetConversationContent.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetConversationContent.cs @@ -1,3 +1,5 @@ +using BotSharp.Abstraction.Conversations.Enums; + namespace BotSharp.Core.Routing; public partial class RoutingService @@ -6,8 +8,8 @@ public async Task GetConversationContent(List dialogs, { var agentService = _services.GetRequiredService(); var conversation = ""; - - foreach (var dialog in dialogs.TakeLast(maxDialogCount)) + var contentDialogs = dialogs.Where(x => x.MessageType != MessageTypeName.RecordOnly).TakeLast(maxDialogCount).ToList(); + foreach (var dialog in contentDialogs) { var role = dialog.Role; if (role != AgentRole.User) From 76505f397337c4dba056ea471f62b8948883ba40 Mon Sep 17 00:00:00 2001 From: "nick.yi" Date: Tue, 21 Apr 2026 08:56:47 +0800 Subject: [PATCH 2/2] optimize AI Context --- .../Routing/RoutingService.GetConversationContent.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetConversationContent.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetConversationContent.cs index 006d3e7b0..b468d3afa 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetConversationContent.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetConversationContent.cs @@ -8,8 +8,8 @@ public async Task GetConversationContent(List dialogs, { var agentService = _services.GetRequiredService(); var conversation = ""; - var contentDialogs = dialogs.Where(x => x.MessageType != MessageTypeName.RecordOnly).TakeLast(maxDialogCount).ToList(); - foreach (var dialog in contentDialogs) + var conversationDialogs = dialogs.Where(x => x.MessageType != MessageTypeName.RecordOnly).TakeLast(maxDialogCount).ToList(); + foreach (var dialog in conversationDialogs) { var role = dialog.Role; if (role != AgentRole.User)