From 30814390ddf37ae0bfe83e3e46e980f6c4933f69 Mon Sep 17 00:00:00 2001 From: hchen2020 <101423@smsassist.com> Date: Wed, 23 Aug 2023 19:35:00 -0500 Subject: [PATCH 1/3] Remove FunctionExecutionValidationResult --- .../FunctionExecutionValidationResult.cs | 24 ------------------- 1 file changed, 24 deletions(-) delete mode 100644 src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionExecutionValidationResult.cs diff --git a/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionExecutionValidationResult.cs b/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionExecutionValidationResult.cs deleted file mode 100644 index 423e6563..00000000 --- a/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionExecutionValidationResult.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Text.Json.Serialization; - -namespace BotSharp.Abstraction.Functions.Models; - -public class FunctionExecutionValidationResult -{ - public FunctionExecutionValidationResult() - { - - } - - public FunctionExecutionValidationResult(string validationStatus, string? validationMessage = null) - { - ValidationStatus = validationStatus; - ValidationMessage = validationMessage; - } - - [JsonPropertyName("validation_status")] - public string ValidationStatus { get; set; } - - [JsonPropertyName("validation_message")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public string ValidationMessage { get; set; } -} From c8b9ce128fdb9b63c323749ed495150f87e29b52 Mon Sep 17 00:00:00 2001 From: hchen2020 <101423@smsassist.com> Date: Thu, 24 Aug 2023 07:12:27 -0500 Subject: [PATCH 2/3] Catch and log function call error. --- .../Services/ConversationService.CallFunctions.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.CallFunctions.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.CallFunctions.cs index b02f3d03..66f0a25d 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.CallFunctions.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.CallFunctions.cs @@ -29,9 +29,17 @@ public partial class ConversationService await hook.OnFunctionExecuting(msg); } - // Execute function - await fn.Execute(msg); - + try + { + // Execute function + await fn.Execute(msg); + } + catch (Exception ex) + { + msg.ExecutionResult = ex.Message; + _logger.LogError(msg.ExecutionResult); + } + // After functions have been executed foreach (var hook in hooks) { From 434324358ac32e79aaba298c311af87af844a1b3 Mon Sep 17 00:00:00 2001 From: hchen2020 <101423@smsassist.com> Date: Thu, 24 Aug 2023 07:18:41 -0500 Subject: [PATCH 3/3] MaxRecursiveDepth setting. --- .../BotSharp.Abstraction/Agents/Settings/AgentSettings.cs | 1 + .../ConversationService.GetChatCompletionsAsyncRecursively.cs | 3 ++- .../Conversations/Services/ConversationService.SendMessage.cs | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Settings/AgentSettings.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Settings/AgentSettings.cs index dfc10822..84ff0274 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Settings/AgentSettings.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Settings/AgentSettings.cs @@ -8,4 +8,5 @@ public class AgentSettings public string RouterId { get; set; } public string DataDir { get; set; } public string TemplateFormat { get; set; } + public int MaxRecursiveDepth { get; set; } = 3; } diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.GetChatCompletionsAsyncRecursively.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.GetChatCompletionsAsyncRecursively.cs index d4f058f7..40856809 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.GetChatCompletionsAsyncRecursively.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.GetChatCompletionsAsyncRecursively.cs @@ -7,13 +7,13 @@ namespace BotSharp.Core.Conversations.Services; public partial class ConversationService { - const int maxRecursiveDepth = 3; int currentRecursiveDepth = 0; private async Task GetChatCompletionsAsyncRecursively(IChatCompletion chatCompletion, string conversationId, Agent agent, List wholeDialogs, + int maxRecursiveDepth, Func onMessageReceived, Func onFunctionExecuting, Func onFunctionExecuted) @@ -83,6 +83,7 @@ public partial class ConversationService conversationId, agent, wholeDialogs, + maxRecursiveDepth, onMessageReceived, onFunctionExecuting, onFunctionExecuted); diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs index 45ede9dc..8d53971a 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs @@ -65,11 +65,14 @@ public partial class ConversationService await hook.BeforeCompletion(); } + var agentSettings = _services.GetRequiredService(); + var chatCompletion = GetChatCompletion(); var result = await GetChatCompletionsAsyncRecursively(chatCompletion, conversationId, agent, wholeDialogs, + agentSettings.MaxRecursiveDepth, onMessageReceived, onFunctionExecuting, onFunctionExecuted);