-
-
Notifications
You must be signed in to change notification settings - Fork 541
/
Copy pathAgentPlugin.cs
68 lines (58 loc) · 2.48 KB
/
AgentPlugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using BotSharp.Abstraction.MLTasks;
using BotSharp.Abstraction.Plugins.Models;
using BotSharp.Abstraction.Settings;
using BotSharp.Abstraction.Statistics.Settings;
using BotSharp.Abstraction.Templating;
using BotSharp.Abstraction.Users.Enums;
using BotSharp.Core.Agents.Hooks;
using Microsoft.Extensions.Configuration;
namespace BotSharp.Core.Agents;
public class AgentPlugin : IBotSharpPlugin
{
public string Id => "f4b367f8-4945-476a-90a7-c3bb8e6d6e49";
public string Name => "Agent";
public string Description => "A container of agent profile includes instruction, functions, examples and templates/ response templates.";
public SettingsMeta Settings =>
new SettingsMeta("Agent");
public string[] AgentIds => new string[]
{
BuiltInAgentId.AIAssistant,
BuiltInAgentId.Chatbot,
BuiltInAgentId.HumanSupport
};
public object GetNewSettingsInstance() =>
new AgentSettings();
public void RegisterDI(IServiceCollection services, IConfiguration config)
{
services.AddScoped<ILlmProviderService, LlmProviderService>();
services.AddScoped<IAgentService, AgentService>();
services.AddScoped<IAgentHook, BasicAgentHook>();
services.AddScoped<IBotSharpStatsService, BotSharpStatsService>();
services.AddScoped(provider =>
{
var settingService = provider.GetRequiredService<ISettingService>();
return settingService.Bind<StatisticsSettings>("Statistics");
});
services.AddScoped(provider =>
{
var settingService = provider.GetRequiredService<ISettingService>();
var render = provider.GetRequiredService<ITemplateRender>();
render.RegisterType(typeof(AgentSettings));
return settingService.Bind<AgentSettings>("Agent");
});
}
public bool AttachMenu(List<PluginMenuDef> menu)
{
var section = menu.First(x => x.Label == "Apps");
menu.Add(new PluginMenuDef("Agent", icon: "bx bx-bot", weight: section.Weight + 1)
{
SubMenu = new List<PluginMenuDef>
{
new PluginMenuDef("Routing", link: "page/agent/router"), // icon: "bx bx-map-pin"
new PluginMenuDef("Evaluating", link: "page/agent/evaluator") { Roles = new List<string> { UserRole.Root, UserRole.Admin } }, // icon: "bx bx-task"
new PluginMenuDef("Agents", link: "page/agent"), // icon: "bx bx-bot"
}
});
return true;
}
}