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;
|
|
|
|
|
|
|
|
|
|
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-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 21:32:58 +00:00
|
|
|
new NameDesc("agent", "the name of the agent"),
|
2023-09-24 16:20:02 +00:00
|
|
|
new NameDesc("args", "required parameters extracted from question"),
|
|
|
|
|
new NameDesc("reason", "why continue to execute current task")
|
2023-09-22 20:38:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public bool IsReasoning => true;
|
|
|
|
|
|
|
|
|
|
public ContinueExecuteTaskRoutingHandler(IServiceProvider services, ILogger<ContinueExecuteTaskRoutingHandler> logger, RoutingSettings settings)
|
|
|
|
|
: base(services, logger, settings)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<RoleDialogModel> Handle(FunctionCallFromLlm inst)
|
|
|
|
|
{
|
|
|
|
|
var routing = _services.GetRequiredService<IAgentRouting>();
|
|
|
|
|
var db = _services.GetRequiredService<IBotSharpRepository>();
|
|
|
|
|
var record = db.Agents.First(x => x.Name.ToLower() == inst.Route.AgentName.ToLower());
|
|
|
|
|
|
|
|
|
|
var result = new RoleDialogModel(AgentRole.Function, inst.Question)
|
|
|
|
|
{
|
|
|
|
|
FunctionName = inst.Function,
|
|
|
|
|
FunctionArgs = JsonSerializer.Serialize(inst.Arguments),
|
|
|
|
|
CurrentAgentId = record.Id
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|