From 7f60133524f52eaeb51542e1236ed9913e4c58d4 Mon Sep 17 00:00:00 2001 From: Jicheng Lu Date: Tue, 9 Jul 2024 23:36:49 -0500 Subject: [PATCH] change utility assistant id --- .../Agents/Enums/BuiltInAgentId.cs | 1 + .../Agents/Services/AgentService.LoadAgent.cs | 4 +--- .../BotSharp.Core/BotSharp.Core.csproj | 24 +++++++++---------- .../Files/Functions/GenerateImageFn.cs | 3 +-- .../Files/Functions/ReadFileFn.cs | 3 +-- .../Files/Hooks/FileReaderHook.cs | 3 +-- .../Files/Hooks/ImageGeneratorHook.cs | 3 +-- .../agent.json | 2 +- .../functions/generate_image.json | 0 .../functions/read_file.json | 0 .../instruction.liquid | 0 .../templates/generate_image.fn.liquid | 0 .../templates/read_file.fn.liquid | 0 .../BotSharp.Plugin.HttpHandler.csproj | 8 +++---- .../Hooks/HttpHandlerHook.cs | 4 ++-- .../functions/handle_http_request.json | 0 .../templates/handle_http_request.fn.liquid | 0 17 files changed, 25 insertions(+), 30 deletions(-) rename src/Infrastructure/BotSharp.Core/data/agents/{00000000-0000-0000-0000-000000000000 => 6745151e-6d46-4a02-8de4-1c4f21c7da95}/agent.json (90%) rename src/Infrastructure/BotSharp.Core/data/agents/{00000000-0000-0000-0000-000000000000 => 6745151e-6d46-4a02-8de4-1c4f21c7da95}/functions/generate_image.json (100%) rename src/Infrastructure/BotSharp.Core/data/agents/{00000000-0000-0000-0000-000000000000 => 6745151e-6d46-4a02-8de4-1c4f21c7da95}/functions/read_file.json (100%) rename src/Infrastructure/BotSharp.Core/data/agents/{00000000-0000-0000-0000-000000000000 => 6745151e-6d46-4a02-8de4-1c4f21c7da95}/instruction.liquid (100%) rename src/Infrastructure/BotSharp.Core/data/agents/{00000000-0000-0000-0000-000000000000 => 6745151e-6d46-4a02-8de4-1c4f21c7da95}/templates/generate_image.fn.liquid (100%) rename src/Infrastructure/BotSharp.Core/data/agents/{00000000-0000-0000-0000-000000000000 => 6745151e-6d46-4a02-8de4-1c4f21c7da95}/templates/read_file.fn.liquid (100%) rename src/Plugins/BotSharp.Plugin.HttpHandler/data/agents/{00000000-0000-0000-0000-000000000000 => 6745151e-6d46-4a02-8de4-1c4f21c7da95}/functions/handle_http_request.json (100%) rename src/Plugins/BotSharp.Plugin.HttpHandler/data/agents/{00000000-0000-0000-0000-000000000000 => 6745151e-6d46-4a02-8de4-1c4f21c7da95}/templates/handle_http_request.fn.liquid (100%) diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Enums/BuiltInAgentId.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Enums/BuiltInAgentId.cs index 98aaf454..44493f9a 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Enums/BuiltInAgentId.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Enums/BuiltInAgentId.cs @@ -5,4 +5,5 @@ public class BuiltInAgentId public const string AIAssistant = "01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a"; public const string Chatbot = "01e2fc5c-2c89-4ec7-8470-7688608b496c"; public const string HumanSupport = "01dcc3e5-0af7-49e6-ad7a-a760bd12dc4b"; + public const string UtilityAssistant = "6745151e-6d46-4a02-8de4-1c4f21c7da95"; } diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs index e3f1774e..89c45510 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs @@ -1,5 +1,3 @@ -using BotSharp.Abstraction.Templating; - namespace BotSharp.Core.Agents.Services; public partial class AgentService @@ -7,7 +5,7 @@ public partial class AgentService [MemoryCache(10 * 60, perInstanceCache: true)] public async Task LoadAgent(string id) { - if (string.IsNullOrEmpty(id)) + if (string.IsNullOrEmpty(id) || id == Guid.Empty.ToString()) { return null; } diff --git a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj index 8f44be5c..da864c60 100644 --- a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj +++ b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj @@ -46,12 +46,12 @@ - - - - - - + + + + + + @@ -153,22 +153,22 @@ PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest diff --git a/src/Infrastructure/BotSharp.Core/Files/Functions/GenerateImageFn.cs b/src/Infrastructure/BotSharp.Core/Files/Functions/GenerateImageFn.cs index 18c34c12..c1e816e3 100644 --- a/src/Infrastructure/BotSharp.Core/Files/Functions/GenerateImageFn.cs +++ b/src/Infrastructure/BotSharp.Core/Files/Functions/GenerateImageFn.cs @@ -9,7 +9,6 @@ public class GenerateImageFn : IFunctionCallback private readonly IServiceProvider _services; private readonly ILogger _logger; - private static string UTILITY_ASSISTANT = Guid.Empty.ToString(); private string _conversationId; private string _messageId; @@ -29,7 +28,7 @@ public class GenerateImageFn : IFunctionCallback SetImageOptions(); var agentService = _services.GetRequiredService(); - var agent = await agentService.LoadAgent(UTILITY_ASSISTANT); + var agent = await agentService.LoadAgent(BuiltInAgentId.UtilityAssistant); var imageAgent = new Agent { Id = agent?.Id ?? Guid.Empty.ToString(), diff --git a/src/Infrastructure/BotSharp.Core/Files/Functions/ReadFileFn.cs b/src/Infrastructure/BotSharp.Core/Files/Functions/ReadFileFn.cs index a1bb50df..5aa75cd5 100644 --- a/src/Infrastructure/BotSharp.Core/Files/Functions/ReadFileFn.cs +++ b/src/Infrastructure/BotSharp.Core/Files/Functions/ReadFileFn.cs @@ -12,7 +12,6 @@ public class ReadFileFn : IFunctionCallback private readonly ILogger _logger; private readonly IEnumerable _imageTypes = new List { "image", "images", "png", "jpg", "jpeg" }; private readonly IEnumerable _pdfTypes = new List { "pdf" }; - private static string UTILITY_ASSISTANT = Guid.Empty.ToString(); public ReadFileFn( IServiceProvider services, @@ -31,7 +30,7 @@ public class ReadFileFn : IFunctionCallback var wholeDialogs = conv.GetDialogHistory(); var fileTypes = args?.FileTypes?.Split(",", StringSplitOptions.RemoveEmptyEntries)?.ToList() ?? new List(); var dialogs = await AssembleFiles(conv.ConversationId, wholeDialogs, fileTypes); - var agent = await agentService.LoadAgent(UTILITY_ASSISTANT); + var agent = await agentService.LoadAgent(BuiltInAgentId.UtilityAssistant); var fileAgent = new Agent { Id = agent?.Id ?? Guid.Empty.ToString(), diff --git a/src/Infrastructure/BotSharp.Core/Files/Hooks/FileReaderHook.cs b/src/Infrastructure/BotSharp.Core/Files/Hooks/FileReaderHook.cs index b9f57846..685148bb 100644 --- a/src/Infrastructure/BotSharp.Core/Files/Hooks/FileReaderHook.cs +++ b/src/Infrastructure/BotSharp.Core/Files/Hooks/FileReaderHook.cs @@ -2,7 +2,6 @@ namespace BotSharp.Core.Files.Hooks; public class FileReaderHook : AgentHookBase { - private static string UTILITY_ASSISTANT = Guid.Empty.ToString(); private static string FUNCTION_NAME = "read_file"; public override string SelfId => string.Empty; @@ -45,7 +44,7 @@ public class FileReaderHook : AgentHookBase private (string, FunctionDef?) GetPromptAndFunction() { var db = _services.GetRequiredService(); - var agent = db.GetAgent(UTILITY_ASSISTANT); + 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/Infrastructure/BotSharp.Core/Files/Hooks/ImageGeneratorHook.cs b/src/Infrastructure/BotSharp.Core/Files/Hooks/ImageGeneratorHook.cs index f3702b3e..dadba673 100644 --- a/src/Infrastructure/BotSharp.Core/Files/Hooks/ImageGeneratorHook.cs +++ b/src/Infrastructure/BotSharp.Core/Files/Hooks/ImageGeneratorHook.cs @@ -2,7 +2,6 @@ namespace BotSharp.Core.Files.Hooks; public class ImageGeneratorHook : AgentHookBase { - private static string UTILITY_ASSISTANT = Guid.Empty.ToString(); private static string FUNCTION_NAME = "generate_image"; public override string SelfId => string.Empty; @@ -45,7 +44,7 @@ public class ImageGeneratorHook : AgentHookBase private (string, FunctionDef?) GetPromptAndFunction() { var db = _services.GetRequiredService(); - var agent = db.GetAgent(UTILITY_ASSISTANT); + 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/Infrastructure/BotSharp.Core/data/agents/00000000-0000-0000-0000-000000000000/agent.json b/src/Infrastructure/BotSharp.Core/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/agent.json similarity index 90% rename from src/Infrastructure/BotSharp.Core/data/agents/00000000-0000-0000-0000-000000000000/agent.json rename to src/Infrastructure/BotSharp.Core/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/agent.json index c44219c1..ffbc26e4 100644 --- a/src/Infrastructure/BotSharp.Core/data/agents/00000000-0000-0000-0000-000000000000/agent.json +++ b/src/Infrastructure/BotSharp.Core/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/agent.json @@ -1,5 +1,5 @@ { - "id": "00000000-0000-0000-0000-000000000000", + "id": "6745151e-6d46-4a02-8de4-1c4f21c7da95", "name": "Utility Assistant", "description": "Utility assistant that can be used to complete many different tasks", "type": "static", diff --git a/src/Infrastructure/BotSharp.Core/data/agents/00000000-0000-0000-0000-000000000000/functions/generate_image.json b/src/Infrastructure/BotSharp.Core/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/generate_image.json similarity index 100% rename from src/Infrastructure/BotSharp.Core/data/agents/00000000-0000-0000-0000-000000000000/functions/generate_image.json rename to src/Infrastructure/BotSharp.Core/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/generate_image.json diff --git a/src/Infrastructure/BotSharp.Core/data/agents/00000000-0000-0000-0000-000000000000/functions/read_file.json b/src/Infrastructure/BotSharp.Core/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/read_file.json similarity index 100% rename from src/Infrastructure/BotSharp.Core/data/agents/00000000-0000-0000-0000-000000000000/functions/read_file.json rename to src/Infrastructure/BotSharp.Core/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/read_file.json diff --git a/src/Infrastructure/BotSharp.Core/data/agents/00000000-0000-0000-0000-000000000000/instruction.liquid b/src/Infrastructure/BotSharp.Core/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/instruction.liquid similarity index 100% rename from src/Infrastructure/BotSharp.Core/data/agents/00000000-0000-0000-0000-000000000000/instruction.liquid rename to src/Infrastructure/BotSharp.Core/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/instruction.liquid diff --git a/src/Infrastructure/BotSharp.Core/data/agents/00000000-0000-0000-0000-000000000000/templates/generate_image.fn.liquid b/src/Infrastructure/BotSharp.Core/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/generate_image.fn.liquid similarity index 100% rename from src/Infrastructure/BotSharp.Core/data/agents/00000000-0000-0000-0000-000000000000/templates/generate_image.fn.liquid rename to src/Infrastructure/BotSharp.Core/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/generate_image.fn.liquid diff --git a/src/Infrastructure/BotSharp.Core/data/agents/00000000-0000-0000-0000-000000000000/templates/read_file.fn.liquid b/src/Infrastructure/BotSharp.Core/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/read_file.fn.liquid similarity index 100% rename from src/Infrastructure/BotSharp.Core/data/agents/00000000-0000-0000-0000-000000000000/templates/read_file.fn.liquid rename to src/Infrastructure/BotSharp.Core/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/read_file.fn.liquid diff --git a/src/Plugins/BotSharp.Plugin.HttpHandler/BotSharp.Plugin.HttpHandler.csproj b/src/Plugins/BotSharp.Plugin.HttpHandler/BotSharp.Plugin.HttpHandler.csproj index 80293b4f..2911dc2b 100644 --- a/src/Plugins/BotSharp.Plugin.HttpHandler/BotSharp.Plugin.HttpHandler.csproj +++ b/src/Plugins/BotSharp.Plugin.HttpHandler/BotSharp.Plugin.HttpHandler.csproj @@ -11,8 +11,8 @@ - - + + @@ -25,10 +25,10 @@ PreserveNewest - + PreserveNewest - + PreserveNewest diff --git a/src/Plugins/BotSharp.Plugin.HttpHandler/Hooks/HttpHandlerHook.cs b/src/Plugins/BotSharp.Plugin.HttpHandler/Hooks/HttpHandlerHook.cs index 891ebc19..a5106380 100644 --- a/src/Plugins/BotSharp.Plugin.HttpHandler/Hooks/HttpHandlerHook.cs +++ b/src/Plugins/BotSharp.Plugin.HttpHandler/Hooks/HttpHandlerHook.cs @@ -1,4 +1,5 @@ using BotSharp.Abstraction.Agents; +using BotSharp.Abstraction.Agents.Enums; using BotSharp.Abstraction.Agents.Settings; using BotSharp.Abstraction.Functions.Models; using BotSharp.Abstraction.Repositories; @@ -8,7 +9,6 @@ namespace BotSharp.Plugin.HttpHandler.Hooks; public class HttpHandlerHook : AgentHookBase { - private static string UTILITY_ASSISTANT = Guid.Empty.ToString(); private static string FUNCTION_NAME = "handle_http_request"; public override string SelfId => string.Empty; @@ -51,7 +51,7 @@ public class HttpHandlerHook : AgentHookBase private (string, FunctionDef?) GetPromptAndFunction() { var db = _services.GetRequiredService(); - var agent = db.GetAgent(UTILITY_ASSISTANT); + 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.HttpHandler/data/agents/00000000-0000-0000-0000-000000000000/functions/handle_http_request.json b/src/Plugins/BotSharp.Plugin.HttpHandler/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/handle_http_request.json similarity index 100% rename from src/Plugins/BotSharp.Plugin.HttpHandler/data/agents/00000000-0000-0000-0000-000000000000/functions/handle_http_request.json rename to src/Plugins/BotSharp.Plugin.HttpHandler/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/handle_http_request.json diff --git a/src/Plugins/BotSharp.Plugin.HttpHandler/data/agents/00000000-0000-0000-0000-000000000000/templates/handle_http_request.fn.liquid b/src/Plugins/BotSharp.Plugin.HttpHandler/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/handle_http_request.fn.liquid similarity index 100% rename from src/Plugins/BotSharp.Plugin.HttpHandler/data/agents/00000000-0000-0000-0000-000000000000/templates/handle_http_request.fn.liquid rename to src/Plugins/BotSharp.Plugin.HttpHandler/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/handle_http_request.fn.liquid