Skip to content

Commit 91a017c

Browse files
authored
Merge pull request #325 from hchen2020/master
Fix Pop agent bug.
2 parents 82da7e7 + beb82c8 commit 91a017c

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/Infrastructure/BotSharp.Core/Routing/Functions/RouteToAgentFn.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
using BotSharp.Abstraction.Functions;
2-
using BotSharp.Abstraction.Repositories;
3-
using BotSharp.Abstraction.Repositories.Filters;
4-
using BotSharp.Abstraction.Routing;
52
using BotSharp.Abstraction.Routing.Models;
63
using System.Drawing;
74

src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ public string OriginAgentId
5353

5454
public string GetCurrentAgentId()
5555
{
56+
if (_stack.Count == 0)
57+
{
58+
return string.Empty;
59+
}
60+
5661
return _stack.Peek();
5762
}
5863

@@ -80,9 +85,10 @@ public void Pop(string? reason = null)
8085
}
8186

8287
var agentId = _stack.Pop();
88+
var currentAgentId = GetCurrentAgentId();
8389

8490
HookEmitter.Emit<IRoutingHook>(_services, async hook =>
85-
await hook.OnAgentDequeued(agentId, _stack.Peek(), reason: reason)
91+
await hook.OnAgentDequeued(agentId, currentAgentId, reason: reason)
8692
).Wait();
8793
}
8894

src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public async Task OnAgentDequeued(string agentId, string currentAgentId, string?
182182
var agent = await _agentService.LoadAgent(agentId);
183183
var currentAgent = await _agentService.LoadAgent(currentAgentId);
184184

185-
var log = $"{agent.Name} is dequeued{(reason != null ? $" ({reason})" : "")}, current agent is {currentAgent.Name}";
185+
var log = $"{agent.Name} is dequeued{(reason != null ? $" ({reason})" : "")}, current agent is {currentAgent?.Name}";
186186
await _chatHub.Clients.User(_user.Id).SendAsync("OnConversationContentLogGenerated",
187187
BuildContentLog(conversationId, "Router", log, ContentLogSource.HardRule, new RoleDialogModel(AgentRole.System, log)
188188
{

0 commit comments

Comments
 (0)