diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs index 3cfc7011..f195591a 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs @@ -54,7 +54,7 @@ public abstract class AgentHookBase : IAgentHook return true; } - public virtual void OnAgentLoaded(Agent agent) + public virtual void OnAgentLoaded(Agent agent) { } diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs index 1461cc22..b8945f40 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs @@ -59,5 +59,5 @@ public interface IAgentService PluginDef GetPlugin(string agentId); - IEnumerable GetAgentUtilities(); + IEnumerable GetAgentUtilityOptions(); } diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentUtilityHook.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentUtilityHook.cs index 9d5667b8..603ec64e 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentUtilityHook.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentUtilityHook.cs @@ -2,5 +2,5 @@ namespace BotSharp.Abstraction.Agents; public interface IAgentUtilityHook { - void AddUtilities(List utilities); + void AddUtilities(List utilities); } diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs index a48201d8..1dd331af 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs @@ -57,14 +57,14 @@ public partial class AgentService : IAgentService return userAgents; } - public IEnumerable GetAgentUtilities() + public IEnumerable GetAgentUtilityOptions() { - var utilities = new List(); + var utilities = new List(); var hooks = _services.GetServices(); foreach (var hook in hooks) { hook.AddUtilities(utilities); } - return utilities.Where(x => !string.IsNullOrWhiteSpace(x)).Distinct().OrderBy(x => x).ToList(); + return utilities.Where(x => !string.IsNullOrWhiteSpace(x.Name)).OrderBy(x => x.Name).ToList(); } } diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs index 5ce68c2a..40c4c03f 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs @@ -1,3 +1,4 @@ +using BotSharp.Abstraction.Agents.Models; using BotSharp.Abstraction.Users.Enums; namespace BotSharp.OpenAPI.Controllers; @@ -153,9 +154,9 @@ public class AgentController : ControllerBase return await _agentService.DeleteAgent(agentId); } - [HttpGet("/agent/utilities")] - public IEnumerable GetAgentUtilities() + [HttpGet("/agent/utility/options")] + public IEnumerable GetAgentUtilityOptions() { - return _agentService.GetAgentUtilities(); + return _agentService.GetAgentUtilityOptions(); } } \ No newline at end of file diff --git a/src/Plugins/BotSharp.Plugin.AudioHandler/AudioHandlerPlugin.cs b/src/Plugins/BotSharp.Plugin.AudioHandler/AudioHandlerPlugin.cs index 2c289907..d79ca6c2 100644 --- a/src/Plugins/BotSharp.Plugin.AudioHandler/AudioHandlerPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.AudioHandler/AudioHandlerPlugin.cs @@ -17,7 +17,6 @@ public class AudioHandlerPlugin : IBotSharpPlugin }); services.AddScoped(); - services.AddScoped(); services.AddScoped(); } } diff --git a/src/Plugins/BotSharp.Plugin.AudioHandler/Hooks/AudioHandlerHook.cs b/src/Plugins/BotSharp.Plugin.AudioHandler/Hooks/AudioHandlerHook.cs deleted file mode 100644 index 20565679..00000000 --- a/src/Plugins/BotSharp.Plugin.AudioHandler/Hooks/AudioHandlerHook.cs +++ /dev/null @@ -1,27 +0,0 @@ -using BotSharp.Abstraction.Agents.Settings; - -namespace BotSharp.Plugin.AudioHandler.Hooks; - -public class AudioHandlerHook : AgentHookBase, IAgentHook -{ - private const string HANDLER_AUDIO = "handle_audio_request"; - - public override string SelfId => string.Empty; - - public AudioHandlerHook(IServiceProvider services, AgentSettings settings) - : base(services, settings) - { - } - - public override void OnAgentLoaded(Agent agent) - { - var utilityLoad = new AgentUtility - { - Name = UtilityName.AudioHandler, - Functions = [new(HANDLER_AUDIO)], - Templates = [new($"{HANDLER_AUDIO}.fn")] - }; - - base.OnAgentLoaded(agent); - } -} diff --git a/src/Plugins/BotSharp.Plugin.AudioHandler/Hooks/AudioHandlerUtilityHook.cs b/src/Plugins/BotSharp.Plugin.AudioHandler/Hooks/AudioHandlerUtilityHook.cs index ac3f0ed7..3d1f3992 100644 --- a/src/Plugins/BotSharp.Plugin.AudioHandler/Hooks/AudioHandlerUtilityHook.cs +++ b/src/Plugins/BotSharp.Plugin.AudioHandler/Hooks/AudioHandlerUtilityHook.cs @@ -2,8 +2,17 @@ namespace BotSharp.Plugin.AudioHandler.Hooks; public class AudioHandlerUtilityHook : IAgentUtilityHook { - public void AddUtilities(List utilities) + private const string HANDLER_AUDIO = "handle_audio_request"; + + public void AddUtilities(List utilities) { - utilities.Add(UtilityName.AudioHandler); + var utility = new AgentUtility + { + Name = UtilityName.AudioHandler, + Functions = [new(HANDLER_AUDIO)], + Templates = [new($"{HANDLER_AUDIO}.fn")] + }; + + utilities.Add(utility); } } \ No newline at end of file diff --git a/src/Plugins/BotSharp.Plugin.EmailHandler/EmailHandlerPlugin.cs b/src/Plugins/BotSharp.Plugin.EmailHandler/EmailHandlerPlugin.cs index eb52b719..fffc8c31 100644 --- a/src/Plugins/BotSharp.Plugin.EmailHandler/EmailHandlerPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.EmailHandler/EmailHandlerPlugin.cs @@ -20,7 +20,6 @@ namespace BotSharp.Plugin.EmailHandler return settingService.Bind("EmailSender"); }); - services.AddScoped(); services.AddScoped(); var emailReaderSettings = new EmailReaderSettings(); diff --git a/src/Plugins/BotSharp.Plugin.EmailHandler/Hooks/EmailHandlerHook.cs b/src/Plugins/BotSharp.Plugin.EmailHandler/Hooks/EmailHandlerHook.cs deleted file mode 100644 index ae38e329..00000000 --- a/src/Plugins/BotSharp.Plugin.EmailHandler/Hooks/EmailHandlerHook.cs +++ /dev/null @@ -1,30 +0,0 @@ -using BotSharp.Abstraction.Agents; -using BotSharp.Abstraction.Agents.Settings; -using BotSharp.Plugin.EmailHandler.Enums; - -namespace BotSharp.Plugin.EmailHandler.Hooks; - -public class EmailHandlerHook : AgentHookBase -{ - private static string EMAIL_READER_FN = "handle_email_reader"; - private static string EMAIL_SENDER_FN = "handle_email_sender"; - - public override string SelfId => string.Empty; - - public EmailHandlerHook(IServiceProvider services, AgentSettings settings) - : base(services, settings) - { - } - - public override void OnAgentLoaded(Agent agent) - { - var utilityLoad = new AgentUtility - { - Name = UtilityName.EmailHandler, - Functions = [new(EMAIL_READER_FN), new(EMAIL_SENDER_FN)], - Templates = [new($"{EMAIL_READER_FN}.fn"), new($"{EMAIL_SENDER_FN}.fn")] - }; - - base.OnAgentLoaded(agent); - } -} diff --git a/src/Plugins/BotSharp.Plugin.EmailHandler/Hooks/EmailHandlerUtilityHook.cs b/src/Plugins/BotSharp.Plugin.EmailHandler/Hooks/EmailHandlerUtilityHook.cs index 7d6a3be2..a909932e 100644 --- a/src/Plugins/BotSharp.Plugin.EmailHandler/Hooks/EmailHandlerUtilityHook.cs +++ b/src/Plugins/BotSharp.Plugin.EmailHandler/Hooks/EmailHandlerUtilityHook.cs @@ -5,8 +5,18 @@ namespace BotSharp.Plugin.EmailHandler.Hooks; public class EmailHandlerUtilityHook : IAgentUtilityHook { - public void AddUtilities(List utilities) + private static string EMAIL_READER_FN = "handle_email_reader"; + private static string EMAIL_SENDER_FN = "handle_email_sender"; + + public void AddUtilities(List utilities) { - utilities.Add(UtilityName.EmailHandler); + var utility = new AgentUtility + { + Name = UtilityName.EmailHandler, + Functions = [new(EMAIL_READER_FN), new(EMAIL_SENDER_FN)], + Templates = [new($"{EMAIL_READER_FN}.fn"), new($"{EMAIL_SENDER_FN}.fn")] + }; + + utilities.Add(utility); } } diff --git a/src/Plugins/BotSharp.Plugin.ExcelHandler/ExcelHandlerPlugin.cs b/src/Plugins/BotSharp.Plugin.ExcelHandler/ExcelHandlerPlugin.cs index 0111ea99..08d652f0 100644 --- a/src/Plugins/BotSharp.Plugin.ExcelHandler/ExcelHandlerPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.ExcelHandler/ExcelHandlerPlugin.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using BotSharp.Abstraction.Plugins; using BotSharp.Abstraction.Settings; using BotSharp.Plugin.ExcelHandler.Helpers.MySql; @@ -30,7 +25,6 @@ public class ExcelHandlerPlugin : IBotSharpPlugin }); services.AddScoped(); - services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/src/Plugins/BotSharp.Plugin.ExcelHandler/Hooks/ExcelHandlerHook.cs b/src/Plugins/BotSharp.Plugin.ExcelHandler/Hooks/ExcelHandlerHook.cs deleted file mode 100644 index de02c18a..00000000 --- a/src/Plugins/BotSharp.Plugin.ExcelHandler/Hooks/ExcelHandlerHook.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace BotSharp.Plugin.ExcelHandler.Hooks; - -public class ExcelHandlerHook : AgentHookBase, IAgentHook -{ - private const string HANDLER_EXCEL = "handle_excel_request"; - - public override string SelfId => string.Empty; - - public ExcelHandlerHook(IServiceProvider services, AgentSettings settings) : base(services, settings) - { - } - - public override void OnAgentLoaded(Agent agent) - { - var utilityLoad = new AgentUtility - { - Name = UtilityName.ExcelHandler, - Functions = [new(HANDLER_EXCEL)], - Templates = [new($"{HANDLER_EXCEL}.fn")] - }; - - base.OnAgentLoaded(agent); - } -} - diff --git a/src/Plugins/BotSharp.Plugin.ExcelHandler/Hooks/ExcelHandlerUtilityHook.cs b/src/Plugins/BotSharp.Plugin.ExcelHandler/Hooks/ExcelHandlerUtilityHook.cs index fde7533f..15c41642 100644 --- a/src/Plugins/BotSharp.Plugin.ExcelHandler/Hooks/ExcelHandlerUtilityHook.cs +++ b/src/Plugins/BotSharp.Plugin.ExcelHandler/Hooks/ExcelHandlerUtilityHook.cs @@ -2,8 +2,17 @@ namespace BotSharp.Plugin.ExcelHandler.Hooks; public class ExcelHandlerUtilityHook : IAgentUtilityHook { - public void AddUtilities(List utilities) + private const string HANDLER_EXCEL = "handle_excel_request"; + + public void AddUtilities(List utilities) { - utilities.Add(UtilityName.ExcelHandler); + var utility = new AgentUtility + { + Name = UtilityName.ExcelHandler, + Functions = [new(HANDLER_EXCEL)], + Templates = [new($"{HANDLER_EXCEL}.fn")] + }; + + utilities.Add(utility); } } \ No newline at end of file diff --git a/src/Plugins/BotSharp.Plugin.FileHandler/FileHandlerPlugin.cs b/src/Plugins/BotSharp.Plugin.FileHandler/FileHandlerPlugin.cs index caef8304..a8ecac6d 100644 --- a/src/Plugins/BotSharp.Plugin.FileHandler/FileHandlerPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.FileHandler/FileHandlerPlugin.cs @@ -19,7 +19,6 @@ public class FileHandlerPlugin : IBotSharpPlugin return settingService.Bind("FileHandler"); }); - services.AddScoped(); services.AddScoped(); } diff --git a/src/Plugins/BotSharp.Plugin.FileHandler/Hooks/FileHandlerHook.cs b/src/Plugins/BotSharp.Plugin.FileHandler/Hooks/FileHandlerHook.cs deleted file mode 100644 index cc0d0653..00000000 --- a/src/Plugins/BotSharp.Plugin.FileHandler/Hooks/FileHandlerHook.cs +++ /dev/null @@ -1,48 +0,0 @@ -namespace BotSharp.Plugin.FileHandler.Hooks; - -public class FileHandlerHook : AgentHookBase, IAgentHook -{ - private const string READ_IMAGE_FN = "read_image"; - private const string READ_PDF_FN = "read_pdf"; - private const string GENERATE_IMAGE_FN = "generate_image"; - private const string EDIT_IMAGE_FN = "edit_image"; - - public override string SelfId => string.Empty; - - public FileHandlerHook(IServiceProvider services, AgentSettings settings) : base(services, settings) - { - } - - public override void OnAgentLoaded(Agent agent) - { - var utilityLoads = new List - { - new AgentUtility - { - Name = UtilityName.ImageGenerator, - Functions = [new(GENERATE_IMAGE_FN)], - Templates = [new($"{GENERATE_IMAGE_FN}.fn")] - }, - new AgentUtility - { - Name = UtilityName.ImageReader, - Functions = [new(READ_IMAGE_FN)], - Templates = [new($"{READ_IMAGE_FN}.fn")] - }, - new AgentUtility - { - Name = UtilityName.ImageEditor, - Functions = [new(EDIT_IMAGE_FN)], - Templates = [new($"{EDIT_IMAGE_FN}.fn")] - }, - new AgentUtility - { - Name = UtilityName.PdfReader, - Functions = [new(READ_PDF_FN)], - Templates = [new($"{READ_PDF_FN}.fn")] - } - }; - - base.OnAgentLoaded(agent); - } -} diff --git a/src/Plugins/BotSharp.Plugin.FileHandler/Hooks/FileHandlerUtilityHook.cs b/src/Plugins/BotSharp.Plugin.FileHandler/Hooks/FileHandlerUtilityHook.cs index ce28634f..3a5a1e0c 100644 --- a/src/Plugins/BotSharp.Plugin.FileHandler/Hooks/FileHandlerUtilityHook.cs +++ b/src/Plugins/BotSharp.Plugin.FileHandler/Hooks/FileHandlerUtilityHook.cs @@ -2,11 +2,42 @@ namespace BotSharp.Plugin.FileHandler.Hooks; public class FileHandlerUtilityHook : IAgentUtilityHook { - public void AddUtilities(List utilities) + private const string READ_IMAGE_FN = "read_image"; + private const string READ_PDF_FN = "read_pdf"; + private const string GENERATE_IMAGE_FN = "generate_image"; + private const string EDIT_IMAGE_FN = "edit_image"; + + public void AddUtilities(List utilities) { - utilities.Add(UtilityName.ImageGenerator); - utilities.Add(UtilityName.ImageReader); - utilities.Add(UtilityName.ImageEditor); - utilities.Add(UtilityName.PdfReader); + + var items = new List + { + new AgentUtility + { + Name = UtilityName.ImageGenerator, + Functions = [new(GENERATE_IMAGE_FN)], + Templates = [new($"{GENERATE_IMAGE_FN}.fn")] + }, + new AgentUtility + { + Name = UtilityName.ImageReader, + Functions = [new(READ_IMAGE_FN)], + Templates = [new($"{READ_IMAGE_FN}.fn")] + }, + new AgentUtility + { + Name = UtilityName.ImageEditor, + Functions = [new(EDIT_IMAGE_FN)], + Templates = [new($"{EDIT_IMAGE_FN}.fn")] + }, + new AgentUtility + { + Name = UtilityName.PdfReader, + Functions = [new(READ_PDF_FN)], + Templates = [new($"{READ_PDF_FN}.fn")] + } + }; + + utilities.AddRange(items); } } diff --git a/src/Plugins/BotSharp.Plugin.HttpHandler/Hooks/HttpHandlerHook.cs b/src/Plugins/BotSharp.Plugin.HttpHandler/Hooks/HttpHandlerHook.cs deleted file mode 100644 index e30fc329..00000000 --- a/src/Plugins/BotSharp.Plugin.HttpHandler/Hooks/HttpHandlerHook.cs +++ /dev/null @@ -1,28 +0,0 @@ -using BotSharp.Abstraction.Agents; -using BotSharp.Abstraction.Agents.Settings; - -namespace BotSharp.Plugin.HttpHandler.Hooks; - -public class HttpHandlerHook : AgentHookBase -{ - private static string HTTP_HANDLER_FN = "handle_http_request"; - - public override string SelfId => string.Empty; - - public HttpHandlerHook(IServiceProvider services, AgentSettings settings) - : base(services, settings) - { - } - - public override void OnAgentLoaded(Agent agent) - { - var utilityLoad = new AgentUtility - { - Name = UtilityName.HttpHandler, - Functions = [new(HTTP_HANDLER_FN)], - Templates = [new($"{HTTP_HANDLER_FN}.fn")] - }; - - base.OnAgentLoaded(agent); - } -} diff --git a/src/Plugins/BotSharp.Plugin.HttpHandler/Hooks/HttpHandlerUtilityHook.cs b/src/Plugins/BotSharp.Plugin.HttpHandler/Hooks/HttpHandlerUtilityHook.cs index 17a38df5..265558ac 100644 --- a/src/Plugins/BotSharp.Plugin.HttpHandler/Hooks/HttpHandlerUtilityHook.cs +++ b/src/Plugins/BotSharp.Plugin.HttpHandler/Hooks/HttpHandlerUtilityHook.cs @@ -4,8 +4,17 @@ namespace BotSharp.Plugin.HttpHandler.Hooks; public class HttpHandlerUtilityHook : IAgentUtilityHook { - public void AddUtilities(List utilities) + private static string HTTP_HANDLER_FN = "handle_http_request"; + + public void AddUtilities(List utilities) { - utilities.Add(UtilityName.HttpHandler); + var utility = new AgentUtility + { + Name = UtilityName.HttpHandler, + Functions = [new(HTTP_HANDLER_FN)], + Templates = [new($"{HTTP_HANDLER_FN}.fn")] + }; + + utilities.Add(utility); } } diff --git a/src/Plugins/BotSharp.Plugin.HttpHandler/HttpHandlerPlugin.cs b/src/Plugins/BotSharp.Plugin.HttpHandler/HttpHandlerPlugin.cs index 48d71ee8..9c8cab55 100644 --- a/src/Plugins/BotSharp.Plugin.HttpHandler/HttpHandlerPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.HttpHandler/HttpHandlerPlugin.cs @@ -20,7 +20,6 @@ public class HttpHandlerPlugin : IBotSharpPlugin return settingService.Bind("HttpHandler"); }); - services.AddScoped(); services.AddScoped(); } } diff --git a/src/Plugins/BotSharp.Plugin.KnowledgeBase/Hooks/KnowledgeBaseAgentHook.cs b/src/Plugins/BotSharp.Plugin.KnowledgeBase/Hooks/KnowledgeBaseAgentHook.cs deleted file mode 100644 index 852ab0da..00000000 --- a/src/Plugins/BotSharp.Plugin.KnowledgeBase/Hooks/KnowledgeBaseAgentHook.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace BotSharp.Plugin.KnowledgeBase.Hooks; - -public class KnowledgeBaseAgentHook : AgentHookBase, IAgentHook -{ - private const string KNOWLEDGE_RETRIEVAL_FN = "knowledge_retrieval"; - - public override string SelfId => string.Empty; - - public KnowledgeBaseAgentHook(IServiceProvider services, AgentSettings settings) - : base(services, settings) - { - - } - - public override void OnAgentLoaded(Agent agent) - { - var utilityLoad = new AgentUtility - { - Name = UtilityName.KnowledgeRetrieval, - Functions = [new(KNOWLEDGE_RETRIEVAL_FN)], - Templates = [new($"{KNOWLEDGE_RETRIEVAL_FN}.fn")] - }; - - base.OnAgentLoaded(agent); - } -} diff --git a/src/Plugins/BotSharp.Plugin.KnowledgeBase/Hooks/KnowledgeBaseUtilityHook.cs b/src/Plugins/BotSharp.Plugin.KnowledgeBase/Hooks/KnowledgeBaseUtilityHook.cs index cd428136..464fd5b2 100644 --- a/src/Plugins/BotSharp.Plugin.KnowledgeBase/Hooks/KnowledgeBaseUtilityHook.cs +++ b/src/Plugins/BotSharp.Plugin.KnowledgeBase/Hooks/KnowledgeBaseUtilityHook.cs @@ -2,8 +2,17 @@ namespace BotSharp.Plugin.KnowledgeBase.Hooks; public class KnowledgeBaseUtilityHook : IAgentUtilityHook { - public void AddUtilities(List utilities) + private const string KNOWLEDGE_RETRIEVAL_FN = "knowledge_retrieval"; + + public void AddUtilities(List utilities) { - utilities.Add(UtilityName.KnowledgeRetrieval); + var utility = new AgentUtility + { + Name = UtilityName.KnowledgeRetrieval, + Functions = [new(KNOWLEDGE_RETRIEVAL_FN)], + Templates = [new($"{KNOWLEDGE_RETRIEVAL_FN}.fn")] + }; + + utilities.Add(utility); } } diff --git a/src/Plugins/BotSharp.Plugin.KnowledgeBase/KnowledgeBasePlugin.cs b/src/Plugins/BotSharp.Plugin.KnowledgeBase/KnowledgeBasePlugin.cs index ebb5aa63..8d89daf6 100644 --- a/src/Plugins/BotSharp.Plugin.KnowledgeBase/KnowledgeBasePlugin.cs +++ b/src/Plugins/BotSharp.Plugin.KnowledgeBase/KnowledgeBasePlugin.cs @@ -25,7 +25,6 @@ public class KnowledgeBasePlugin : IBotSharpPlugin services.AddSingleton(); services.AddScoped(); - services.AddScoped(); services.AddScoped(); } diff --git a/src/Plugins/BotSharp.Plugin.Planner/Hooks/PlannerAgentHook.cs b/src/Plugins/BotSharp.Plugin.Planner/Hooks/PlannerAgentHook.cs index 60f39a7d..d4bd1594 100644 --- a/src/Plugins/BotSharp.Plugin.Planner/Hooks/PlannerAgentHook.cs +++ b/src/Plugins/BotSharp.Plugin.Planner/Hooks/PlannerAgentHook.cs @@ -2,10 +2,6 @@ namespace BotSharp.Plugin.Planner.Hooks; public class PlannerAgentHook : AgentHookBase { - private const string PRIMARY_STAGE_FN = "plan_primary_stage"; - private const string SECONDARY_STAGE_FN = "plan_secondary_stage"; - private const string SUMMARY_FN = "plan_summary"; - public override string SelfId => BuiltInAgentId.Planner; public PlannerAgentHook(IServiceProvider services, AgentSettings settings) @@ -31,24 +27,4 @@ public class PlannerAgentHook : AgentHookBase return true; } - - public override void OnAgentLoaded(Agent agent) - { - var utilityLoad = new AgentUtility - { - Name = UtilityName.TwoStagePlanner, - Functions = [ - new(PRIMARY_STAGE_FN), - new(SECONDARY_STAGE_FN), - new(SUMMARY_FN) - ], - Templates = [ - new($"{PRIMARY_STAGE_FN}.fn"), - new($"{SECONDARY_STAGE_FN}.fn"), - new($"{SUMMARY_FN}.fn") - ] - }; - - base.OnAgentLoaded(agent); - } } diff --git a/src/Plugins/BotSharp.Plugin.Planner/Hooks/PlannerUtilityHook.cs b/src/Plugins/BotSharp.Plugin.Planner/Hooks/PlannerUtilityHook.cs index 08d3f8f5..b10d02ac 100644 --- a/src/Plugins/BotSharp.Plugin.Planner/Hooks/PlannerUtilityHook.cs +++ b/src/Plugins/BotSharp.Plugin.Planner/Hooks/PlannerUtilityHook.cs @@ -2,8 +2,27 @@ namespace BotSharp.Plugin.Planner.Hooks; public class PlannerUtilityHook : IAgentUtilityHook { - public void AddUtilities(List utilities) + private const string PRIMARY_STAGE_FN = "plan_primary_stage"; + private const string SECONDARY_STAGE_FN = "plan_secondary_stage"; + private const string SUMMARY_FN = "plan_summary"; + + public void AddUtilities(List utilities) { - utilities.Add(UtilityName.TwoStagePlanner); + var utility = new AgentUtility + { + Name = UtilityName.TwoStagePlanner, + Functions = [ + new(PRIMARY_STAGE_FN), + new(SECONDARY_STAGE_FN), + new(SUMMARY_FN) + ], + Templates = [ + new($"{PRIMARY_STAGE_FN}.fn"), + new($"{SECONDARY_STAGE_FN}.fn"), + new($"{SUMMARY_FN}.fn") + ] + }; + + utilities.Add(utility); } } diff --git a/src/Plugins/BotSharp.Plugin.PythonInterpreter/Hooks/InterpreterAgentHook.cs b/src/Plugins/BotSharp.Plugin.PythonInterpreter/Hooks/InterpreterAgentHook.cs deleted file mode 100644 index 64e0ec27..00000000 --- a/src/Plugins/BotSharp.Plugin.PythonInterpreter/Hooks/InterpreterAgentHook.cs +++ /dev/null @@ -1,51 +0,0 @@ -namespace BotSharp.Plugin.PythonInterpreter.Hooks; - -public class InterpreterAgentHook : AgentHookBase -{ - private static string FUNCTION_NAME = "python_interpreter"; - - public override string SelfId => string.Empty; - - public InterpreterAgentHook(IServiceProvider services, AgentSettings settings) - : base(services, settings) - { - } - public override void OnAgentLoaded(Agent agent) - { - var conv = _services.GetRequiredService(); - var isConvMode = conv.IsConversationMode(); - var isEnabled = !agent.Utilities.IsNullOrEmpty() && agent.Utilities.Contains(UtilityName.PythonInterpreter); - - if (isConvMode && isEnabled) - { - var (prompt, fn) = GetPromptAndFunction(); - if (fn != null) - { - if (!string.IsNullOrWhiteSpace(prompt)) - { - agent.Instruction += $"\r\n\r\n{prompt}\r\n\r\n"; - } - - if (agent.Functions == null) - { - agent.Functions = new List { fn }; - } - else - { - agent.Functions.Add(fn); - } - } - } - - base.OnAgentLoaded(agent); - } - - private (string, FunctionDef?) GetPromptAndFunction() - { - var db = _services.GetRequiredService(); - var agent = db.GetAgent(BuiltInAgentId.UtilityAssistant); - var prompt = agent?.Templates?.FirstOrDefault(x => x.Name.IsEqualTo($"{FUNCTION_NAME}.fn"))?.Content ?? string.Empty; - var loadAttachmentFn = agent?.Functions?.FirstOrDefault(x => x.Name.IsEqualTo(FUNCTION_NAME)); - return (prompt, loadAttachmentFn); - } -} diff --git a/src/Plugins/BotSharp.Plugin.PythonInterpreter/Hooks/InterpreterUtilityHook.cs b/src/Plugins/BotSharp.Plugin.PythonInterpreter/Hooks/InterpreterUtilityHook.cs index be37bfa1..540870be 100644 --- a/src/Plugins/BotSharp.Plugin.PythonInterpreter/Hooks/InterpreterUtilityHook.cs +++ b/src/Plugins/BotSharp.Plugin.PythonInterpreter/Hooks/InterpreterUtilityHook.cs @@ -2,8 +2,17 @@ namespace BotSharp.Plugin.PythonInterpreter.Hooks; public class InterpreterUtilityHook : IAgentUtilityHook { - public void AddUtilities(List utilities) + private static string FUNCTION_NAME = "python_interpreter"; + + public void AddUtilities(List utilities) { - utilities.Add(UtilityName.PythonInterpreter); + var utility = new AgentUtility() + { + Name = UtilityName.PythonInterpreter, + Functions = [new(FUNCTION_NAME)], + Templates = [new($"{FUNCTION_NAME}.fn")] + }; + + utilities.Add(utility); } } diff --git a/src/Plugins/BotSharp.Plugin.PythonInterpreter/InterpreterPlugin.cs b/src/Plugins/BotSharp.Plugin.PythonInterpreter/InterpreterPlugin.cs index be2e7c06..7d195286 100644 --- a/src/Plugins/BotSharp.Plugin.PythonInterpreter/InterpreterPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.PythonInterpreter/InterpreterPlugin.cs @@ -15,7 +15,6 @@ public class InterpreterPlugin : IBotSharpAppPlugin public void RegisterDI(IServiceCollection services, IConfiguration config) { - services.AddScoped(); services.AddScoped(); } diff --git a/src/Plugins/BotSharp.Plugin.SqlDriver/Hooks/SqlDriverAgentHook.cs b/src/Plugins/BotSharp.Plugin.SqlDriver/Hooks/SqlDriverAgentHook.cs deleted file mode 100644 index c64e70f0..00000000 --- a/src/Plugins/BotSharp.Plugin.SqlDriver/Hooks/SqlDriverAgentHook.cs +++ /dev/null @@ -1,48 +0,0 @@ -using BotSharp.Abstraction.Agents.Enums; -using BotSharp.Abstraction.Agents.Settings; - -namespace BotSharp.Plugin.SqlDriver.Hooks; - -public class SqlDriverAgentHook : AgentHookBase, IAgentHook -{ - private const string SQL_TABLE_DEFINITION_FN = "sql_table_definition"; - private const string VERIFY_DICTIONARY_TERM_FN = "verify_dictionary_term"; - private const string SQL_SELECT_FN = "sql_select"; - - public override string SelfId => BuiltInAgentId.Planner; - - public SqlDriverAgentHook(IServiceProvider services, AgentSettings settings) - : base(services, settings) - { - } - - public override void OnAgentLoaded(Agent agent) - { - var dbType = SqlDriverHelper.GetDatabaseType(_services); - agent.TemplateDict["db_type"] = dbType; - - var utilityLoads = new List - { - new AgentUtility - { - Name = UtilityName.SqlTableDefinition, - Functions = [new(SQL_TABLE_DEFINITION_FN)], - Templates = [new($"{SQL_TABLE_DEFINITION_FN}.fn")] - }, - new AgentUtility - { - Name = UtilityName.SqlDictionaryLookup, - Functions = [new(VERIFY_DICTIONARY_TERM_FN)], - Templates = [new($"{VERIFY_DICTIONARY_TERM_FN}.fn")] - }, - new AgentUtility - { - Name = UtilityName.SqlExecutor, - Functions = new List { new(SQL_SELECT_FN), new(SQL_TABLE_DEFINITION_FN) }, - Templates = new List { new($"sql_executor.fn") } - } - }; - - base.OnAgentLoaded(agent); - } -} diff --git a/src/Plugins/BotSharp.Plugin.SqlDriver/Hooks/SqlUtilityHook.cs b/src/Plugins/BotSharp.Plugin.SqlDriver/Hooks/SqlUtilityHook.cs index 451863ff..566ac319 100644 --- a/src/Plugins/BotSharp.Plugin.SqlDriver/Hooks/SqlUtilityHook.cs +++ b/src/Plugins/BotSharp.Plugin.SqlDriver/Hooks/SqlUtilityHook.cs @@ -2,10 +2,34 @@ namespace BotSharp.Plugin.SqlDriver.Hooks; public class SqlUtilityHook : IAgentUtilityHook { - public void AddUtilities(List utilities) + private const string SQL_TABLE_DEFINITION_FN = "sql_table_definition"; + private const string VERIFY_DICTIONARY_TERM_FN = "verify_dictionary_term"; + private const string SQL_SELECT_FN = "sql_select"; + + public void AddUtilities(List utilities) { - utilities.Add(UtilityName.SqlExecutor); - utilities.Add(UtilityName.SqlDictionaryLookup); - utilities.Add(UtilityName.SqlTableDefinition); + var items = new List + { + new AgentUtility + { + Name = UtilityName.SqlTableDefinition, + Functions = [new(SQL_TABLE_DEFINITION_FN)], + Templates = [new($"{SQL_TABLE_DEFINITION_FN}.fn")] + }, + new AgentUtility + { + Name = UtilityName.SqlDictionaryLookup, + Functions = [new(VERIFY_DICTIONARY_TERM_FN)], + Templates = [new($"{VERIFY_DICTIONARY_TERM_FN}.fn")] + }, + new AgentUtility + { + Name = UtilityName.SqlExecutor, + Functions = new List { new(SQL_SELECT_FN), new(SQL_TABLE_DEFINITION_FN) }, + Templates = new List { new($"sql_executor.fn") } + } + }; + + utilities.AddRange(items); } } diff --git a/src/Plugins/BotSharp.Plugin.SqlDriver/SqlDriverPlugin.cs b/src/Plugins/BotSharp.Plugin.SqlDriver/SqlDriverPlugin.cs index 8e21d2b0..6a618e34 100644 --- a/src/Plugins/BotSharp.Plugin.SqlDriver/SqlDriverPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.SqlDriver/SqlDriverPlugin.cs @@ -25,7 +25,6 @@ public class SqlDriverPlugin : IBotSharpPlugin services.AddScoped(); services.AddScoped(); - services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Hooks/OutboundPhoneCallHandlerHook.cs b/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Hooks/OutboundPhoneCallHandlerHook.cs deleted file mode 100644 index 84f0d387..00000000 --- a/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Hooks/OutboundPhoneCallHandlerHook.cs +++ /dev/null @@ -1,29 +0,0 @@ -using BotSharp.Abstraction.Agents.Models; -using BotSharp.Abstraction.Agents.Settings; -using BotSharp.Plugin.Twilio.OutboundPhoneCallHandler.Enums; - -namespace BotSharp.Plugin.Twilio.OutboundPhoneCallHandler.Hooks -{ - internal class OutboundPhoneCallHandlerHook : AgentHookBase - { - private static string OUTBOUND_PHONE_CALL_FN = "twilio_outbound_phone_call"; - - public override string SelfId => string.Empty; - - public OutboundPhoneCallHandlerHook(IServiceProvider services, AgentSettings settings) : base(services, settings) - { - } - - public override void OnAgentLoaded(Agent agent) - { - var utilityLoad = new AgentUtility - { - Name = UtilityName.OutboundPhoneCall, - Functions = [new(OUTBOUND_PHONE_CALL_FN)], - Templates = [new($"{OUTBOUND_PHONE_CALL_FN}.fn")] - }; - - base.OnAgentLoaded(agent); - } - } -} diff --git a/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Hooks/OutboundPhoneCallHandlerUtilityHook.cs b/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Hooks/OutboundPhoneCallHandlerUtilityHook.cs index 982fe9b1..09e8a9e4 100644 --- a/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Hooks/OutboundPhoneCallHandlerUtilityHook.cs +++ b/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Hooks/OutboundPhoneCallHandlerUtilityHook.cs @@ -1,12 +1,21 @@ +using BotSharp.Abstraction.Agents.Models; using BotSharp.Plugin.Twilio.OutboundPhoneCallHandler.Enums; -namespace BotSharp.Plugin.Twilio.OutboundPhoneCallHandler.Hooks +namespace BotSharp.Plugin.Twilio.OutboundPhoneCallHandler.Hooks; + +public class OutboundPhoneCallHandlerUtilityHook : IAgentUtilityHook { - public class OutboundPhoneCallHandlerUtilityHook : IAgentUtilityHook + private static string OUTBOUND_PHONE_CALL_FN = "twilio_outbound_phone_call"; + + public void AddUtilities(List utilities) { - public void AddUtilities(List utilities) + var utility = new AgentUtility { - utilities.Add(UtilityName.OutboundPhoneCall); - } + Name = UtilityName.OutboundPhoneCall, + Functions = [new(OUTBOUND_PHONE_CALL_FN)], + Templates = [new($"{OUTBOUND_PHONE_CALL_FN}.fn")] + }; + + utilities.Add(utility); } } diff --git a/src/Plugins/BotSharp.Plugin.Twilio/TwilioPlugin.cs b/src/Plugins/BotSharp.Plugin.Twilio/TwilioPlugin.cs index 2907276c..cd75cc14 100644 --- a/src/Plugins/BotSharp.Plugin.Twilio/TwilioPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.Twilio/TwilioPlugin.cs @@ -30,7 +30,6 @@ public class TwilioPlugin : IBotSharpPlugin services.AddSingleton(); services.AddHostedService(); services.AddTwilioRequestValidation(); - services.AddScoped(); services.AddScoped(); } }