using BotSharp.Abstraction.Functions.Models; using BotSharp.Abstraction.Routing; using BotSharp.Abstraction.Routing.Settings; namespace BotSharp.Core.Routing.Handlers; public class ConversationEndRoutingHandler : RoutingHandlerBase, IRoutingHandler { public string Name => "conversation_end"; public string Description => "User completed his task and wants to end the conversation."; public List Parameters => new List { new ParameterPropertyDef("reason", "why end conversation"), new ParameterPropertyDef("response", "response content to user") }; public ConversationEndRoutingHandler(IServiceProvider services, ILogger logger, RoutingSettings settings) : base(services, logger, settings) { } public async Task Handle(IRoutingService routing, FunctionCallFromLlm inst, RoleDialogModel message) { var response = new RoleDialogModel(AgentRole.Assistant, inst.Response) { CurrentAgentId = message.CurrentAgentId, MessageId = message.MessageId, StopCompletion = true, FunctionName = inst.Function }; _dialogs.Add(response); var hooks = _services.GetServices() .OrderBy(x => x.Priority) .ToList(); foreach (var hook in hooks) { await hook.OnConversationEnding(response); } return true; } }