From 0f6a183ed4d267f704b647f268325e2402070f20 Mon Sep 17 00:00:00 2001 From: Haiping Chen <101423@smsassist.com> Date: Wed, 28 Feb 2024 20:41:21 -0600 Subject: [PATCH 1/2] Fix Pop agent bug. --- .../BotSharp.Core/Routing/Functions/RouteToAgentFn.cs | 3 --- src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs | 3 ++- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Routing/Functions/RouteToAgentFn.cs b/src/Infrastructure/BotSharp.Core/Routing/Functions/RouteToAgentFn.cs index bba32ff85..55bcdf820 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Functions/RouteToAgentFn.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Functions/RouteToAgentFn.cs @@ -1,7 +1,4 @@ using BotSharp.Abstraction.Functions; -using BotSharp.Abstraction.Repositories; -using BotSharp.Abstraction.Repositories.Filters; -using BotSharp.Abstraction.Routing; using BotSharp.Abstraction.Routing.Models; using System.Drawing; diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs index d12adfa21..2666daffe 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs @@ -80,9 +80,10 @@ public void Pop(string? reason = null) } var agentId = _stack.Pop(); + var currentAgentId = GetCurrentAgentId(); HookEmitter.Emit(_services, async hook => - await hook.OnAgentDequeued(agentId, _stack.Peek(), reason: reason) + await hook.OnAgentDequeued(agentId, currentAgentId, reason: reason) ).Wait(); } From beb82c855a1581f42ffd99619ba745d294fac8b8 Mon Sep 17 00:00:00 2001 From: Haiping Chen <101423@smsassist.com> Date: Wed, 28 Feb 2024 20:45:01 -0600 Subject: [PATCH 2/2] fix GetCurrentAgentId --- src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs | 5 +++++ .../BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs index 2666daffe..db8900b4f 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs @@ -53,6 +53,11 @@ public string OriginAgentId public string GetCurrentAgentId() { + if (_stack.Count == 0) + { + return string.Empty; + } + return _stack.Peek(); } diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs index cfc4b446c..812f87e66 100644 --- a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs +++ b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs @@ -182,7 +182,7 @@ public async Task OnAgentDequeued(string agentId, string currentAgentId, string? var agent = await _agentService.LoadAgent(agentId); var currentAgent = await _agentService.LoadAgent(currentAgentId); - var log = $"{agent.Name} is dequeued{(reason != null ? $" ({reason})" : "")}, current agent is {currentAgent.Name}"; + var log = $"{agent.Name} is dequeued{(reason != null ? $" ({reason})" : "")}, current agent is {currentAgent?.Name}"; await _chatHub.Clients.User(_user.Id).SendAsync("OnConversationContentLogGenerated", BuildContentLog(conversationId, "Router", log, ContentLogSource.HardRule, new RoleDialogModel(AgentRole.System, log) {