diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/Enums/ConversationChannel.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/Enums/ConversationChannel.cs new file mode 100644 index 00000000..ecf84e3f --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/Enums/ConversationChannel.cs @@ -0,0 +1,9 @@ +namespace BotSharp.Abstraction.Conversations.Enums; + +public class ConversationChannel +{ + public const string WebChat = "webchat"; + public const string OpenAPI = "openapi"; + public const string Phone = "phone"; + public const string Messenger = "messenger"; +} diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs index 52b104d4..e17d4217 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs @@ -17,6 +17,8 @@ public class Conversation public string Status { get; set; } = ConversationStatus.Open; + public string Channel { get; set; } = ConversationChannel.OpenAPI; + public DateTime UpdatedTime { get; set; } = DateTime.UtcNow; public DateTime CreatedTime { get; set; } = DateTime.UtcNow; } diff --git a/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionCallFromLlm.cs b/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionCallFromLlm.cs index c73de5bb..4f8435b4 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionCallFromLlm.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionCallFromLlm.cs @@ -13,7 +13,7 @@ public class FunctionCallFromLlm : RoutingArgs public JsonDocument? Arguments { get; set; } [JsonIgnore(Condition = JsonIgnoreCondition.Always)] - public bool IsExecutionOnce { get; set; } + public bool ExecutingDirectly { get; set; } public override string ToString() { diff --git a/src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingService.cs b/src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingService.cs index da074555..3ba73ee5 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingService.cs @@ -19,5 +19,5 @@ public interface IRoutingService /// /// /// - Task ExecuteOnce(Agent agent, RoleDialogModel message); + Task ExecuteDirectly(Agent agent, RoleDialogModel message); } diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs index 704e317b..b6d2c278 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs @@ -57,7 +57,7 @@ public partial class ConversationService var response = agentId == settings.RouterId ? await routing.InstructLoop(message) : - await routing.ExecuteOnce(agent, message); + await routing.ExecuteDirectly(agent, message); await HandleAssistantMessage(response, onMessageReceived); diff --git a/src/Infrastructure/BotSharp.Core/Planning/HFPlanner.cs b/src/Infrastructure/BotSharp.Core/Planning/HFPlanner.cs index 9bb6f9fd..f8b1e7a8 100644 --- a/src/Infrastructure/BotSharp.Core/Planning/HFPlanner.cs +++ b/src/Infrastructure/BotSharp.Core/Planning/HFPlanner.cs @@ -3,6 +3,7 @@ using BotSharp.Abstraction.Functions.Models; using BotSharp.Abstraction.Planning; using BotSharp.Abstraction.Repositories; using BotSharp.Abstraction.Routing.Models; +using BotSharp.Abstraction.Routing.Settings; using BotSharp.Abstraction.Templating; namespace BotSharp.Core.Planning; @@ -28,7 +29,10 @@ public class HFPlanner : IPlaner RoleDialogModel response = default; var inst = new FunctionCallFromLlm(); - var completion = CompletionProvider.GetChatCompletion(_services); + var routerSetting = _services.GetRequiredService(); + var completion = CompletionProvider.GetChatCompletion(_services, + provider: routerSetting.Provider, + model: routerSetting.Model); int retryCount = 0; while (retryCount < 3) diff --git a/src/Infrastructure/BotSharp.Core/Routing/Handlers/RouteToAgentRoutingHandler.cs b/src/Infrastructure/BotSharp.Core/Routing/Handlers/RouteToAgentRoutingHandler.cs index 7743ef03..b9acfad4 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Handlers/RouteToAgentRoutingHandler.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Handlers/RouteToAgentRoutingHandler.cs @@ -42,7 +42,7 @@ public class RouteToAgentRoutingHandler : RoutingHandlerBase, IRoutingHandler var agent = await agentService.LoadAgent(agentId); inst.AgentName = agent.Name; - if (inst.IsExecutionOnce) + if (inst.ExecutingDirectly) { message.Content = inst.Question; } diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs index 50b3587b..5bc52ebb 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs @@ -21,8 +21,7 @@ public partial class RoutingService var agentService = _services.GetRequiredService(); var agent = await agentService.LoadAgent(agentId); - var settings = _services.GetRequiredService(); - var chatCompletion = CompletionProvider.GetChatCompletion(_services, provider: settings.Provider, model: settings.Model); + var chatCompletion = CompletionProvider.GetChatCompletion(_services); var message = dialogs.Last(); var response = chatCompletion.GetChatCompletions(agent, dialogs); diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs index 41845eda..72ab4aa9 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs @@ -31,7 +31,7 @@ public partial class RoutingService : IRoutingService _logger = logger; } - public async Task ExecuteOnce(Agent agent, RoleDialogModel message) + public async Task ExecuteDirectly(Agent agent, RoleDialogModel message) { var handlers = _services.GetServices(); @@ -48,7 +48,7 @@ public partial class RoutingService : IRoutingService Reason = message.Content, AgentName = agent.Name, OriginalAgent = agent.Name, - IsExecutionOnce = true + ExecutingDirectly = true }; var result = await handler.Handle(this, inst, message); diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/ConversationViewModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/ConversationViewModel.cs index a1273cd6..eaa9a11f 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/ConversationViewModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/ConversationViewModel.cs @@ -1,3 +1,4 @@ +using BotSharp.Abstraction.Conversations.Enums; using BotSharp.Abstraction.Conversations.Models; using BotSharp.OpenAPI.ViewModels.Users; using System.Text.Json.Serialization; @@ -20,6 +21,7 @@ public class ConversationViewModel public string Event { get; set; } + public string Channel { get; set; } = ConversationChannel.OpenAPI; public string Status { get; set; } [JsonPropertyName("updated_time")] @@ -38,6 +40,7 @@ public class ConversationViewModel }, AgentId = sess.AgentId, Title = sess.Title, + Channel = sess.Channel, Status = sess.Status, CreatedTime = sess.CreatedTime, UpdatedTime = sess.UpdatedTime