BotSharp/src/Infrastructure/BotSharp.Core/Routing/Handlers/TaskEndRoutingHandler.cs

47 lines
1.3 KiB
C#
Raw Normal View History

2023-09-22 20:38:58 +00:00
using BotSharp.Abstraction.Functions.Models;
2023-09-24 16:20:02 +00:00
using BotSharp.Abstraction.Models;
2023-09-22 20:38:58 +00:00
using BotSharp.Abstraction.Routing;
using BotSharp.Abstraction.Routing.Settings;
namespace BotSharp.Core.Routing.Handlers;
public class TaskEndRoutingHandler : RoutingHandlerBase, IRoutingHandler
{
public string Name => "task_end";
public string Description => "Call this function when current task is completed.";
2023-09-24 16:20:02 +00:00
public List<NameDesc> Parameters => new List<NameDesc>
2023-09-22 20:38:58 +00:00
{
2023-09-24 16:20:02 +00:00
new NameDesc("abandoned_arguments", "the arguments next task can't reuse")
2023-09-22 20:38:58 +00:00
};
public bool IsReasoning => true;
public TaskEndRoutingHandler(IServiceProvider services, ILogger<TaskEndRoutingHandler> logger, RoutingSettings settings)
: base(services, logger, settings)
{
}
2023-10-16 20:07:07 +00:00
public async Task<RoleDialogModel> Handle(IRoutingService routing, FunctionCallFromLlm inst)
2023-09-22 20:38:58 +00:00
{
2023-10-16 20:07:07 +00:00
var result = new RoleDialogModel(AgentRole.Assistant, inst.Response)
{
CurrentAgentId = _settings.RouterId,
FunctionName = inst.Function,
2023-10-23 00:31:49 +00:00
Data = inst
2023-10-16 20:07:07 +00:00
};
var hooks = _services.GetServices<IConversationHook>()
.OrderBy(x => x.Priority)
.ToList();
foreach (var hook in hooks)
{
2023-10-23 00:31:49 +00:00
await hook.OnCurrentTaskEnding(result);
2023-10-16 20:07:07 +00:00
}
return result;
2023-09-22 20:38:58 +00:00
}
}