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

43 lines
1.6 KiB
C#
Raw Normal View History

2023-09-22 20:38:58 +00:00
using BotSharp.Abstraction.Functions;
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.Models;
using BotSharp.Abstraction.Routing.Settings;
namespace BotSharp.Core.Routing.Handlers;
public class RouteToAgentRoutingHandler : RoutingHandlerBase, IRoutingHandler
{
public string Name => "route_to_agent";
public string Description => "Route request to appropriate agent.";
2023-09-24 16:20:02 +00:00
public List<NameDesc> Parameters => new List<NameDesc>
2023-09-22 20:38:58 +00:00
{
2023-10-20 03:47:14 +00:00
new NameDesc("reason", "why route to agent"),
new NameDesc("next_action_agent", "agent for next action based on user latest response"),
new NameDesc("user_goal_agent", "agent who can achieve user original goal"),
2023-10-13 20:08:59 +00:00
new NameDesc("args", "useful parameters of next action agent")
2023-09-22 20:38:58 +00:00
};
public bool IsReasoning => false;
public RouteToAgentRoutingHandler(IServiceProvider services, ILogger<RouteToAgentRoutingHandler> 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 context = _services.GetRequiredService<RoutingContext>();
2023-09-22 20:38:58 +00:00
var function = _services.GetServices<IFunctionCallback>().FirstOrDefault(x => x.Name == inst.Function);
message.FunctionArgs = JsonSerializer.Serialize(inst);
2023-09-22 20:38:58 +00:00
var ret = await function.Execute(message);
ret = await routing.InvokeAgent(context.GetCurrentAgentId(), message);
2023-10-27 15:18:48 +00:00
return true;
2023-09-22 20:38:58 +00:00
}
}