2023-09-28 03:31:58 +00:00
|
|
|
using BotSharp.Abstraction.Functions.Models;
|
2023-10-12 11:30:13 +00:00
|
|
|
using BotSharp.Abstraction.Routing;
|
2023-10-24 21:38:34 +00:00
|
|
|
using BotSharp.Abstraction.Routing.Settings;
|
2023-09-28 03:31:58 +00:00
|
|
|
|
|
|
|
|
namespace BotSharp.Core.Routing.Hooks;
|
|
|
|
|
|
|
|
|
|
public class RoutingAgentHook : AgentHookBase
|
|
|
|
|
{
|
2023-10-24 21:38:34 +00:00
|
|
|
private readonly RoutingSettings _routingSetting;
|
2024-01-13 21:17:40 +00:00
|
|
|
public override string SelfId => string.Empty;
|
2023-10-24 21:38:34 +00:00
|
|
|
|
|
|
|
|
public RoutingAgentHook(IServiceProvider services, AgentSettings settings, RoutingSettings routingSetting)
|
2023-09-28 03:31:58 +00:00
|
|
|
: base(services, settings)
|
|
|
|
|
{
|
2023-10-24 21:38:34 +00:00
|
|
|
_routingSetting = routingSetting;
|
2023-09-28 03:31:58 +00:00
|
|
|
}
|
|
|
|
|
|
2023-10-12 11:30:13 +00:00
|
|
|
public override bool OnInstructionLoaded(string template, Dictionary<string, object> dict)
|
|
|
|
|
{
|
2024-01-26 04:32:48 +00:00
|
|
|
if (_agent.Type != AgentType.Routing)
|
2024-01-13 21:17:40 +00:00
|
|
|
{
|
|
|
|
|
return base.OnInstructionLoaded(template, dict);
|
|
|
|
|
}
|
2023-10-12 11:30:13 +00:00
|
|
|
dict["router"] = _agent;
|
|
|
|
|
|
2023-11-01 01:48:12 +00:00
|
|
|
var routing = _services.GetRequiredService<IRoutingService>();
|
2024-01-24 23:02:59 +00:00
|
|
|
var agents = routing.GetRoutableAgents(_agent.Profiles);
|
|
|
|
|
dict["routing_agents"] = agents;
|
2023-11-01 01:48:12 +00:00
|
|
|
dict["routing_handlers"] = routing.GetHandlers();
|
2023-10-12 11:30:13 +00:00
|
|
|
|
|
|
|
|
return base.OnInstructionLoaded(template, dict);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-29 18:08:42 +00:00
|
|
|
public override bool OnFunctionsLoaded(List<FunctionDef> functions)
|
2023-09-28 03:31:58 +00:00
|
|
|
{
|
2023-09-28 17:42:14 +00:00
|
|
|
/*functions.Add(new FunctionDef
|
2023-09-28 03:31:58 +00:00
|
|
|
{
|
|
|
|
|
Name = "fallback_to_router",
|
|
|
|
|
Description = "If the user's request is beyond your capabilities, you can call this function for help."
|
2023-09-28 17:42:14 +00:00
|
|
|
});*/
|
2023-09-29 18:08:42 +00:00
|
|
|
return base.OnFunctionsLoaded(functions);
|
2023-09-28 03:31:58 +00:00
|
|
|
}
|
|
|
|
|
}
|