From 8abc002f14defa451927d9c627ecdb9ae76c4dfc Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Thu, 21 Sep 2023 14:21:59 -0500 Subject: [PATCH] route_to_agent fallback --- Directory.Build.props | 2 +- .../BotSharp.Core/Routing/RoutingService.cs | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 23dce0b1..81c66e4a 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,7 +2,7 @@ 10.0 ..\..\..\packages - 0.14.5 + 0.14.6 true \ No newline at end of file diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs index 665f6ce7..4eae4709 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs @@ -59,8 +59,23 @@ public class RoutingService : IRoutingService // Compatible with previous Router, can be removed in the future. else if (inst.Function == "route_to_agent") { + // If the agent name is empty, fallback to router + if (string.IsNullOrEmpty(inst.Parameters.AgentName)) + { + result = new RoleDialogModel(AgentRole.Function, inst.Reason) + { + FunctionName = inst.Function, + FunctionArgs = JsonSerializer.Serialize(new RoutingArgs + { + AgentName = inst.Parameters.AgentName + }), + CurrentAgentId = router.Id + }; + break; + } + var function = _services.GetServices().FirstOrDefault(x => x.Name == inst.Function); - result = new RoleDialogModel(AgentRole.Function, inst.Parameters.Question) + result = new RoleDialogModel(AgentRole.Function, inst.Reason) { FunctionName = inst.Function, FunctionArgs = JsonSerializer.Serialize(new RoutingArgs