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.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; } -} 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) { 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);