From 39a6d2ed054ce6f6db0c8f78f095586afa0f52b3 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Fri, 12 Jan 2024 18:31:25 -0600 Subject: [PATCH] Add AgentIds to IBotSharpPlugin --- .../Plugins/IBotSharpPlugin.cs | 2 +- .../Plugins/Models/PluginDef.cs | 4 ++-- .../BotSharp.Core/Plugins/PluginLoader.cs | 20 ++++++++++++++++++- .../HttpHandlerPlugin.cs | 2 +- .../KnowledgeBasePlugin.cs | 2 +- .../WebDriverPlugin.cs | 2 +- .../PizzaBotPlugin.cs | 8 +++++++- 7 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Plugins/IBotSharpPlugin.cs b/src/Infrastructure/BotSharp.Abstraction/Plugins/IBotSharpPlugin.cs index f7f87060..9ce98003 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Plugins/IBotSharpPlugin.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Plugins/IBotSharpPlugin.cs @@ -17,7 +17,7 @@ public interface IBotSharpPlugin /// /// Has build-in agent profile with this plugin /// - bool WithAgent => false; + string[] AgentIds => new string[0]; void RegisterDI(IServiceCollection services, IConfiguration config); diff --git a/src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginDef.cs b/src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginDef.cs index 7f009ce0..c14c03d4 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginDef.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginDef.cs @@ -9,8 +9,8 @@ public class PluginDef [JsonPropertyName("icon_url")] public string IconUrl { get; set; } - [JsonPropertyName("with_agent")] - public bool WithAgent { get; set; } + [JsonPropertyName("agent_ids")] + public string[] AgentIds { get; set; } public bool Enabled { get; set; } diff --git a/src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs b/src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs index 47b03c59..96a97c3f 100644 --- a/src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs +++ b/src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs @@ -56,7 +56,7 @@ public class PluginLoader Description = module.Description, Assembly = assemblyName, IconUrl = module.IconUrl, - WithAgent = module.WithAgent, + AgentIds = module.AgentIds, Menus = module.GetMenus(), }); Console.Write($"Loaded plugin "); @@ -104,6 +104,15 @@ public class PluginLoader config.EnabledPlugins.Add(id); db.SavePluginConfig(config); } + + // enable agents + var agentService = services.GetRequiredService(); + foreach (var agentId in plugin.AgentIds) + { + var agent = agentService.LoadAgent(agentId).Result; + agent.Disabled = false; + agentService.UpdateAgent(agent, AgentField.Disabled); + } } else { @@ -112,6 +121,15 @@ public class PluginLoader config.EnabledPlugins.Remove(id); db.SavePluginConfig(config); } + + // disable agents + var agentService = services.GetRequiredService(); + foreach (var agentId in plugin.AgentIds) + { + var agent = agentService.LoadAgent(agentId).Result; + agent.Disabled = true; + agentService.UpdateAgent(agent, AgentField.Disabled); + } } return plugin; } diff --git a/src/Plugins/BotSharp.Plugin.HttpHandler/HttpHandlerPlugin.cs b/src/Plugins/BotSharp.Plugin.HttpHandler/HttpHandlerPlugin.cs index 9efcec99..b64a3ad8 100644 --- a/src/Plugins/BotSharp.Plugin.HttpHandler/HttpHandlerPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.HttpHandler/HttpHandlerPlugin.cs @@ -8,7 +8,7 @@ public class HttpHandlerPlugin : IBotSharpPlugin public string Name => "HTTP Handler"; public string Description => "Empower agent to handle HTTP request in RESTful API or GraphQL"; public string IconUrl => "https://lirp.cdn-website.com/6f8d6d8a/dms3rep/multi/opt/API_Icon-640w.png"; - public bool WithAgent => true; + public string[] AgentIds => new[] { "87c458fc-ec5f-40ae-8ed6-05dda8a07523" }; public void RegisterDI(IServiceCollection services, IConfiguration config) { diff --git a/src/Plugins/BotSharp.Plugin.KnowledgeBase/KnowledgeBasePlugin.cs b/src/Plugins/BotSharp.Plugin.KnowledgeBase/KnowledgeBasePlugin.cs index eb41f859..91ce959a 100644 --- a/src/Plugins/BotSharp.Plugin.KnowledgeBase/KnowledgeBasePlugin.cs +++ b/src/Plugins/BotSharp.Plugin.KnowledgeBase/KnowledgeBasePlugin.cs @@ -9,7 +9,7 @@ public class KnowledgeBasePlugin : IBotSharpPlugin public string Name => "Knowledge Base"; public string Description => "Embedding private data and feed them into LLM in the conversation."; public string IconUrl => "https://cdn-icons-png.flaticon.com/512/9592/9592995.png"; - public bool WithAgent => true; + public string[] AgentIds => new[] { "f5679799-ba89-4fef-936a-bcc311e5f14d" }; public void RegisterDI(IServiceCollection services, IConfiguration config) { diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/WebDriverPlugin.cs b/src/Plugins/BotSharp.Plugin.WebDriver/WebDriverPlugin.cs index 7abd0264..6990980a 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/WebDriverPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/WebDriverPlugin.cs @@ -10,7 +10,7 @@ public class WebDriverPlugin : IBotSharpPlugin public string Name => "Web Driver"; public string Description => "Empower agent to manipulate web browser in automation tools."; public string IconUrl => "https://cdn-icons-png.flaticon.com/512/8576/8576378.png"; - public bool WithAgent => true; + public string[] AgentIds => new[] { "f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b" }; public void RegisterDI(IServiceCollection services, IConfiguration config) { diff --git a/tests/BotSharp.Plugin.PizzaBot/PizzaBotPlugin.cs b/tests/BotSharp.Plugin.PizzaBot/PizzaBotPlugin.cs index 806e5fc6..d3d4c3a6 100644 --- a/tests/BotSharp.Plugin.PizzaBot/PizzaBotPlugin.cs +++ b/tests/BotSharp.Plugin.PizzaBot/PizzaBotPlugin.cs @@ -9,7 +9,13 @@ public class PizzaBotPlugin : IBotSharpPlugin public string Name => "Pizza AI Assistant"; public string Description => "An example of an enterprise-grade AI Chatbot."; public string IconUrl => "https://cdn-icons-png.flaticon.com/512/6978/6978255.png"; - public bool WithAgent => true; + public string[] AgentIds => new[] + { + "b284db86-e9c2-4c25-a59e-4649797dd130", + "c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd", + "dfd9b46d-d00c-40af-8a75-3fbdc2b89869", + "fe8c60aa-b114-4ef3-93cb-a8efeac80f75" + }; public void RegisterDI(IServiceCollection services, IConfiguration config) {