From 18721a6b8fda13cb1f20ef2b8effcbd553ff181d Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Tue, 27 Feb 2024 14:59:08 -0600 Subject: [PATCH] Auto restore function name in InvokeFunction. --- .../Routing/RoutingService.InvokeFunction.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs index ba937d2d..4b8bd099 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs @@ -9,8 +9,17 @@ public partial class RoutingService var function = _services.GetServices().FirstOrDefault(x => x.Name == name); if (function == null) return false; + var originalFunctionName = message.FunctionName; message.FunctionName = name; message.Role = AgentRole.Function; - return await function.Execute(message); + var result = await function.Execute(message); + + // restore original function name + if (!message.StopCompletion) + { + message.FunctionName = originalFunctionName; + } + + return result; } }