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;
|
2023-11-27 22:20:49 +00:00
|
|
|
using BotSharp.Abstraction.Repositories.Filters;
|
2023-09-22 20:38:58 +00:00
|
|
|
using BotSharp.Abstraction.Routing;
|
|
|
|
|
using BotSharp.Abstraction.Routing.Settings;
|
2024-01-29 18:08:49 +00:00
|
|
|
using BotSharp.Core.Routing.Planning;
|
2023-09-22 20:38:58 +00:00
|
|
|
|
|
|
|
|
namespace BotSharp.Core.Routing.Handlers;
|
|
|
|
|
|
2023-10-30 16:48:18 +00:00
|
|
|
public class ContinueExecuteTaskRoutingHandler : RoutingHandlerBase//, IRoutingHandler
|
2023-09-22 20:38:58 +00:00
|
|
|
{
|
|
|
|
|
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-30 16:48:18 +00:00
|
|
|
new ParameterPropertyDef("next_action_agent", "agent for next action based on user latest response"),
|
|
|
|
|
new ParameterPropertyDef("user_goal_agent", "agent who can achieve user original goal"),
|
2023-10-28 20:59:26 +00:00
|
|
|
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-30 16:48:18 +00:00
|
|
|
nameof(HFPlanner)
|
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)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-27 20:36:26 +00:00
|
|
|
public async Task<bool> Handle(IRoutingService routing, FunctionCallFromLlm inst, RoleDialogModel message)
|
2023-09-22 20:38:58 +00:00
|
|
|
{
|
|
|
|
|
var db = _services.GetRequiredService<IBotSharpRepository>();
|
2023-11-27 22:20:49 +00:00
|
|
|
var filter = new AgentFilter { AgentName = inst.AgentName };
|
|
|
|
|
var record = db.GetAgents(filter).FirstOrDefault();
|
2023-09-22 20:38:58 +00:00
|
|
|
|
2023-10-27 20:36:26 +00:00
|
|
|
message.FunctionName = inst.Function;
|
|
|
|
|
message.CurrentAgentId = record.Id;
|
|
|
|
|
message.FunctionArgs = JsonSerializer.Serialize(inst.Arguments);
|
2023-09-22 20:38:58 +00:00
|
|
|
|
2023-10-27 20:36:26 +00:00
|
|
|
return true;
|
2023-09-22 20:38:58 +00:00
|
|
|
}
|
|
|
|
|
}
|