diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs index 44e90d32..c475d6a5 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs @@ -16,15 +16,12 @@ public interface IConversationService /// Send message to LLM /// /// - /// - /// /// /// /// This delegate is useful when you want to report progress on UI /// This delegate is useful when you want to report progress on UI /// Task SendMessage(string agentId, - string channel, RoleDialogModel lastDalog, Func onMessageReceived, Func onFunctionExecuting, diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs index b393edd8..adf84334 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs @@ -10,13 +10,12 @@ namespace BotSharp.Core.Conversations.Services; public partial class ConversationService { public async Task SendMessage(string agentId, - string channel, RoleDialogModel message, Func onMessageReceived, Func onFunctionExecuting, Func onFunctionExecuted) { - var conversation = await GetConversationRecord(agentId, channel); + var conversation = await GetConversationRecord(agentId); var agentService = _services.GetRequiredService(); Agent agent = await agentService.LoadAgent(agentId); @@ -70,13 +69,15 @@ public partial class ConversationService return true; } - private async Task GetConversationRecord(string agentId, string channel) + private async Task GetConversationRecord(string agentId) { var converation = await GetConversation(_conversationId); // Create conversation if this conversation does not exist if (converation == null) { + var state = _services.GetRequiredService(); + var channel = state.GetState("channel"); var sess = new Conversation { Id = _conversationId, diff --git a/src/Infrastructure/BotSharp.Core/Evaluations/EvaluatingService.cs b/src/Infrastructure/BotSharp.Core/Evaluations/EvaluatingService.cs index d8824c7a..75191edf 100644 --- a/src/Infrastructure/BotSharp.Core/Evaluations/EvaluatingService.cs +++ b/src/Infrastructure/BotSharp.Core/Evaluations/EvaluatingService.cs @@ -88,12 +88,14 @@ public class EvaluatingService : IEvaluatingService private async Task SendMessage(string agentId, string conversationId, string text) { var conv = _services.GetRequiredService(); - conv.SetConversationId(conversationId, new List()); + conv.SetConversationId(conversationId, new List + { + $"channel={ConversationChannel.OpenAPI}" + }); RoleDialogModel response = default; await conv.SendMessage(agentId, - ConversationChannel.OpenAPI, new RoleDialogModel(AgentRole.User, text), async msg => response = msg, fnExecuting => Task.CompletedTask, diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs index 1516f867..5527f13f 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs @@ -143,8 +143,7 @@ public partial class RoutingService : IRoutingService // Filter agents by profile var state = _services.GetRequiredService(); - var conversation = db.GetConversation(state.GetConversationId()); - var channel = conversation?.Channel; + var channel = state.GetState("channel"); var specifiedProfile = agents.FirstOrDefault(x => x.Profiles.Contains(channel)); if (specifiedProfile != null) { diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs index b4d8a8e2..dde37482 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs @@ -1,3 +1,4 @@ +using BotSharp.Abstraction.Agents.Enums; using BotSharp.Abstraction.ApiAdapters; using BotSharp.Abstraction.Conversations.Enums; using BotSharp.Abstraction.Conversations.Models; @@ -99,14 +100,15 @@ public class ConversationController : ControllerBase, IApiAdapter { var conv = _services.GetRequiredService(); conv.SetConversationId(conversationId, input.States); - conv.States.SetState("provider", input.Provider) + conv.States.SetState("channel", input.Channel) + .SetState("provider", input.Provider) .SetState("model", input.Model) .SetState("temperature", input.Temperature) .SetState("sampling_factor", input.SamplingFactor); var response = new ChatResponseModel(); - var inputMsg = new RoleDialogModel("user", input.Text); - await conv.SendMessage(agentId, input.Channel, inputMsg, + var inputMsg = new RoleDialogModel(AgentRole.User, input.Text); + await conv.SendMessage(agentId, inputMsg, async msg => { response.Text = msg.Content; diff --git a/src/Plugins/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs b/src/Plugins/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs index 892d2894..5dd17606 100644 --- a/src/Plugins/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs +++ b/src/Plugins/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs @@ -76,13 +76,13 @@ public class ChatbotUiController : ControllerBase, IApiAdapter var conv = _services.GetRequiredService(); conv.SetConversationId(input.ConversationId, input.States); - conv.States.SetState("provider", input.Provider) + conv.States.SetState("channel", input.Channel) + .SetState("provider", input.Provider) .SetState("model", input.Model) .SetState("temperature", input.Temperature) .SetState("sampling_factor", input.SamplingFactor); var result = await conv.SendMessage(input.AgentId, - input.Channel, message, async msg => await OnChunkReceived(outputStream, msg), diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/Services/MessageHandleService.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/Services/MessageHandleService.cs index 6e84ec49..a11be86d 100644 --- a/src/Plugins/BotSharp.Plugin.MetaMessenger/Services/MessageHandleService.cs +++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/Services/MessageHandleService.cs @@ -48,10 +48,13 @@ public class MessageHandleService // Go to LLM var conv = _services.GetRequiredService(); - conv.SetConversationId(sender, new List()); + conv.SetConversationId(sender, new List + { + $"channel={ConversationChannel.Messenger}" + }); var replies = new List(); - var result = await conv.SendMessage(agentId, ConversationChannel.Messenger, + var result = await conv.SendMessage(agentId, new RoleDialogModel(AgentRole.User, message), async msg => { if (msg.RichContent != null) diff --git a/src/Plugins/BotSharp.Plugin.Twilio/Controllers/TwilioVoiceController.cs b/src/Plugins/BotSharp.Plugin.Twilio/Controllers/TwilioVoiceController.cs index 85b75834..ec2cd1a4 100644 --- a/src/Plugins/BotSharp.Plugin.Twilio/Controllers/TwilioVoiceController.cs +++ b/src/Plugins/BotSharp.Plugin.Twilio/Controllers/TwilioVoiceController.cs @@ -47,13 +47,13 @@ public class TwilioVoiceController : TwilioController var conv = _services.GetRequiredService(); conv.SetConversationId(sessionId, new List { + $"channel={ConversationChannel.Phone}", $"calling_phone={input.DialCallSid}" }); VoiceResponse response = default; var result = await conv.SendMessage(agentId, - ConversationChannel.Phone, new RoleDialogModel(AgentRole.User, input.SpeechResult), async msg => {