From 67fd6f79fd1079b32073b8aa528406dc83fde859 Mon Sep 17 00:00:00 2001 From: Haiping Chen <101423@smsassist.com> Date: Mon, 29 Jan 2024 12:08:49 -0600 Subject: [PATCH] Allow agent to inherit from other agent. --- .../Agents/Models/Agent.cs | 11 ++- .../Plugins/PluginDependencyAttribute.cs | 11 +++ .../Routing/Models/RoutingRule.cs | 2 +- .../{ => Routing}/Planning/IExecutor.cs | 5 +- .../{ => Routing}/Planning/IPlaner.cs | 2 +- .../Agents/Services/AgentService.LoadAgent.cs | 21 +++++ .../BotSharp.Core/BotSharp.Core.csproj | 4 +- .../Conversations/ConversationPlugin.cs | 4 +- .../Infrastructures/LlmProviderPlugin.cs | 3 +- .../Instructs/InstructService.cs | 8 ++ .../BotSharp.Core/Plugins/PluginLoader.cs | 82 ++++++++++++++----- .../FileRepository/FileRepository.cs | 4 +- .../ContinueExecuteTaskRoutingHandler.cs | 2 +- .../InterruptTaskExecutionRoutingHandler.cs | 2 +- .../RetrieveDataFromAgentRoutingHandler.cs | 2 +- .../Routing/Handlers/TaskEndRoutingHandler.cs | 2 +- .../{ => Routing}/Planning/HFPlanner.cs | 4 +- .../Planning/InstructExecutor.cs | 4 +- .../{ => Routing}/Planning/NaivePlanner.cs | 14 ++-- .../Planning/SequentialPlanner.cs | 6 +- .../BotSharp.Core/Routing/RoutingPlugin.cs | 3 +- .../Routing/RoutingService.GetPlanner.cs | 4 +- .../BotSharp.Core/Routing/RoutingService.cs | 2 +- .../agent.json | 2 +- .../{welcome.liquid => .welcome.liquid} | 0 .../planner_prompt.sequential.liquid | 2 +- .../Controllers/PluginController.cs | 8 +- .../Providers/ChatCompletionProvider.cs | 4 +- .../Hooks/ChatHubConversationHook.cs | 2 +- .../agent.json | 14 +--- src/WebStarter/appsettings.json | 3 +- 31 files changed, 160 insertions(+), 77 deletions(-) create mode 100644 src/Infrastructure/BotSharp.Abstraction/Plugins/PluginDependencyAttribute.cs rename src/Infrastructure/BotSharp.Abstraction/{ => Routing}/Planning/IExecutor.cs (57%) rename src/Infrastructure/BotSharp.Abstraction/{ => Routing}/Planning/IPlaner.cs (90%) rename src/Infrastructure/BotSharp.Core/{ => Routing}/Planning/HFPlanner.cs (97%) rename src/Infrastructure/BotSharp.Core/{ => Routing}/Planning/InstructExecutor.cs (92%) rename src/Infrastructure/BotSharp.Core/{ => Routing}/Planning/NaivePlanner.cs (96%) rename src/Infrastructure/BotSharp.Core/{ => Routing}/Planning/SequentialPlanner.cs (97%) rename src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/{welcome.liquid => .welcome.liquid} (100%) diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs index 6b18b652..68e636b8 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs @@ -33,7 +33,8 @@ public class Agent /// Templates /// [JsonIgnore] - public List? Templates { get; set; } + public List Templates { get; set; } + = new List(); /// /// Samples @@ -46,7 +47,8 @@ public class Agent /// Functions /// [JsonIgnore] - public List Functions { get; set; } = new List(); + public List Functions { get; set; } + = new List(); /// /// Responses @@ -80,6 +82,11 @@ public class Agent public List Profiles { get; set; } = new List(); + /// + /// Inherit from agent + /// + public string? InheritAgentId { get; set; } + public List RoutingRules { get; set; } = new List(); diff --git a/src/Infrastructure/BotSharp.Abstraction/Plugins/PluginDependencyAttribute.cs b/src/Infrastructure/BotSharp.Abstraction/Plugins/PluginDependencyAttribute.cs new file mode 100644 index 00000000..7b5e93cb --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Plugins/PluginDependencyAttribute.cs @@ -0,0 +1,11 @@ +namespace BotSharp.Abstraction.Plugins; + +public class PluginDependencyAttribute : Attribute +{ + public string[] PluginNames { get; set; } + + public PluginDependencyAttribute(params string[] pluginNames) + { + PluginNames = pluginNames; + } +} diff --git a/src/Infrastructure/BotSharp.Abstraction/Routing/Models/RoutingRule.cs b/src/Infrastructure/BotSharp.Abstraction/Routing/Models/RoutingRule.cs index b652ced1..b0353ce6 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Routing/Models/RoutingRule.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Routing/Models/RoutingRule.cs @@ -26,7 +26,7 @@ public class RoutingRule public override string ToString() { - return $"{AgentName} {Field}"; + return $"{Type} {AgentName} {Field}"; } public RoutingRule() diff --git a/src/Infrastructure/BotSharp.Abstraction/Planning/IExecutor.cs b/src/Infrastructure/BotSharp.Abstraction/Routing/Planning/IExecutor.cs similarity index 57% rename from src/Infrastructure/BotSharp.Abstraction/Planning/IExecutor.cs rename to src/Infrastructure/BotSharp.Abstraction/Routing/Planning/IExecutor.cs index 187fcfcc..c8bffe6c 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Planning/IExecutor.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Routing/Planning/IExecutor.cs @@ -1,11 +1,10 @@ using BotSharp.Abstraction.Functions.Models; -using BotSharp.Abstraction.Routing; -namespace BotSharp.Abstraction.Planning; +namespace BotSharp.Abstraction.Routing.Planning; public interface IExecutor { - Task Execute(IRoutingService routing, + Task Execute(IRoutingService routing, FunctionCallFromLlm inst, RoleDialogModel message, List dialogs); diff --git a/src/Infrastructure/BotSharp.Abstraction/Planning/IPlaner.cs b/src/Infrastructure/BotSharp.Abstraction/Routing/Planning/IPlaner.cs similarity index 90% rename from src/Infrastructure/BotSharp.Abstraction/Planning/IPlaner.cs rename to src/Infrastructure/BotSharp.Abstraction/Routing/Planning/IPlaner.cs index a6136ea8..4053f81c 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Planning/IPlaner.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Routing/Planning/IPlaner.cs @@ -1,6 +1,6 @@ using BotSharp.Abstraction.Functions.Models; -namespace BotSharp.Abstraction.Planning; +namespace BotSharp.Abstraction.Routing.Planning; /// /// Task breakdown and execution plan diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs index ab40b134..a6910603 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs @@ -32,6 +32,27 @@ public partial class AgentService throw new Exception($"Can't load agent by id: {id}"); } + if (agent.InheritAgentId != null) + { + var inheritedAgent = await GetAgent(agent.InheritAgentId); + agent.Templates.AddRange(inheritedAgent.Templates + // exclude private template + .Where(x => !x.Name.StartsWith(".")) + // exclude duplicate name + .Where(x => !agent.Templates.Exists(t => t.Name == x.Name))); + + agent.Functions.AddRange(inheritedAgent.Functions + // exclude private template + .Where(x => !x.Name.StartsWith(".")) + // exclude duplicate name + .Where(x => !agent.Functions.Exists(t => t.Name == x.Name))); + + if (agent.Instruction == null) + { + agent.Instruction = inheritedAgent.Instruction; + } + } + agent.TemplateDict = new Dictionary(); // Populate state into dictionary diff --git a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj index 8f706a7b..8e79687f 100644 --- a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj +++ b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj @@ -50,11 +50,11 @@ + - @@ -87,7 +87,7 @@ PreserveNewest - + PreserveNewest diff --git a/src/Infrastructure/BotSharp.Core/Conversations/ConversationPlugin.cs b/src/Infrastructure/BotSharp.Core/Conversations/ConversationPlugin.cs index 00d55555..13885fec 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/ConversationPlugin.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/ConversationPlugin.cs @@ -1,12 +1,12 @@ using BotSharp.Abstraction.Instructs; using BotSharp.Abstraction.Messaging; -using BotSharp.Abstraction.Planning; using BotSharp.Abstraction.Plugins.Models; +using BotSharp.Abstraction.Routing.Planning; using BotSharp.Abstraction.Settings; using BotSharp.Abstraction.Templating; using BotSharp.Core.Instructs; using BotSharp.Core.Messaging; -using BotSharp.Core.Planning; +using BotSharp.Core.Routing.Planning; using BotSharp.Core.Templating; using Microsoft.Extensions.Configuration; diff --git a/src/Infrastructure/BotSharp.Core/Infrastructures/LlmProviderPlugin.cs b/src/Infrastructure/BotSharp.Core/Infrastructures/LlmProviderPlugin.cs index 469447a2..74f1aa83 100644 --- a/src/Infrastructure/BotSharp.Core/Infrastructures/LlmProviderPlugin.cs +++ b/src/Infrastructure/BotSharp.Core/Infrastructures/LlmProviderPlugin.cs @@ -21,10 +21,11 @@ public class LlmProviderPlugin : IBotSharpPlugin services.AddScoped(provider => { var settingService = provider.GetRequiredService(); + var loger = provider.GetRequiredService>(); var llmProviders = settingService.Bind>("LlmProviders"); foreach (var llmProvider in llmProviders) { - Console.WriteLine($"Loaded LlmProvider {llmProvider.Provider} settings with {llmProvider.Models.Count} models."); + loger.LogInformation($"Loaded LlmProvider {llmProvider.Provider} settings with {llmProvider.Models.Count} models."); } return llmProviders; }); diff --git a/src/Infrastructure/BotSharp.Core/Instructs/InstructService.cs b/src/Infrastructure/BotSharp.Core/Instructs/InstructService.cs index ccab8874..d8a9a1bb 100644 --- a/src/Infrastructure/BotSharp.Core/Instructs/InstructService.cs +++ b/src/Infrastructure/BotSharp.Core/Instructs/InstructService.cs @@ -16,6 +16,14 @@ public partial class InstructService : IInstructService _logger = logger; } + /// + /// Execute completion by using specified instruction or template + /// + /// Agent (static agent) + /// Additional message provided by user + /// Template name + /// System prompt + /// public async Task Execute(string agentId, RoleDialogModel message, string? templateName = null, string? instruction = null) { var agentService = _services.GetRequiredService(); diff --git a/src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs b/src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs index 0d54f4af..0932041d 100644 --- a/src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs +++ b/src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs @@ -27,12 +27,17 @@ public class PluginLoader _settings = settings; } - public void Load(Action loaded) + public void Load(Action loaded, string? plugin = null) { _executingDir = Directory.GetParent(Assembly.GetEntryAssembly().Location).FullName; _settings.Assemblies.ToList().ForEach(assemblyName => { + if (plugin != null && plugin != assemblyName) + { + return; + } + var assemblyPath = Path.Combine(_executingDir, assemblyName + ".dll"); if (File.Exists(assemblyPath)) { @@ -45,38 +50,66 @@ public class PluginLoader foreach (var module in modules) { - module.RegisterDI(_services, _config); - // string classSummary = GetSummaryComment(module.GetType()); - var name = string.IsNullOrEmpty(module.Name) ? module.GetType().Name : module.Name; - _modules.Add(module); - _plugins.Add(new PluginDef + if (_plugins.Exists(x => x.Id == module.Id)) { - Id = module.Id, - Name = name, - Module = module, - Description = module.Description, - Assembly = assemblyName, - IconUrl = module.IconUrl, - AgentIds = module.AgentIds - }); - Console.Write($"Loaded plugin "); - Console.Write(name, Color.Green); - Console.WriteLine($" from {assemblyName}."); - if (!string.IsNullOrEmpty(module.Description)) - { - Console.WriteLine(module.Description); + continue; } + + // Solve plugin dependency + var attr = module.GetType().GetCustomAttribute(); + if (attr != null) + { + foreach (var plugin in attr.PluginNames) + { + if (!_plugins.Any(x => x.Assembly == plugin)) + { + Load(loaded, plugin); + } + + if (!_plugins.Any(x => x.Assembly == plugin)) + { + Console.WriteLine($"Load dependent plugin {plugin} failed by {module.Name}.", Color.Red); + } + } + } + + InitModule(assemblyName, module); } loaded(assembly); } else { - Console.WriteLine($"Can't find assemble {assemblyPath}."); + Console.WriteLine($"Can't find assemble {assemblyPath}.", Color.Red); } }); } + private void InitModule(string assembly, IBotSharpPlugin module) + { + module.RegisterDI(_services, _config); + // string classSummary = GetSummaryComment(module.GetType()); + var name = string.IsNullOrEmpty(module.Name) ? module.GetType().Name : module.Name; + _modules.Add(module); + _plugins.Add(new PluginDef + { + Id = module.Id, + Name = name, + Module = module, + Description = module.Description, + Assembly = assembly, + IconUrl = module.IconUrl, + AgentIds = module.AgentIds + }); + Console.Write($"Loaded plugin "); + Console.Write(name, Color.Green); + Console.WriteLine($" from {assembly}."); + if (!string.IsNullOrEmpty(module.Description)) + { + Console.WriteLine(module.Description); + } + } + public List GetPlugins(IServiceProvider services) { // Apply user configurations @@ -124,6 +157,13 @@ public class PluginLoader var agent = agentService.LoadAgent(agentId).Result; agent.Disabled = false; agentService.UpdateAgent(agent, AgentField.Disabled); + + if (agent.InheritAgentId != null) + { + agent = agentService.LoadAgent(agent.InheritAgentId).Result; + agent.Disabled = false; + agentService.UpdateAgent(agent, AgentField.Disabled); + } } } else diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs index 6874ed02..2fca2321 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs @@ -176,10 +176,10 @@ public partial class FileRepository : IBotSharpRepository return (agent, agentFile); } - private string FetchInstruction(string fileDir) + private string? FetchInstruction(string fileDir) { var file = Path.Combine(fileDir, $"{AGENT_INSTRUCTION_FILE}.{_agentSettings.TemplateFormat}"); - if (!File.Exists(file)) return string.Empty; + if (!File.Exists(file)) return null; var instruction = File.ReadAllText(file); return instruction; diff --git a/src/Infrastructure/BotSharp.Core/Routing/Handlers/ContinueExecuteTaskRoutingHandler.cs b/src/Infrastructure/BotSharp.Core/Routing/Handlers/ContinueExecuteTaskRoutingHandler.cs index 66fe6759..646dd481 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Handlers/ContinueExecuteTaskRoutingHandler.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Handlers/ContinueExecuteTaskRoutingHandler.cs @@ -4,7 +4,7 @@ using BotSharp.Abstraction.Repositories; using BotSharp.Abstraction.Repositories.Filters; using BotSharp.Abstraction.Routing; using BotSharp.Abstraction.Routing.Settings; -using BotSharp.Core.Planning; +using BotSharp.Core.Routing.Planning; namespace BotSharp.Core.Routing.Handlers; diff --git a/src/Infrastructure/BotSharp.Core/Routing/Handlers/InterruptTaskExecutionRoutingHandler.cs b/src/Infrastructure/BotSharp.Core/Routing/Handlers/InterruptTaskExecutionRoutingHandler.cs index 00068306..da58b98b 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Handlers/InterruptTaskExecutionRoutingHandler.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Handlers/InterruptTaskExecutionRoutingHandler.cs @@ -1,7 +1,7 @@ using BotSharp.Abstraction.Functions.Models; using BotSharp.Abstraction.Routing; using BotSharp.Abstraction.Routing.Settings; -using BotSharp.Core.Planning; +using BotSharp.Core.Routing.Planning; namespace BotSharp.Core.Routing.Handlers; diff --git a/src/Infrastructure/BotSharp.Core/Routing/Handlers/RetrieveDataFromAgentRoutingHandler.cs b/src/Infrastructure/BotSharp.Core/Routing/Handlers/RetrieveDataFromAgentRoutingHandler.cs index 3e397089..54f3e66c 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Handlers/RetrieveDataFromAgentRoutingHandler.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Handlers/RetrieveDataFromAgentRoutingHandler.cs @@ -2,7 +2,7 @@ using BotSharp.Abstraction.Functions.Models; using BotSharp.Abstraction.Routing; using BotSharp.Abstraction.Routing.Models; using BotSharp.Abstraction.Routing.Settings; -using BotSharp.Core.Planning; +using BotSharp.Core.Routing.Planning; namespace BotSharp.Core.Routing.Handlers; diff --git a/src/Infrastructure/BotSharp.Core/Routing/Handlers/TaskEndRoutingHandler.cs b/src/Infrastructure/BotSharp.Core/Routing/Handlers/TaskEndRoutingHandler.cs index 0b299f25..5e431f84 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Handlers/TaskEndRoutingHandler.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Handlers/TaskEndRoutingHandler.cs @@ -1,7 +1,7 @@ using BotSharp.Abstraction.Functions.Models; using BotSharp.Abstraction.Routing; using BotSharp.Abstraction.Routing.Settings; -using BotSharp.Core.Planning; +using BotSharp.Core.Routing.Planning; namespace BotSharp.Core.Routing.Handlers; diff --git a/src/Infrastructure/BotSharp.Core/Planning/HFPlanner.cs b/src/Infrastructure/BotSharp.Core/Routing/Planning/HFPlanner.cs similarity index 97% rename from src/Infrastructure/BotSharp.Core/Planning/HFPlanner.cs rename to src/Infrastructure/BotSharp.Core/Routing/Planning/HFPlanner.cs index 8f4e0033..9cff003a 100644 --- a/src/Infrastructure/BotSharp.Core/Planning/HFPlanner.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Planning/HFPlanner.cs @@ -1,12 +1,12 @@ using BotSharp.Abstraction.Agents.Models; using BotSharp.Abstraction.Functions.Models; -using BotSharp.Abstraction.Planning; using BotSharp.Abstraction.Repositories; using BotSharp.Abstraction.Repositories.Filters; using BotSharp.Abstraction.Routing.Models; +using BotSharp.Abstraction.Routing.Planning; using BotSharp.Abstraction.Templating; -namespace BotSharp.Core.Planning; +namespace BotSharp.Core.Routing.Planning; /// /// Human feedback based planner diff --git a/src/Infrastructure/BotSharp.Core/Planning/InstructExecutor.cs b/src/Infrastructure/BotSharp.Core/Routing/Planning/InstructExecutor.cs similarity index 92% rename from src/Infrastructure/BotSharp.Core/Planning/InstructExecutor.cs rename to src/Infrastructure/BotSharp.Core/Routing/Planning/InstructExecutor.cs index 0d02cd95..0f436edd 100644 --- a/src/Infrastructure/BotSharp.Core/Planning/InstructExecutor.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Planning/InstructExecutor.cs @@ -1,8 +1,8 @@ using BotSharp.Abstraction.Functions.Models; -using BotSharp.Abstraction.Planning; using BotSharp.Abstraction.Routing; +using BotSharp.Abstraction.Routing.Planning; -namespace BotSharp.Core.Planning; +namespace BotSharp.Core.Routing.Planning; public class InstructExecutor : IExecutor { diff --git a/src/Infrastructure/BotSharp.Core/Planning/NaivePlanner.cs b/src/Infrastructure/BotSharp.Core/Routing/Planning/NaivePlanner.cs similarity index 96% rename from src/Infrastructure/BotSharp.Core/Planning/NaivePlanner.cs rename to src/Infrastructure/BotSharp.Core/Routing/Planning/NaivePlanner.cs index 78112559..fa4b20a0 100644 --- a/src/Infrastructure/BotSharp.Core/Planning/NaivePlanner.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Planning/NaivePlanner.cs @@ -1,11 +1,11 @@ using BotSharp.Abstraction.Agents.Models; using BotSharp.Abstraction.Functions.Models; -using BotSharp.Abstraction.Planning; using BotSharp.Abstraction.Repositories.Filters; using BotSharp.Abstraction.Routing.Models; +using BotSharp.Abstraction.Routing.Planning; using BotSharp.Abstraction.Templating; -namespace BotSharp.Core.Planning; +namespace BotSharp.Core.Routing.Planning; public class NaivePlanner : IPlaner { @@ -32,7 +32,7 @@ public class NaivePlanner : IPlaner var completion = CompletionProvider.GetTextCompletion(_services);*/ // chat completion - var completion = CompletionProvider.GetChatCompletion(_services, + var completion = CompletionProvider.GetChatCompletion(_services, provider: router?.LlmConfig?.Provider, model: router?.LlmConfig?.Model); @@ -44,7 +44,7 @@ public class NaivePlanner : IPlaner { // text completion // text = await completion.GetCompletion(content, router.Id, messageId); - var dialogs = new List + var dialogs = new List { new RoleDialogModel(AgentRole.User, next) { @@ -91,7 +91,7 @@ public class NaivePlanner : IPlaner if (inst.UnmatchedAgent) { var unmatchedAgentId = context.GetCurrentAgentId(); - + // Exclude the wrong routed agent var agents = router.TemplateDict["routing_agents"] as RoutableAgent[]; router.TemplateDict["routing_agents"] = agents.Where(x => x.AgentId != unmatchedAgentId).ToArray(); @@ -123,8 +123,8 @@ public class NaivePlanner : IPlaner private void FixMalformedResponse(FunctionCallFromLlm args) { var agentService = _services.GetRequiredService(); - var agents = agentService.GetAgents(new AgentFilter - { + var agents = agentService.GetAgents(new AgentFilter + { Type = AgentType.Task }).Result.Items.ToList(); var malformed = false; diff --git a/src/Infrastructure/BotSharp.Core/Planning/SequentialPlanner.cs b/src/Infrastructure/BotSharp.Core/Routing/Planning/SequentialPlanner.cs similarity index 97% rename from src/Infrastructure/BotSharp.Core/Planning/SequentialPlanner.cs rename to src/Infrastructure/BotSharp.Core/Routing/Planning/SequentialPlanner.cs index 8f571266..1b24152a 100644 --- a/src/Infrastructure/BotSharp.Core/Planning/SequentialPlanner.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Planning/SequentialPlanner.cs @@ -1,11 +1,11 @@ using BotSharp.Abstraction.Agents.Models; using BotSharp.Abstraction.Functions.Models; -using BotSharp.Abstraction.Planning; using BotSharp.Abstraction.Routing; using BotSharp.Abstraction.Routing.Models; +using BotSharp.Abstraction.Routing.Planning; using BotSharp.Abstraction.Templating; -namespace BotSharp.Core.Planning; +namespace BotSharp.Core.Routing.Planning; public class SequentialPlanner : IPlaner { @@ -91,7 +91,7 @@ public class SequentialPlanner : IPlaner context.Empty(); return false; } - + // Handover to Router; context.Pop(); diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingPlugin.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingPlugin.cs index 946e6057..677157d6 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingPlugin.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingPlugin.cs @@ -1,10 +1,9 @@ -using BotSharp.Abstraction.Planning; using BotSharp.Abstraction.Routing; using BotSharp.Abstraction.Routing.Models; using BotSharp.Abstraction.Routing.Settings; using BotSharp.Abstraction.Settings; -using BotSharp.Core.Planning; using BotSharp.Core.Routing.Hooks; +using BotSharp.Core.Routing.Planning; using Microsoft.Extensions.Configuration; namespace BotSharp.Core.Routing; diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetPlanner.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetPlanner.cs index 01de9a29..2d47f1ab 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetPlanner.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetPlanner.cs @@ -1,7 +1,7 @@ using BotSharp.Abstraction.Agents.Models; -using BotSharp.Abstraction.Planning; using BotSharp.Abstraction.Routing.Enums; -using BotSharp.Core.Planning; +using BotSharp.Abstraction.Routing.Planning; +using BotSharp.Core.Routing.Planning; namespace BotSharp.Core.Routing; diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs index b94903af..8a34d684 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs @@ -1,10 +1,10 @@ using BotSharp.Abstraction.Agents.Models; using BotSharp.Abstraction.Functions.Models; -using BotSharp.Abstraction.Planning; using BotSharp.Abstraction.Repositories; using BotSharp.Abstraction.Repositories.Filters; using BotSharp.Abstraction.Routing; using BotSharp.Abstraction.Routing.Models; +using BotSharp.Abstraction.Routing.Planning; using BotSharp.Abstraction.Routing.Settings; using System.Drawing; diff --git a/src/Infrastructure/BotSharp.Core/data/agents/01e2fc5c-2c89-4ec7-8470-7688608b496c/agent.json b/src/Infrastructure/BotSharp.Core/data/agents/01e2fc5c-2c89-4ec7-8470-7688608b496c/agent.json index d75a4483..536ca340 100644 --- a/src/Infrastructure/BotSharp.Core/data/agents/01e2fc5c-2c89-4ec7-8470-7688608b496c/agent.json +++ b/src/Infrastructure/BotSharp.Core/data/agents/01e2fc5c-2c89-4ec7-8470-7688608b496c/agent.json @@ -1,7 +1,7 @@ { "id": "01e2fc5c-2c89-4ec7-8470-7688608b496c", "name": "Chatbot", - "description": "AI chatbot that can do variaty of tasks", + "description": "Chatbot is used to test the performance of different large models and does not interact with external APIs.", "type": "task", "createdDateTime": "2024-01-15T10:39:32Z", "updatedDateTime": "2024-01-15T14:39:32Z", diff --git a/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/welcome.liquid b/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/.welcome.liquid similarity index 100% rename from src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/welcome.liquid rename to src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/.welcome.liquid diff --git a/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/planner_prompt.sequential.liquid b/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/planner_prompt.sequential.liquid index a1025e50..32de085b 100644 --- a/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/planner_prompt.sequential.liquid +++ b/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/planner_prompt.sequential.liquid @@ -1,2 +1,2 @@ -In order to execute the instructions listed by the user in the order specified by the user. +In order to execute the listed instructions in the order specified by the user. What is the next step based on the CONVERSATION? \ No newline at end of file diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/PluginController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/PluginController.cs index 54cdae14..7feceadf 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/PluginController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/PluginController.cs @@ -54,15 +54,15 @@ public class PluginController : ControllerBase return menu; } - [HttpPost("/plugin/{id}/enable")] - public PluginDef EnablePlugin([FromRoute] string id) + [HttpPost("/plugin/{id}/install")] + public PluginDef InstallPlugin([FromRoute] string id) { var loader = _services.GetRequiredService(); return loader.UpdatePluginStatus(_services, id, true); } - [HttpPost("/plugin/{id}/disable")] - public PluginDef DisablePluginStats([FromRoute] string id) + [HttpPost("/plugin/{id}/remove")] + public PluginDef RemovePluginStats([FromRoute] string id) { var loader = _services.GetRequiredService(); return loader.UpdatePluginStatus(_services, id, false); diff --git a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs index bf563670..ca8d7e01 100644 --- a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs @@ -292,7 +292,9 @@ public class ChatCompletionProvider : IChatCompletion else if (x.Role == ChatRole.User) { var m = x as ChatRequestUserMessage; - return $"{m.Role}: {m.Content}"; + return !string.IsNullOrEmpty(m.Name) ? + $"{m.Name}: {m.Content}" : + $"{m.Role}: {m.Content}"; } else if (x.Role == ChatRole.Assistant) { diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs index bad8cf2b..8275daa7 100644 --- a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs +++ b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs @@ -36,7 +36,7 @@ public class ChatHubConversationHook : ConversationHookBase var agent = await agentService.LoadAgent(conversation.AgentId); // Check if the Welcome template exists. - var welcomeTemplate = agent.Templates?.FirstOrDefault(x => x.Name == "welcome"); + var welcomeTemplate = agent.Templates?.FirstOrDefault(x => x.Name == ".welcome"); if (welcomeTemplate != null) { var richContentService = _services.GetRequiredService(); diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/agent.json b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/agent.json index 290a88d0..2d928f12 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/agent.json +++ b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/agent.json @@ -1,19 +1,13 @@ { "id": "f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b", "name": "Web Driver", - "description": "Perform a specific action on a web browser", + "description": "Perform the web page related task in browser by using automation tools.", "type": "task", "createdDateTime": "2024-01-02T00:00:00Z", "updatedDateTime": "2024-01-02T00:00:00Z", "isPublic": true, - "profiles": [ "default" ], + "profiles": [ "web-driver" ], "llmConfig": { - "max_recursion_depth": 10 - }, - "routingRules": [ - { - "type": "fallback", - "redirectTo": "01e2fc5c-2c89-4ec7-8470-7688608b496c" - } - ] + "max_recursion_depth": 5 + } } \ No newline at end of file diff --git a/src/WebStarter/appsettings.json b/src/WebStarter/appsettings.json index 67952c9a..91bf2de7 100644 --- a/src/WebStarter/appsettings.json +++ b/src/WebStarter/appsettings.json @@ -161,8 +161,9 @@ "PluginLoader": { "Assemblies": [ - "BotSharp.Plugin.MongoStorage", "BotSharp.Core", + "BotSharp.Logger", + "BotSharp.Plugin.MongoStorage", "BotSharp.Plugin.AzureOpenAI", "BotSharp.Plugin.GoogleAI", "BotSharp.Plugin.MetaAI",