diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs index 7214a3d5..f727403d 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs @@ -57,9 +57,9 @@ public abstract class AgentHookBase : IAgentHook { } - public virtual void OnLoadAgentUtility(Agent agent, IEnumerable utilities) + public virtual void OnAgentUtilityloaded(Agent agent) { - if (agent.Type == AgentType.Routing || utilities.IsNullOrEmpty()) return; + if (agent.Type == AgentType.Routing) return; var conv = _services.GetRequiredService(); var isConvMode = conv.IsConversationMode(); @@ -68,16 +68,13 @@ public abstract class AgentHookBase : IAgentHook var render = _services.GetRequiredService(); agent.Functions ??= []; - var agentUtilities = agent.Utilities ?? []; + agent.Utilities ??= []; - foreach (var utillity in utilities) + foreach (var utillity in agent.Utilities) { - if (utillity.Name.IsNullOrEmpty() || utillity.Content == null) continue; + if (utillity == null || string.IsNullOrWhiteSpace(utillity.Name)) continue; - var isEnabled = agentUtilities.Contains(utillity.Name); - if (!isEnabled) continue; - - var (fns, prompts) = GetUtilityContent(utillity.Content); + var (fns, prompts) = GetUtilityContent(utillity); if (!fns.IsNullOrEmpty()) { @@ -94,7 +91,7 @@ public abstract class AgentHookBase : IAgentHook } } - private (IEnumerable, IEnumerable) GetUtilityContent(UtilityContent content) + private (IEnumerable, IEnumerable) GetUtilityContent(AgentUtility utility) { var db = _services.GetRequiredService(); var render = _services.GetRequiredService(); @@ -108,15 +105,15 @@ public abstract class AgentHookBase : IAgentHook return (fns, prompts); } - if (!content.Functions.IsNullOrEmpty()) + if (!utility.Functions.IsNullOrEmpty()) { - var functionNames = content.Functions?.Select(x => x.Name)?.ToList() ?? []; + var functionNames = utility.Functions?.Select(x => x.Name)?.ToList() ?? []; fns = agent?.Functions?.Where(x => functionNames.Contains(x.Name, StringComparer.OrdinalIgnoreCase))?.ToList() ?? []; } - if (!content.Templates.IsNullOrEmpty()) + if (!utility.Templates.IsNullOrEmpty()) { - foreach (var template in content.Templates) + foreach (var template in utility.Templates) { var prompt = agent?.Templates?.FirstOrDefault(x => x.Name.IsEqualTo(template.Name))?.Content ?? string.Empty; if (string.IsNullOrWhiteSpace(prompt)) continue; diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentHook.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentHook.cs index d60f348c..ceb212bf 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentHook.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentHook.cs @@ -25,12 +25,12 @@ public interface IAgentHook bool OnSamplesLoaded(List samples); + void OnAgentUtilityloaded(Agent agent); + /// /// Triggered when agent is loaded completely. /// /// /// void OnAgentLoaded(Agent agent); - - void OnLoadAgentUtility(Agent agent, IEnumerable utilities); } diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs index 43f0f5ba..63594d08 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs @@ -93,7 +93,7 @@ public class Agent /// /// Agent utilities /// - public List Utilities { get; set; } = new(); + public List Utilities { get; set; } = new(); /// /// Inherit from agent @@ -173,9 +173,9 @@ public class Agent return this; } - public Agent SetUtilities(List utilities) + public Agent SetUtilities(List utilities) { - Utilities = utilities ?? new List(); + Utilities = utilities ?? new List(); return this; } diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentUtility.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentUtility.cs index 672c9f3d..1617e173 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentUtility.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentUtility.cs @@ -2,33 +2,32 @@ namespace BotSharp.Abstraction.Agents.Models; public class AgentUtility { + [JsonPropertyName("name")] public string Name { get; set; } - public UtilityContent Content { get; set; } + + [JsonPropertyName("functions")] + public IEnumerable Functions { get; set; } = []; + + [JsonPropertyName("templates")] + public IEnumerable Templates { get; set; } = []; public AgentUtility() { } - public AgentUtility(string utilityName, UtilityContent content) + public AgentUtility( + string name, + IEnumerable? functions = null, + IEnumerable? templates = null) { - Name = utilityName; - Content = content; + Name = name; + Functions = functions ?? []; + Templates = templates ?? []; } } -public class UtilityContent -{ - public IEnumerable Functions { get; set; } = []; - public IEnumerable Templates { get; set; } = []; - - public UtilityContent() - { - - } -} - public class UtilityFunction : UtilityBase { public UtilityFunction() diff --git a/src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingContext.cs b/src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingContext.cs index f75e8e0e..1dd9f50a 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingContext.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingContext.cs @@ -6,6 +6,7 @@ public interface IRoutingContext string FirstGoalAgentId(); bool ContainsAgentId(string agentId); string OriginAgentId { get; } + string EntryAgentId { get; } string ConversationId { get; } string MessageId { get; } void SetMessageId(string conversationId, string messageId); diff --git a/src/Infrastructure/BotSharp.Abstraction/Users/Enums/UserAction.cs b/src/Infrastructure/BotSharp.Abstraction/Users/Enums/UserAction.cs index b565a260..b702ea01 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Users/Enums/UserAction.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Users/Enums/UserAction.cs @@ -1,5 +1,8 @@ namespace BotSharp.Abstraction.Users.Enums; +/// +/// User actions on agent level +/// public static class UserAction { public const string Edit = "edit"; diff --git a/src/Infrastructure/BotSharp.Abstraction/Users/Enums/UserPermission.cs b/src/Infrastructure/BotSharp.Abstraction/Users/Enums/UserPermission.cs index 58dfc186..64212fe4 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Users/Enums/UserPermission.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Users/Enums/UserPermission.cs @@ -1,5 +1,8 @@ namespace BotSharp.Abstraction.Users.Enums; +/// +/// User permission +/// public static class UserPermission { public const string CreateAgent = "create-agent"; diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs index f0a864a2..45121830 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs @@ -67,6 +67,7 @@ public partial class AgentService hook.OnSamplesLoaded(agent.Samples); } + hook.OnAgentUtilityloaded(agent); hook.OnAgentLoaded(agent); } diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs index 18afb27f..1a333119 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs @@ -37,7 +37,7 @@ public partial class AgentService record.Templates = agent.Templates ?? new List(); record.Responses = agent.Responses ?? new List(); record.Samples = agent.Samples ?? new List(); - record.Utilities = agent.Utilities ?? new List(); + record.Utilities = agent.Utilities ?? new List(); if (agent.LlmConfig != null && !agent.LlmConfig.IsInherit) { record.LlmConfig = agent.LlmConfig; diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs index 7f545527..de676d28 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs @@ -151,7 +151,7 @@ namespace BotSharp.Core.Repository File.WriteAllText(agentFile, json); } - private void UpdateAgentUtilities(string agentId, List utilities) + private void UpdateAgentUtilities(string agentId, List utilities) { if (utilities == null) return; diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs index 5c1f1903..3cb1eac9 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs @@ -41,7 +41,8 @@ public class RoutingContext : IRoutingContext var agentService = _services.GetRequiredService(); _routerAgentIds = agentService.GetAgents(new AgentFilter { - Type = AgentType.Routing + Type = AgentType.Routing, + Pager = new Pagination { Size = 20 } }).Result.Items.Select(x => x.Id).ToArray(); } @@ -49,6 +50,17 @@ public class RoutingContext : IRoutingContext } } + /// + /// Entry agent + /// + public string EntryAgentId + { + get + { + return _stack.LastOrDefault() ?? string.Empty; + } + } + public bool IsEmpty => !_stack.Any(); public string GetCurrentAgentId() diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentCreationModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentCreationModel.cs index 78f75833..4a41a8d8 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentCreationModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentCreationModel.cs @@ -48,7 +48,7 @@ public class AgentCreationModel /// Combine different Agents together to form a Profile. /// public List Profiles { get; set; } = new(); - public List Utilities { get; set; } = new(); + public List Utilities { get; set; } = new(); public List RoutingRules { get; set; } = new(); public AgentLlmConfig? LlmConfig { get; set; } diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs index d64530c6..08e7c85c 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs @@ -34,7 +34,7 @@ public class AgentUpdateModel /// /// Utilities /// - public List? Utilities { get; set; } + public List? Utilities { get; set; } /// /// Functions @@ -81,7 +81,7 @@ public class AgentUpdateModel Templates = Templates ?? new List(), Functions = Functions ?? new List(), Responses = Responses ?? new List(), - Utilities = Utilities ?? new List(), + Utilities = Utilities ?? new List(), LlmConfig = LlmConfig }; diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs index ca814177..066cc030 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs @@ -20,7 +20,7 @@ public class AgentViewModel public List Functions { get; set; } public List Responses { get; set; } public List Samples { get; set; } - public List Utilities { get; set; } + public List Utilities { get; set; } [JsonPropertyName("is_public")] public bool IsPublic { get; set; } diff --git a/src/Plugins/BotSharp.Plugin.AudioHandler/Hooks/AudioHandlerHook.cs b/src/Plugins/BotSharp.Plugin.AudioHandler/Hooks/AudioHandlerHook.cs index 547cd7c3..20565679 100644 --- a/src/Plugins/BotSharp.Plugin.AudioHandler/Hooks/AudioHandlerHook.cs +++ b/src/Plugins/BotSharp.Plugin.AudioHandler/Hooks/AudioHandlerHook.cs @@ -18,14 +18,10 @@ public class AudioHandlerHook : AgentHookBase, IAgentHook var utilityLoad = new AgentUtility { Name = UtilityName.AudioHandler, - Content = new UtilityContent - { - Functions = [new(HANDLER_AUDIO)], - Templates = [new($"{HANDLER_AUDIO}.fn")] - } + Functions = [new(HANDLER_AUDIO)], + Templates = [new($"{HANDLER_AUDIO}.fn")] }; - base.OnLoadAgentUtility(agent, [utilityLoad]); base.OnAgentLoaded(agent); } } diff --git a/src/Plugins/BotSharp.Plugin.EmailHandler/Hooks/EmailHandlerHook.cs b/src/Plugins/BotSharp.Plugin.EmailHandler/Hooks/EmailHandlerHook.cs index 4bee4bff..ae38e329 100644 --- a/src/Plugins/BotSharp.Plugin.EmailHandler/Hooks/EmailHandlerHook.cs +++ b/src/Plugins/BotSharp.Plugin.EmailHandler/Hooks/EmailHandlerHook.cs @@ -21,14 +21,10 @@ public class EmailHandlerHook : AgentHookBase var utilityLoad = new AgentUtility { Name = UtilityName.EmailHandler, - Content = new UtilityContent - { - Functions = [new(EMAIL_READER_FN), new(EMAIL_SENDER_FN)], - Templates = [new($"{EMAIL_READER_FN}.fn"), new($"{EMAIL_SENDER_FN}.fn")] - } + Functions = [new(EMAIL_READER_FN), new(EMAIL_SENDER_FN)], + Templates = [new($"{EMAIL_READER_FN}.fn"), new($"{EMAIL_SENDER_FN}.fn")] }; - base.OnLoadAgentUtility(agent, [utilityLoad]); base.OnAgentLoaded(agent); } } diff --git a/src/Plugins/BotSharp.Plugin.ExcelHandler/Hooks/ExcelHandlerHook.cs b/src/Plugins/BotSharp.Plugin.ExcelHandler/Hooks/ExcelHandlerHook.cs index 453386ed..de02c18a 100644 --- a/src/Plugins/BotSharp.Plugin.ExcelHandler/Hooks/ExcelHandlerHook.cs +++ b/src/Plugins/BotSharp.Plugin.ExcelHandler/Hooks/ExcelHandlerHook.cs @@ -15,14 +15,10 @@ public class ExcelHandlerHook : AgentHookBase, IAgentHook var utilityLoad = new AgentUtility { Name = UtilityName.ExcelHandler, - Content = new UtilityContent - { - Functions = [new(HANDLER_EXCEL)], - Templates = [new($"{HANDLER_EXCEL}.fn")] - } + Functions = [new(HANDLER_EXCEL)], + Templates = [new($"{HANDLER_EXCEL}.fn")] }; - base.OnLoadAgentUtility(agent, [utilityLoad]); base.OnAgentLoaded(agent); } } diff --git a/src/Plugins/BotSharp.Plugin.FileHandler/Hooks/FileHandlerHook.cs b/src/Plugins/BotSharp.Plugin.FileHandler/Hooks/FileHandlerHook.cs index f43c9a1d..cc0d0653 100644 --- a/src/Plugins/BotSharp.Plugin.FileHandler/Hooks/FileHandlerHook.cs +++ b/src/Plugins/BotSharp.Plugin.FileHandler/Hooks/FileHandlerHook.cs @@ -20,42 +20,29 @@ public class FileHandlerHook : AgentHookBase, IAgentHook new AgentUtility { Name = UtilityName.ImageGenerator, - Content = new UtilityContent - { - Functions = [new(GENERATE_IMAGE_FN)], - Templates = [new($"{GENERATE_IMAGE_FN}.fn")] - } + Functions = [new(GENERATE_IMAGE_FN)], + Templates = [new($"{GENERATE_IMAGE_FN}.fn")] }, new AgentUtility { Name = UtilityName.ImageReader, - Content = new UtilityContent - { - Functions = [new(READ_IMAGE_FN)], - Templates = [new($"{READ_IMAGE_FN}.fn")] - } + Functions = [new(READ_IMAGE_FN)], + Templates = [new($"{READ_IMAGE_FN}.fn")] }, new AgentUtility { Name = UtilityName.ImageEditor, - Content = new UtilityContent - { - Functions = [new(EDIT_IMAGE_FN)], - Templates = [new($"{EDIT_IMAGE_FN}.fn")] - } + Functions = [new(EDIT_IMAGE_FN)], + Templates = [new($"{EDIT_IMAGE_FN}.fn")] }, new AgentUtility { Name = UtilityName.PdfReader, - Content = new UtilityContent - { - Functions = [new(READ_PDF_FN)], - Templates = [new($"{READ_PDF_FN}.fn")] - } + Functions = [new(READ_PDF_FN)], + Templates = [new($"{READ_PDF_FN}.fn")] } }; - base.OnLoadAgentUtility(agent, utilityLoads); base.OnAgentLoaded(agent); } } diff --git a/src/Plugins/BotSharp.Plugin.HttpHandler/Hooks/HttpHandlerHook.cs b/src/Plugins/BotSharp.Plugin.HttpHandler/Hooks/HttpHandlerHook.cs index 049f4718..e30fc329 100644 --- a/src/Plugins/BotSharp.Plugin.HttpHandler/Hooks/HttpHandlerHook.cs +++ b/src/Plugins/BotSharp.Plugin.HttpHandler/Hooks/HttpHandlerHook.cs @@ -19,14 +19,10 @@ public class HttpHandlerHook : AgentHookBase var utilityLoad = new AgentUtility { Name = UtilityName.HttpHandler, - Content = new UtilityContent - { - Functions = [new(HTTP_HANDLER_FN)], - Templates = [new($"{HTTP_HANDLER_FN}.fn")] - } + Functions = [new(HTTP_HANDLER_FN)], + Templates = [new($"{HTTP_HANDLER_FN}.fn")] }; - base.OnLoadAgentUtility(agent, [utilityLoad]); base.OnAgentLoaded(agent); } } diff --git a/src/Plugins/BotSharp.Plugin.KnowledgeBase/Hooks/KnowledgeBaseAgentHook.cs b/src/Plugins/BotSharp.Plugin.KnowledgeBase/Hooks/KnowledgeBaseAgentHook.cs index 8988c241..852ab0da 100644 --- a/src/Plugins/BotSharp.Plugin.KnowledgeBase/Hooks/KnowledgeBaseAgentHook.cs +++ b/src/Plugins/BotSharp.Plugin.KnowledgeBase/Hooks/KnowledgeBaseAgentHook.cs @@ -17,14 +17,10 @@ public class KnowledgeBaseAgentHook : AgentHookBase, IAgentHook var utilityLoad = new AgentUtility { Name = UtilityName.KnowledgeRetrieval, - Content = new UtilityContent - { - Functions = [new(KNOWLEDGE_RETRIEVAL_FN)], - Templates = [new($"{KNOWLEDGE_RETRIEVAL_FN}.fn")] - } + Functions = [new(KNOWLEDGE_RETRIEVAL_FN)], + Templates = [new($"{KNOWLEDGE_RETRIEVAL_FN}.fn")] }; - base.OnLoadAgentUtility(agent, [utilityLoad]); base.OnAgentLoaded(agent); } } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs index baa0729f..82b62b62 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs @@ -13,7 +13,7 @@ public class AgentDocument : MongoBase public List Functions { get; set; } public List Responses { get; set; } public List Samples { get; set; } - public List Utilities { get; set; } + public List Utilities { get; set; } public bool IsPublic { get; set; } public bool Disabled { get; set; } public List Profiles { get; set; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentUtilityMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentUtilityMongoElement.cs new file mode 100644 index 00000000..0eecee90 --- /dev/null +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentUtilityMongoElement.cs @@ -0,0 +1,60 @@ +using BotSharp.Abstraction.Agents.Models; + +namespace BotSharp.Plugin.MongoStorage.Models; + +public class AgentUtilityMongoElement +{ + public string Name { get; set; } + public List Functions { get; set; } = []; + public List Templates { get; set; } = []; + + public static AgentUtilityMongoElement ToMongoElement(AgentUtility utility) + { + return new AgentUtilityMongoElement + { + Name = utility.Name, + Functions = utility.Functions?.Select(x => new UtilityFunctionMongoElement(x.Name))?.ToList() ?? [], + Templates = utility.Templates?.Select(x => new UtilityTemplateMongoElement(x.Name))?.ToList() ?? [] + }; + } + + public static AgentUtility ToDomainElement(AgentUtilityMongoElement utility) + { + return new AgentUtility + { + Name = utility.Name, + Functions = utility.Functions?.Select(x => new UtilityFunction(x.Name))?.ToList() ?? [], + Templates = utility.Templates?.Select(x => new UtilityTemplate(x.Name))?.ToList() ?? [] + }; + } +} + +public class UtilityFunctionMongoElement +{ + public string Name { get; set; } + + public UtilityFunctionMongoElement() + { + + } + + public UtilityFunctionMongoElement(string name) + { + Name = name; + } +} + +public class UtilityTemplateMongoElement +{ + public string Name { get; set; } + + public UtilityTemplateMongoElement() + { + + } + + public UtilityTemplateMongoElement(string name) + { + Name = name; + } +} \ No newline at end of file diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs index d17f7f2f..3a88dc9c 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs @@ -224,13 +224,15 @@ public partial class MongoRepository _dc.Agents.UpdateOne(filter, update); } - private void UpdateAgentUtilities(string agentId, List utilities) + private void UpdateAgentUtilities(string agentId, List utilities) { if (utilities == null) return; + var elements = utilities?.Select(x => AgentUtilityMongoElement.ToMongoElement(x))?.ToList() ?? []; + var filter = Builders.Filter.Eq(x => x.Id, agentId); var update = Builders.Update - .Set(x => x.Utilities, utilities) + .Set(x => x.Utilities, elements) .Set(x => x.UpdatedTime, DateTime.UtcNow); _dc.Agents.UpdateOne(filter, update); @@ -263,7 +265,7 @@ public partial class MongoRepository .Set(x => x.Functions, agent.Functions.Select(f => FunctionDefMongoElement.ToMongoElement(f)).ToList()) .Set(x => x.Responses, agent.Responses.Select(r => AgentResponseMongoElement.ToMongoElement(r)).ToList()) .Set(x => x.Samples, agent.Samples) - .Set(x => x.Utilities, agent.Utilities) + .Set(x => x.Utilities, agent.Utilities.Select(u => AgentUtilityMongoElement.ToMongoElement(u)).ToList()) .Set(x => x.LlmConfig, AgentLlmConfigMongoElement.ToMongoElement(agent.LlmConfig)) .Set(x => x.IsPublic, agent.IsPublic) .Set(x => x.UpdatedTime, DateTime.UtcNow); @@ -406,28 +408,18 @@ public partial class MongoRepository IconUrl = x.IconUrl, Description = x.Description, Instruction = x.Instruction, - ChannelInstructions = x.ChannelInstructions? - .Select(i => ChannelInstructionMongoElement.ToMongoElement(i))? - .ToList() ?? new List(), - Templates = x.Templates? - .Select(t => AgentTemplateMongoElement.ToMongoElement(t))? - .ToList() ?? new List(), - Functions = x.Functions? - .Select(f => FunctionDefMongoElement.ToMongoElement(f))? - .ToList() ?? new List(), - Responses = x.Responses? - .Select(r => AgentResponseMongoElement.ToMongoElement(r))? - .ToList() ?? new List(), + ChannelInstructions = x.ChannelInstructions?.Select(i => ChannelInstructionMongoElement.ToMongoElement(i))?.ToList() ?? [], + Templates = x.Templates?.Select(t => AgentTemplateMongoElement.ToMongoElement(t))?.ToList() ?? [], + Functions = x.Functions?.Select(f => FunctionDefMongoElement.ToMongoElement(f))?.ToList() ?? [], + Responses = x.Responses?.Select(r => AgentResponseMongoElement.ToMongoElement(r))?.ToList() ?? [], Samples = x.Samples ?? new List(), - Utilities = x.Utilities ?? new List(), + Utilities = x.Utilities?.Select(u => AgentUtilityMongoElement.ToMongoElement(u))?.ToList() ?? [], IsPublic = x.IsPublic, Type = x.Type, InheritAgentId = x.InheritAgentId, Disabled = x.Disabled, Profiles = x.Profiles, - RoutingRules = x.RoutingRules? - .Select(r => RoutingRuleMongoElement.ToMongoElement(r))? - .ToList() ?? new List(), + RoutingRules = x.RoutingRules?.Select(r => RoutingRuleMongoElement.ToMongoElement(r))?.ToList() ?? [], LlmConfig = AgentLlmConfigMongoElement.ToMongoElement(x.LlmConfig), CreatedTime = x.CreatedDateTime, UpdatedTime = x.UpdatedDateTime @@ -505,24 +497,14 @@ public partial class MongoRepository IconUrl = agentDoc.IconUrl, Description = agentDoc.Description, Instruction = agentDoc.Instruction, - ChannelInstructions = !agentDoc.ChannelInstructions.IsNullOrEmpty() ? agentDoc.ChannelInstructions - .Select(i => ChannelInstructionMongoElement.ToDomainElement(i)) - .ToList() : new List(), - Templates = !agentDoc.Templates.IsNullOrEmpty() ? agentDoc.Templates - .Select(t => AgentTemplateMongoElement.ToDomainElement(t)) - .ToList() : new List(), - Functions = !agentDoc.Functions.IsNullOrEmpty() ? agentDoc.Functions - .Select(f => FunctionDefMongoElement.ToDomainElement(f)) - .ToList() : new List(), - Responses = !agentDoc.Responses.IsNullOrEmpty() ? agentDoc.Responses - .Select(r => AgentResponseMongoElement.ToDomainElement(r)) - .ToList() : new List(), - RoutingRules = !agentDoc.RoutingRules.IsNullOrEmpty() ? agentDoc.RoutingRules - .Select(r => RoutingRuleMongoElement.ToDomainElement(agentDoc.Id, agentDoc.Name, r)) - .ToList() : new List(), + ChannelInstructions = agentDoc.ChannelInstructions?.Select(i => ChannelInstructionMongoElement.ToDomainElement(i))?.ToList() ?? [], + Templates = agentDoc.Templates?.Select(t => AgentTemplateMongoElement.ToDomainElement(t))?.ToList() ?? [], + Functions = agentDoc.Functions?.Select(f => FunctionDefMongoElement.ToDomainElement(f)).ToList() ?? [], + Responses = agentDoc.Responses?.Select(r => AgentResponseMongoElement.ToDomainElement(r))?.ToList() ?? [], + RoutingRules = agentDoc.RoutingRules?.Select(r => RoutingRuleMongoElement.ToDomainElement(agentDoc.Id, agentDoc.Name, r))?.ToList() ?? [], LlmConfig = AgentLlmConfigMongoElement.ToDomainElement(agentDoc.LlmConfig), - Samples = agentDoc.Samples ?? new List(), - Utilities = agentDoc.Utilities ?? new List(), + Samples = agentDoc.Samples ?? [], + Utilities = agentDoc.Utilities?.Select(u => AgentUtilityMongoElement.ToDomainElement(u))?.ToList() ?? [], IsPublic = agentDoc.IsPublic, Disabled = agentDoc.Disabled, Type = agentDoc.Type, diff --git a/src/Plugins/BotSharp.Plugin.Planner/Hooks/PlannerAgentHook.cs b/src/Plugins/BotSharp.Plugin.Planner/Hooks/PlannerAgentHook.cs index 2b098b78..60f39a7d 100644 --- a/src/Plugins/BotSharp.Plugin.Planner/Hooks/PlannerAgentHook.cs +++ b/src/Plugins/BotSharp.Plugin.Planner/Hooks/PlannerAgentHook.cs @@ -37,22 +37,18 @@ public class PlannerAgentHook : AgentHookBase var utilityLoad = new AgentUtility { Name = UtilityName.TwoStagePlanner, - Content = new UtilityContent - { - 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") - ] - } + 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.OnLoadAgentUtility(agent, [utilityLoad]); base.OnAgentLoaded(agent); } } diff --git a/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/agent.json b/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/agent.json index a90ef2ed..c3db4f42 100644 --- a/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/agent.json +++ b/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/agent.json @@ -9,7 +9,39 @@ "disabled": false, "isPublic": true, "profiles": [ "planning" ], - "utilities": [ "two-stage-planner", "sql-dictionary-lookup", "excel-handler" ], + "utilities": [ + { + "name": "two-stage-planner", + "functions": [ + { "name": "plan_primary_stage" }, + { "name": "plan_secondary_stage" }, + { "name": "plan_summary" } + ], + "templates": [ + { "name": "plan_primary_stage.fn" }, + { "name": "plan_secondary_stage.fn" }, + { "name": "plan_summary.fn" } + ] + }, + { + "name": "sql-dictionary-lookup", + "functions": [ + { "name": "verify_dictionary_term" } + ], + "templates": [ + { "name": "verify_dictionary_term.fn" } + ] + }, + { + "name": "excel-handler", + "functions": [ + { "name": "handle_excel_request" } + ], + "templates": [ + { "name": "handle_excel_request.fn" } + ] + } + ], "llmConfig": { "provider": "openai", "model": "gpt-4o", diff --git a/src/Plugins/BotSharp.Plugin.SqlDriver/Hooks/SqlDriverAgentHook.cs b/src/Plugins/BotSharp.Plugin.SqlDriver/Hooks/SqlDriverAgentHook.cs index 0ad432b0..c64e70f0 100644 --- a/src/Plugins/BotSharp.Plugin.SqlDriver/Hooks/SqlDriverAgentHook.cs +++ b/src/Plugins/BotSharp.Plugin.SqlDriver/Hooks/SqlDriverAgentHook.cs @@ -26,33 +26,23 @@ public class SqlDriverAgentHook : AgentHookBase, IAgentHook new AgentUtility { Name = UtilityName.SqlTableDefinition, - Content = new UtilityContent - { - Functions = new List { new(SQL_TABLE_DEFINITION_FN) }, - Templates = new List { new($"{SQL_TABLE_DEFINITION_FN}.fn") } - } + Functions = [new(SQL_TABLE_DEFINITION_FN)], + Templates = [new($"{SQL_TABLE_DEFINITION_FN}.fn")] }, new AgentUtility { Name = UtilityName.SqlDictionaryLookup, - Content = new UtilityContent - { - Functions = new List { new(VERIFY_DICTIONARY_TERM_FN) }, - Templates = new List { new($"{VERIFY_DICTIONARY_TERM_FN}.fn") } - } + Functions = [new(VERIFY_DICTIONARY_TERM_FN)], + Templates = [new($"{VERIFY_DICTIONARY_TERM_FN}.fn")] }, new AgentUtility { Name = UtilityName.SqlExecutor, - Content = new UtilityContent - { - Functions = new List { new(SQL_SELECT_FN), new(SQL_TABLE_DEFINITION_FN) }, - Templates = new List { new($"sql_executor.fn") } - } + Functions = new List { new(SQL_SELECT_FN), new(SQL_TABLE_DEFINITION_FN) }, + Templates = new List { new($"sql_executor.fn") } } }; - base.OnLoadAgentUtility(agent, utilityLoads); base.OnAgentLoaded(agent); } } diff --git a/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Hooks/OutboundPhoneCallHandlerHook.cs b/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Hooks/OutboundPhoneCallHandlerHook.cs index 664a4e80..84f0d387 100644 --- a/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Hooks/OutboundPhoneCallHandlerHook.cs +++ b/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Hooks/OutboundPhoneCallHandlerHook.cs @@ -19,14 +19,10 @@ namespace BotSharp.Plugin.Twilio.OutboundPhoneCallHandler.Hooks var utilityLoad = new AgentUtility { Name = UtilityName.OutboundPhoneCall, - Content = new UtilityContent - { - Functions = [new(OUTBOUND_PHONE_CALL_FN)], - Templates = [new($"{OUTBOUND_PHONE_CALL_FN}.fn")] - } + Functions = [new(OUTBOUND_PHONE_CALL_FN)], + Templates = [new($"{OUTBOUND_PHONE_CALL_FN}.fn")] }; - base.OnLoadAgentUtility(agent, [utilityLoad]); base.OnAgentLoaded(agent); } }