From 245384e8d253fd014ed44d273be9aef7c6830cf0 Mon Sep 17 00:00:00 2001 From: "LAPTOP-3CFGGVOS\\rabbit" Date: Mon, 27 May 2024 20:44:01 +0800 Subject: [PATCH 1/4] optimize UpdateBreakPoint --- .../Services/ConversationService.UpdateBreakpoint.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.UpdateBreakpoint.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.UpdateBreakpoint.cs index 7453a202..1bee7b89 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.UpdateBreakpoint.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.UpdateBreakpoint.cs @@ -4,7 +4,7 @@ namespace BotSharp.Core.Conversations.Services; public partial class ConversationService : IConversationService { - public async Task UpdateBreakpoint(bool resetStates = false, string? reason = null) + public async Task UpdateBreakpoint(bool resetStates = false, string? reason = null, params string[] excludedStates) { var db = _services.GetRequiredService(); var routingCtx = _services.GetRequiredService(); @@ -22,7 +22,8 @@ public partial class ConversationService : IConversationService { var states = _services.GetRequiredService(); // keep language state - states.CleanStates(StateConst.LANGUAGE); + if(excludedStates.IsNullOrEmpty()) excludedStates = new string[] { StateConst.LANGUAGE }; + states.CleanStates(excludedStates); } var hooks = _services.GetServices() From ad7b3a41eb43212da1b5dd8abb91f637ee16ea86 Mon Sep 17 00:00:00 2001 From: "LAPTOP-3CFGGVOS\\rabbit" Date: Mon, 27 May 2024 21:17:50 +0800 Subject: [PATCH 2/4] optimize UpdateBreakpoint --- .../Conversations/IConversationService.cs | 3 ++- .../Services/ConversationService.UpdateBreakpoint.cs | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs index 9df6ae7f..055db3cc 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs @@ -51,6 +51,7 @@ public interface IConversationService /// /// Whether to reset all states /// Append user init words + /// /// - Task UpdateBreakpoint(bool resetStates = false, string? reason = null); + Task UpdateBreakpoint(bool resetStates = false, string? reason = null, params string[] excludedStates); } diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.UpdateBreakpoint.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.UpdateBreakpoint.cs index 1bee7b89..8f88f44f 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.UpdateBreakpoint.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.UpdateBreakpoint.cs @@ -22,7 +22,12 @@ public partial class ConversationService : IConversationService { var states = _services.GetRequiredService(); // keep language state - if(excludedStates.IsNullOrEmpty()) excludedStates = new string[] { StateConst.LANGUAGE }; + if (excludedStates == null) excludedStates = new string[] { }; + if (!excludedStates.Contains(StateConst.LANGUAGE)) + { + excludedStates = excludedStates.Append(StateConst.LANGUAGE).ToArray(); + } + states.CleanStates(excludedStates); } From c3c28e282b745dc5a88180389e06135d20affccc Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Mon, 27 May 2024 19:26:58 -0500 Subject: [PATCH 3/4] Return Instruction for SSE. --- .../BotSharp.OpenAPI/Controllers/ConversationController.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs index 6ed27b32..71d824b3 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs @@ -298,6 +298,7 @@ public class ConversationController : ControllerBase MessageId = msg.MessageId, Text = msg.Indication, Function = "indicating", + Instruction = msg.Instruction, States = new Dictionary() }; await OnChunkReceived(Response, indicator); From d6ac3c09ea47ccae8298cfc2dded62d135e56e47 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Mon, 27 May 2024 21:06:05 -0500 Subject: [PATCH 4/4] Fix current agent id for routing rule. --- src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs index 6b126a37..31caa932 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs @@ -118,6 +118,7 @@ public class RoutingContext : IRoutingContext var message = new RoleDialogModel(AgentRole.User, $"Try to route to agent {agent.Name}") { + CurrentAgentId = currentAgentId, FunctionName = "route_to_agent", FunctionArgs = JsonSerializer.Serialize(new FunctionCallFromLlm {