From 805dc63ea8642a549f6370197434410c8741a402 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Tue, 29 Oct 2024 14:59:46 -0500 Subject: [PATCH] init conv side car --- .../Conversations/IConversationSideCar.cs | 11 ++ .../IConversationStateService.cs | 4 + .../Models/ConversationContext.cs | 10 ++ .../Routing/IRoutingContext.cs | 11 ++ .../Routing/IRoutingService.cs | 6 +- .../Conversations/ConversationPlugin.cs | 1 + .../ConversationService.SendMessage.cs | 3 +- .../ConversationService.UpdateBreakpoint.cs | 10 +- .../Services/ConversationService.cs | 13 +- .../Services/ConversationSideCar.cs | 154 ++++++++++++++++++ .../Services/ConversationStateService.cs | 17 ++ .../Services/ConversationStorage.cs | 14 +- .../FileRepository/FileRepository.Agent.cs | 4 +- .../Routing/Planning/SequentialPlanner.cs | 2 +- .../BotSharp.Core/Routing/RoutingContext.cs | 41 ++++- .../Routing/RoutingService.InvokeAgent.cs | 14 +- .../BotSharp.Core/Routing/RoutingService.cs | 21 ++- .../Hooks/ChatHubConversationHook.cs | 12 ++ .../TwoStaging/TwoStageTaskPlanner.cs | 2 +- 19 files changed, 318 insertions(+), 32 deletions(-) create mode 100644 src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationSideCar.cs create mode 100644 src/Infrastructure/BotSharp.Abstraction/Conversations/Models/ConversationContext.cs create mode 100644 src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationSideCar.cs diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationSideCar.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationSideCar.cs new file mode 100644 index 00000000..569555c2 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationSideCar.cs @@ -0,0 +1,11 @@ +namespace BotSharp.Abstraction.Conversations; + +public interface IConversationSideCar +{ + bool IsEnabled(); + void AppendConversationDialogs(string conversationId, List messages); + List GetConversationDialogs(string conversationId); + void UpdateConversationBreakpoint(string conversationId, ConversationBreakpoint breakpoint); + ConversationBreakpoint? GetConversationBreakpoint(string conversationId); + Task Execute(string conversationId, string agentId, string text, PostbackMessageModel? postback = null, List? states = null); +} diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationStateService.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationStateService.cs index de26ef5b..df123922 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationStateService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationStateService.cs @@ -19,4 +19,8 @@ public interface IConversationStateService bool RemoveState(string name); void CleanStates(params string[] excludedStates); void Save(); + + ConversationState GetCurrentState(); + void SetCurrentState(ConversationState state); + void ResetCurrentState(); } diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/ConversationContext.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/ConversationContext.cs new file mode 100644 index 00000000..0b0b0846 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/ConversationContext.cs @@ -0,0 +1,10 @@ +namespace BotSharp.Abstraction.Conversations.Models; + +public class ConversationContext +{ + public ConversationState State { get; set; } + public List Dialogs { get; set; } = new(); + public List Breakpoints { get; set; } = new(); + public int RecursiveCounter { get; set; } + public Stack RoutingStack { get; set; } = new(); +} diff --git a/src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingContext.cs b/src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingContext.cs index 3c93976b..854832c6 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingContext.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingContext.cs @@ -17,4 +17,15 @@ public interface IRoutingContext void PopTo(string agentId, string reason); void Replace(string agentId, string? reason = null); void Empty(string? reason = null); + + + int CurrentRecursionDepth { get; } + int GetRecursiveCounter(); + int IncreaseRecursiveCounter(); + void SetRecursiveCounter(int counter); + void ResetRecursiveCounter(); + + Stack GetAgentStack(); + void SetAgentStack(Stack stack); + void ResetAgentStack(); } diff --git a/src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingService.cs b/src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingService.cs index 3b221f4d..c0f7c81c 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingService.cs @@ -27,7 +27,11 @@ public interface IRoutingService RoutingRule[] GetRulesByAgentId(string id); List GetHandlers(Agent router); - void ResetRecursiveCounter(); + + //void ResetRecursiveCounter(); + //int GetRecursiveCounter(); + //void SetRecursiveCounter(int counter); + Task InvokeAgent(string agentId, List dialogs); Task InvokeFunction(string name, RoleDialogModel messages); Task InstructLoop(RoleDialogModel message, List dialogs); diff --git a/src/Infrastructure/BotSharp.Core/Conversations/ConversationPlugin.cs b/src/Infrastructure/BotSharp.Core/Conversations/ConversationPlugin.cs index a9be6fd2..7db04623 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/ConversationPlugin.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/ConversationPlugin.cs @@ -43,6 +43,7 @@ public class ConversationPlugin : IBotSharpPlugin services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); services.AddScoped(); // Rich content messaging diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs index 59ce88c2..375cf3e6 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs @@ -1,7 +1,6 @@ using BotSharp.Abstraction.Messaging; using BotSharp.Abstraction.Messaging.Models.RichContent; using BotSharp.Abstraction.Routing.Settings; -using BotSharp.Core.Routing.Planning; namespace BotSharp.Core.Conversations.Services; @@ -90,7 +89,7 @@ public partial class ConversationService response = await routing.InstructDirect(agent, message); } - routing.ResetRecursiveCounter(); + routing.Context.ResetRecursiveCounter(); } await HandleAssistantMessage(response, onMessageReceived); diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.UpdateBreakpoint.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.UpdateBreakpoint.cs index 8f88f44f..618095e4 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.UpdateBreakpoint.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.UpdateBreakpoint.cs @@ -10,7 +10,15 @@ public partial class ConversationService : IConversationService var routingCtx = _services.GetRequiredService(); var messageId = routingCtx.MessageId; - db.UpdateConversationBreakpoint(_conversationId, new ConversationBreakpoint + //db.UpdateConversationBreakpoint(_conversationId, new ConversationBreakpoint + //{ + // MessageId = messageId, + // Breakpoint = DateTime.UtcNow, + // Reason = reason + //}); + + var sidecar = _services.GetRequiredService(); + sidecar.UpdateConversationBreakpoint(_conversationId, new ConversationBreakpoint { MessageId = messageId, Breakpoint = DateTime.UtcNow, diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs index 070f4c59..302107ab 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs @@ -98,6 +98,7 @@ public partial class ConversationService : IConversationService var record = sess; record.Id = sess.Id.IfNullOrEmptyAs(Guid.NewGuid().ToString()); record.UserId = sess.UserId.IfNullOrEmptyAs(foundUserId); + record.Tags = sess.Tags; record.Title = "New Conversation"; db.CreateNewConversation(record); @@ -139,8 +140,12 @@ public partial class ConversationService : IConversationService if (fromBreakpoint) { - var db = _services.GetRequiredService(); - var breakpoint = db.GetConversationBreakpoint(_conversationId); + //var db = _services.GetRequiredService(); + //var breakpoint = db.GetConversationBreakpoint(_conversationId); + + var sidecar = _services.GetRequiredService(); + var breakpoint = sidecar.GetConversationBreakpoint(_conversationId); + if (breakpoint != null) { dialogs = dialogs.Where(x => x.CreatedAt >= breakpoint.Breakpoint).ToList(); @@ -151,9 +156,7 @@ public partial class ConversationService : IConversationService } } - return dialogs - .TakeLast(lastCount) - .ToList(); + return dialogs.TakeLast(lastCount).ToList(); } public void SetConversationId(string conversationId, List states, bool isReadOnly = false) diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationSideCar.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationSideCar.cs new file mode 100644 index 00000000..903b8ee0 --- /dev/null +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationSideCar.cs @@ -0,0 +1,154 @@ +using BotSharp.Abstraction.Conversations.Enums; +using BotSharp.Abstraction.Models; + +namespace BotSharp.Core.Conversations.Services; + +public class ConversationSideCar : IConversationSideCar +{ + private readonly IServiceProvider _services; + private readonly ILogger _logger; + + private Stack contextStack = new(); + + private bool enabled = false; + + public ConversationSideCar( + IServiceProvider services, + ILogger logger) + { + _services = services; + _logger = logger; + } + + public bool IsEnabled() + { + return enabled; + } + + public void AppendConversationDialogs(string conversationId, List messages) + { + if (enabled) + { + var top = contextStack.Peek(); + top.Dialogs.AddRange(messages); + } + else + { + var db = _services.GetRequiredService(); + db.AppendConversationDialogs(conversationId, messages); + } + } + + public List GetConversationDialogs(string conversationId) + { + if (enabled) + { + return contextStack.Peek().Dialogs; + } + else + { + var db = _services.GetRequiredService(); + return db.GetConversationDialogs(conversationId); + } + } + + public void UpdateConversationBreakpoint(string conversationId, ConversationBreakpoint breakpoint) + { + if (enabled) + { + var top = contextStack.Peek().Breakpoints; + top.Add(breakpoint); + } + else + { + var db = _services.GetRequiredService(); + db.UpdateConversationBreakpoint(conversationId, breakpoint); + } + } + + public ConversationBreakpoint? GetConversationBreakpoint(string conversationId) + { + if (enabled) + { + var top = contextStack.Peek().Breakpoints; + return top.LastOrDefault(); + } + else + { + var db = _services.GetRequiredService(); + return db.GetConversationBreakpoint(conversationId); + } + } + + public async Task Execute(string conversationId, string agentId, string text, + PostbackMessageModel? postback = null, List? states = null) + { + BeforeExecute(); + var response = await InnerExecute(agentId, text, postback, states); + AfterExecute(); + return response; + } + + private async Task InnerExecute(string agentId, string text, + PostbackMessageModel? postback = null, List? states = null) + { + var conv = _services.GetRequiredService(); + var routing = _services.GetRequiredService(); + var state = _services.GetRequiredService(); + + var inputMsg = new RoleDialogModel(AgentRole.User, text); + routing.Context.SetMessageId(conv.ConversationId, inputMsg.MessageId); + states?.ForEach(x => state.SetState(x.Key, x.Value, activeRounds: x.ActiveRounds, source: StateSource.External)); + + var response = new RoleDialogModel(AgentRole.Assistant, string.Empty); + await conv.SendMessage(agentId, inputMsg, + replyMessage: postback, + async msg => + { + response.Content = !string.IsNullOrEmpty(msg.SecondaryContent) ? msg.SecondaryContent : msg.Content; + response.FunctionName = msg.FunctionName; + response.RichContent = msg.SecondaryRichContent ?? msg.RichContent; + response.Instruction = msg.Instruction; + response.Data = msg.Data; + }); + + return response; + } + + private void BeforeExecute() + { + enabled = true; + var state = _services.GetRequiredService(); + var routing = _services.GetRequiredService(); + + var node = new ConversationContext + { + State = state.GetCurrentState(), + Dialogs = new(), + Breakpoints = new(), + RecursiveCounter = routing.Context.GetRecursiveCounter(), + RoutingStack = routing.Context.GetAgentStack() + }; + contextStack.Push(node); + + // Reset + state.ResetCurrentState(); + routing.Context.ResetRecursiveCounter(); + routing.Context.ResetAgentStack(); + + } + + private void AfterExecute() + { + var state = _services.GetRequiredService(); + var routing = _services.GetRequiredService(); + + var node = contextStack.Pop(); + + // Recover + state.SetCurrentState(node.State); + routing.Context.SetRecursiveCounter(node.RecursiveCounter); + routing.Context.SetAgentStack(node.RoutingStack); + enabled = false; + } +} \ No newline at end of file diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs index 7a3d1d5d..f6c146a8 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs @@ -384,4 +384,21 @@ public class ConversationStateService : IConversationStateService, IDisposable } return true; } + + public ConversationState GetCurrentState() + { + var values = _curStates.Values.ToList(); + var copy = JsonSerializer.Deserialize>(JsonSerializer.Serialize(values)); + return new ConversationState(copy ?? new()); + } + + public void SetCurrentState(ConversationState state) + { + _curStates = state; + } + + public void ResetCurrentState() + { + _curStates.Clear(); + } } diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs index ea145ac0..1ce112ca 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs @@ -91,13 +91,21 @@ public class ConversationStorage : IConversationStorage }); } - db.AppendConversationDialogs(conversationId, dialogElements); + //db.AppendConversationDialogs(conversationId, dialogElements); + + var sidecar = _services.GetRequiredService(); + sidecar.AppendConversationDialogs(conversationId, dialogElements); + } public List GetDialogs(string conversationId) { - var db = _services.GetRequiredService(); - var dialogs = db.GetConversationDialogs(conversationId); + //var db = _services.GetRequiredService(); + //var dialogs = db.GetConversationDialogs(conversationId); + + var sidecar = _services.GetRequiredService(); + var dialogs = sidecar.GetConversationDialogs(conversationId); + var hooks = _services.GetServices(); var results = new List(); diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs index bb137279..7f9a7b81 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs @@ -188,7 +188,7 @@ namespace BotSharp.Core.Repository // Save default instructions var instructionFile = Path.Combine(instructionDir, $"{AGENT_INSTRUCTION_FILE}.{_agentSettings.TemplateFormat}"); File.WriteAllText(instructionFile, instruction ?? string.Empty); - Thread.Sleep(100); + Thread.Sleep(50); // Save channel instructions foreach (var ci in channelInstructions) @@ -197,7 +197,7 @@ namespace BotSharp.Core.Repository var file = Path.Combine(instructionDir, $"{AGENT_INSTRUCTION_FILE}.{ci.Channel}.{_agentSettings.TemplateFormat}"); File.WriteAllText(file, ci.Instruction ?? string.Empty); - Thread.Sleep(100); + Thread.Sleep(50); } } diff --git a/src/Infrastructure/BotSharp.Core/Routing/Planning/SequentialPlanner.cs b/src/Infrastructure/BotSharp.Core/Routing/Planning/SequentialPlanner.cs index 93fa2f3b..f6b05375 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Planning/SequentialPlanner.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Planning/SequentialPlanner.cs @@ -147,7 +147,7 @@ public class SequentialPlanner : IRoutingPlaner context.Pop(); var routing = _services.GetRequiredService(); - routing.ResetRecursiveCounter(); + routing.Context.ResetRecursiveCounter(); return true; } diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs index a77397d0..3450d41e 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs @@ -1,5 +1,4 @@ using BotSharp.Abstraction.Routing.Settings; -using BotSharp.Abstraction.Utilities; namespace BotSharp.Core.Routing; @@ -10,6 +9,7 @@ public class RoutingContext : IRoutingContext private string[] _routerAgentIds; private string _conversationId; private string _messageId; + private int _currentRecursionDepth = 0; public RoutingContext(IServiceProvider services, RoutingSettings setting) { @@ -20,9 +20,9 @@ public class RoutingContext : IRoutingContext public int AgentCount => _stack.Count; public string ConversationId => _conversationId; public string MessageId => _messageId; + public int CurrentRecursionDepth => _currentRecursionDepth; - private Stack _stack { get; set; } - = new Stack(); + private Stack _stack { get; set; } = new(); /// /// Intent name @@ -208,4 +208,39 @@ public class RoutingContext : IRoutingContext _conversationId = conversationId; _messageId = messageId; } + + public int GetRecursiveCounter() + { + return _currentRecursionDepth; + } + + public int IncreaseRecursiveCounter() + { + return _currentRecursionDepth; + } + + public void SetRecursiveCounter(int counter) + { + _currentRecursionDepth = counter; + } + + public void ResetRecursiveCounter() + { + _currentRecursionDepth = 0; + } + + public Stack GetAgentStack() + { + return new Stack(_stack); + } + + public void SetAgentStack(Stack stack) + { + _stack = new Stack(stack); + } + + public void ResetAgentStack() + { + _stack.Clear(); + } } diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs index ccd708c3..25ab3552 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs @@ -4,14 +4,15 @@ namespace BotSharp.Core.Routing; public partial class RoutingService { - private int _currentRecursionDepth = 0; + //private int _currentRecursionDepth = 0; public async Task InvokeAgent(string agentId, List dialogs) { var agentService = _services.GetRequiredService(); var agent = await agentService.LoadAgent(agentId); - _currentRecursionDepth++; - if (_currentRecursionDepth > agent.LlmConfig.MaxRecursionDepth) + //_currentRecursionDepth++; + Context.IncreaseRecursiveCounter(); + if (Context.CurrentRecursionDepth > agent.LlmConfig.MaxRecursionDepth) { _logger.LogWarning($"Current recursive call depth greater than {agent.LlmConfig.MaxRecursionDepth}, which will cause unexpected result."); return false; @@ -36,8 +37,7 @@ public partial class RoutingService if (response.Role == AgentRole.Function) { - message = RoleDialogModel.From(message, - role: AgentRole.Function); + message = RoleDialogModel.From(message, role: AgentRole.Function); if (response.FunctionName != null && response.FunctionName.Contains("/")) { response.FunctionName = response.FunctionName.Split("/").Last(); @@ -57,9 +57,7 @@ public partial class RoutingService response.Content = "Apologies, I'm not quite sure I understand. Could you please provide additional clarification or context?"; } - message = RoleDialogModel.From(message, - role: AgentRole.Assistant, - content: response.Content); + message = RoleDialogModel.From(message, role: AgentRole.Assistant, content: response.Content); message.CurrentAgentId = agent.Id; dialogs.Add(message); } diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs index b7c489e1..770acaf9 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs @@ -16,12 +16,23 @@ public partial class RoutingService : IRoutingService public IRoutingContext Context => _context; public Agent Router => _router; - public void ResetRecursiveCounter() - { - _currentRecursionDepth = 0; - } + //public int GetRecursiveCounter() + //{ + // return _currentRecursionDepth; + //} - public RoutingService(IServiceProvider services, + //public void SetRecursiveCounter(int counter) + //{ + // _currentRecursionDepth = counter; + //} + + //public void ResetRecursiveCounter() + //{ + // _currentRecursionDepth = 0; + //} + + public RoutingService( + IServiceProvider services, RoutingSettings settings, IRoutingContext context, ILogger logger) diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs index 29c6df82..2d693603 100644 --- a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs +++ b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs @@ -32,6 +32,8 @@ public class ChatHubConversationHook : ConversationHookBase public override async Task OnConversationInitialized(Conversation conversation) { + if (!AllowSendingMessage()) return; + var userService = _services.GetRequiredService(); var conv = ConversationViewModel.FromSession(conversation); @@ -44,6 +46,8 @@ public class ChatHubConversationHook : ConversationHookBase public override async Task OnMessageReceived(RoleDialogModel message) { + if (!AllowSendingMessage()) return; + var conv = _services.GetRequiredService(); var userService = _services.GetRequiredService(); var sender = await userService.GetMyProfile(); @@ -90,6 +94,8 @@ public class ChatHubConversationHook : ConversationHookBase public override async Task OnResponseGenerated(RoleDialogModel message) { + if (!AllowSendingMessage()) return; + var conv = _services.GetRequiredService(); var json = JsonSerializer.Serialize(new ChatResponseModel() { @@ -156,6 +162,12 @@ public class ChatHubConversationHook : ConversationHookBase } #region Private methods + private bool AllowSendingMessage() + { + var sidecar = _services.GetRequiredService(); + return !sidecar.IsEnabled(); + } + private async Task InitClientConversation(ConversationViewModel conversation) { await _chatHub.Clients.User(_user.Id).SendAsync(INIT_CLIENT_CONVERSATION, conversation); diff --git a/src/Plugins/BotSharp.Plugin.Planner/TwoStaging/TwoStageTaskPlanner.cs b/src/Plugins/BotSharp.Plugin.Planner/TwoStaging/TwoStageTaskPlanner.cs index 2ecd9ac0..565115a5 100644 --- a/src/Plugins/BotSharp.Plugin.Planner/TwoStaging/TwoStageTaskPlanner.cs +++ b/src/Plugins/BotSharp.Plugin.Planner/TwoStaging/TwoStageTaskPlanner.cs @@ -92,7 +92,7 @@ public partial class TwoStageTaskPlanner : IRoutingPlaner } var routing = _services.GetRequiredService(); - routing.ResetRecursiveCounter(); + routing.Context.ResetRecursiveCounter(); return true; }