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

48 lines
1.6 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.Repositories;
using BotSharp.Abstraction.Routing;
using BotSharp.Abstraction.Routing.Settings;
2023-10-29 01:54:10 +00:00
using BotSharp.Core.Planning;
2023-09-22 20:38:58 +00:00
namespace BotSharp.Core.Routing.Handlers;
public class ContinueExecuteTaskRoutingHandler : RoutingHandlerBase, IRoutingHandler
{
public string Name => "continue_execute_task";
public string Description => "Continue to execute user's request without further information retrival.";
2023-10-28 20:59:26 +00:00
public List<ParameterPropertyDef> Parameters => new List<ParameterPropertyDef>
2023-09-22 20:38:58 +00:00
{
2023-10-28 20:59:26 +00:00
new ParameterPropertyDef("agent", "the name of the agent"),
new ParameterPropertyDef("reason", "why continue to execute current task"),
new ParameterPropertyDef("args", "required parameters extracted from question")
{
Type = "object"
}
2023-09-22 20:38:58 +00:00
};
2023-10-28 20:59:26 +00:00
public List<string> Planers => new List<string>
{
2023-10-29 01:54:10 +00:00
nameof(ReasoningPlanner)
2023-10-28 20:59:26 +00:00
};
2023-09-22 20:38:58 +00:00
public ContinueExecuteTaskRoutingHandler(IServiceProvider services, ILogger<ContinueExecuteTaskRoutingHandler> logger, RoutingSettings settings)
: base(services, logger, settings)
{
}
public async Task<bool> Handle(IRoutingService routing, FunctionCallFromLlm inst, RoleDialogModel message)
2023-09-22 20:38:58 +00:00
{
var db = _services.GetRequiredService<IBotSharpRepository>();
var record = db.GetAgents(inst.AgentName).FirstOrDefault();
2023-09-22 20:38:58 +00:00
message.FunctionName = inst.Function;
message.CurrentAgentId = record.Id;
message.FunctionArgs = JsonSerializer.Serialize(inst.Arguments);
2023-09-22 20:38:58 +00:00
return true;
2023-09-22 20:38:58 +00:00
}
}