diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Enums/AgentField.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Enums/AgentField.cs index 346bcf31..2a9508d7 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Enums/AgentField.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Enums/AgentField.cs @@ -19,6 +19,7 @@ public enum AgentField LlmConfig, Utility, KnowledgeBase, + Rule, MaxMessageCount } diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentRuleHook.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentRuleHook.cs new file mode 100644 index 00000000..8a19a561 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentRuleHook.cs @@ -0,0 +1,6 @@ +namespace BotSharp.Abstraction.Agents; + +public interface IAgentRuleHook +{ + void AddRules(List rules); +} diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs index 91beea8b..2ec4ff92 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs @@ -58,6 +58,4 @@ public interface IAgentService Task> GetUserAgents(string userId); PluginDef GetPlugin(string agentId); - - IEnumerable GetAgentUtilityOptions(); } diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs index 566df050..96aa070c 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs @@ -99,6 +99,11 @@ public class Agent /// public List Utilities { get; set; } = new(); + /// + /// Agent rules + /// + public List Rules { get; set; } = new(); + /// /// Agent knowledge bases /// @@ -154,6 +159,7 @@ public class Agent MaxMessageCount = agent.MaxMessageCount, Profiles = agent.Profiles, RoutingRules = agent.RoutingRules, + Rules = agent.Rules, LlmConfig = agent.LlmConfig, KnowledgeBases = agent.KnowledgeBases, CreatedDateTime = agent.CreatedDateTime, @@ -269,6 +275,12 @@ public class Agent return this; } + public Agent SetRules(List rules) + { + Rules = rules ?? []; + return this; + } + public Agent SetLlmConfig(AgentLlmConfig? llmConfig) { LlmConfig = llmConfig; diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentRule.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentRule.cs new file mode 100644 index 00000000..5c3a276e --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentRule.cs @@ -0,0 +1,13 @@ +namespace BotSharp.Abstraction.Agents.Models; + +public class AgentRule +{ + public string Name { get; set; } + public bool Disabled { get; set; } + + [JsonPropertyName("event_name")] + public string EventName { get; set; } + + [JsonPropertyName("entity_type")] + public string EntityType { get; set; } +} diff --git a/src/Infrastructure/BotSharp.Abstraction/Http/IHttpRequestHook.cs b/src/Infrastructure/BotSharp.Abstraction/Http/IHttpRequestHook.cs new file mode 100644 index 00000000..18b96e77 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Http/IHttpRequestHook.cs @@ -0,0 +1,8 @@ +using System.Net.Http.Headers; + +namespace BotSharp.Abstraction.Http; + +public interface IHttpRequestHook +{ + void OnAddHttpHeaders(HttpHeaders headers); +} diff --git a/src/Infrastructure/BotSharp.Abstraction/Users/IAuthenticationHook.cs b/src/Infrastructure/BotSharp.Abstraction/Users/IAuthenticationHook.cs index d953271f..939d509e 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Users/IAuthenticationHook.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Users/IAuthenticationHook.cs @@ -1,5 +1,4 @@ using BotSharp.Abstraction.Users.Models; -using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; namespace BotSharp.Abstraction.Users; diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs index 584a4c7e..6889336a 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs @@ -40,6 +40,7 @@ public partial class AgentService record.Samples = agent.Samples ?? []; record.Utilities = agent.Utilities ?? []; record.KnowledgeBases = agent.KnowledgeBases ?? []; + record.Rules = agent.Rules ?? []; if (agent.LlmConfig != null && !agent.LlmConfig.IsInherit) { record.LlmConfig = agent.LlmConfig; @@ -104,6 +105,7 @@ public partial class AgentService .SetSamples(foundAgent.Samples) .SetUtilities(foundAgent.Utilities) .SetKnowledgeBases(foundAgent.KnowledgeBases) + .SetRules(foundAgent.Rules) .SetLlmConfig(foundAgent.LlmConfig); _db.UpdateAgent(clonedAgent, AgentField.All); diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs index 80cdc56c..c54c4fd8 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs @@ -53,15 +53,4 @@ public partial class AgentService : IAgentService var userAgents = _db.GetUserAgents(userId); return userAgents; } - - public IEnumerable GetAgentUtilityOptions() - { - var utilities = new List(); - var hooks = _services.GetServices(); - foreach (var hook in hooks) - { - hook.AddUtilities(utilities); - } - return utilities.Where(x => !string.IsNullOrWhiteSpace(x.Name)).OrderBy(x => x.Name).ToList(); - } } diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs index 0a8d5b65..d38b2a89 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs @@ -60,6 +60,9 @@ namespace BotSharp.Core.Repository case AgentField.KnowledgeBase: UpdateAgentKnowledgeBases(agent.Id, agent.KnowledgeBases); break; + case AgentField.Rule: + UpdateAgentRules(agent.Id, agent.Rules); + break; case AgentField.MaxMessageCount: UpdateAgentMaxMessageCount(agent.Id, agent.MaxMessageCount); break; @@ -184,6 +187,19 @@ namespace BotSharp.Core.Repository File.WriteAllText(agentFile, json); } + private void UpdateAgentRules(string agentId, List rules) + { + if (rules == null) return; + + var (agent, agentFile) = GetAgentFromFile(agentId); + if (agent == null) return; + + agent.Rules = rules; + agent.UpdatedDateTime = DateTime.UtcNow; + var json = JsonSerializer.Serialize(agent, _options); + File.WriteAllText(agentFile, json); + } + private void UpdateAgentRoutingRules(string agentId, List rules) { if (rules == null) return; @@ -240,7 +256,7 @@ namespace BotSharp.Core.Repository var text = JsonSerializer.Serialize(func, _options); var file = Path.Combine(functionDir, $"{func.Name}.json"); File.WriteAllText(file, text); - Thread.Sleep(100); + Thread.Sleep(50); } } @@ -328,6 +344,7 @@ namespace BotSharp.Core.Repository agent.Utilities = inputAgent.Utilities; agent.KnowledgeBases = inputAgent.KnowledgeBases; agent.RoutingRules = inputAgent.RoutingRules; + agent.Rules = inputAgent.Rules; agent.LlmConfig = inputAgent.LlmConfig; agent.MaxMessageCount = inputAgent.MaxMessageCount; agent.UpdatedDateTime = DateTime.UtcNow; diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs index 1885365d..6efb7104 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs @@ -152,6 +152,24 @@ public class AgentController : ControllerBase [HttpGet("/agent/utility/options")] public IEnumerable GetAgentUtilityOptions() { - return _agentService.GetAgentUtilityOptions(); + var utilities = new List(); + var hooks = _services.GetServices(); + foreach (var hook in hooks) + { + hook.AddUtilities(utilities); + } + return utilities.Where(x => !string.IsNullOrWhiteSpace(x.Name)).OrderBy(x => x.Name).ToList(); + } + + [HttpGet("/agent/rule/options")] + public IEnumerable GetAgentRuleOptions() + { + var rules = new List(); + var hooks = _services.GetServices(); + foreach (var hook in hooks) + { + hook.AddRules(rules); + } + return rules.Where(x => !string.IsNullOrWhiteSpace(x.Name)).OrderBy(x => x.Name).ToList(); } } \ No newline at end of file diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentCreationModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentCreationModel.cs index 3caba6ae..a0e8f790 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentCreationModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentCreationModel.cs @@ -55,6 +55,7 @@ public class AgentCreationModel public List Utilities { get; set; } = new(); public List RoutingRules { get; set; } = new(); public List KnowledgeBases { get; set; } = new(); + public List Rules { get; set; } = new(); public AgentLlmConfig? LlmConfig { get; set; } public Agent ToAgent() @@ -78,6 +79,7 @@ public class AgentCreationModel Profiles = Profiles, LlmConfig = LlmConfig, KnowledgeBases = KnowledgeBases, + Rules = Rules, RoutingRules = RoutingRules?.Select(x => RoutingRuleUpdateModel.ToDomainElement(x))?.ToList() ?? [], }; } diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs index 66618186..8e268b97 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs @@ -75,6 +75,9 @@ public class AgentUpdateModel [JsonPropertyName("routing_rules")] public List? RoutingRules { get; set; } + [JsonPropertyName("rules")] + public List? Rules { get; set; } + [JsonPropertyName("llm_config")] public AgentLlmConfig? LlmConfig { get; set; } @@ -89,15 +92,16 @@ public class AgentUpdateModel MergeUtility = MergeUtility, MaxMessageCount = MaxMessageCount, Type = Type, - Profiles = Profiles ?? new List(), - RoutingRules = RoutingRules?.Select(x => RoutingRuleUpdateModel.ToDomainElement(x))?.ToList() ?? new List(), + Profiles = Profiles ?? [], + RoutingRules = RoutingRules?.Select(x => RoutingRuleUpdateModel.ToDomainElement(x))?.ToList() ?? [], Instruction = Instruction ?? string.Empty, - ChannelInstructions = ChannelInstructions ?? new List(), - Templates = Templates ?? new List(), - Functions = Functions ?? new List(), - Responses = Responses ?? new List(), - Utilities = Utilities ?? new List(), + ChannelInstructions = ChannelInstructions ?? [], + Templates = Templates ?? [], + Functions = Functions ?? [], + Responses = Responses ?? [], + Utilities = Utilities ?? [], KnowledgeBases = KnowledgeBases ?? [], + Rules = Rules ?? [], LlmConfig = LlmConfig }; diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs index e9479109..de4a13ba 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs @@ -28,6 +28,9 @@ public class AgentViewModel [JsonPropertyName("knowledge_bases")] public List KnowledgeBases { get; set; } + [JsonPropertyName("rules")] + public List Rules { get; set; } + [JsonPropertyName("is_public")] public bool IsPublic { get; set; } @@ -72,20 +75,21 @@ public class AgentViewModel Description = agent.Description, Type = agent.Type, Instruction = agent.Instruction, - ChannelInstructions = agent.ChannelInstructions, - Templates = agent.Templates, - Functions = agent.Functions, - Responses = agent.Responses, - Samples = agent.Samples, - Utilities = agent.Utilities, - KnowledgeBases = agent.KnowledgeBases, + ChannelInstructions = agent.ChannelInstructions ?? [], + Templates = agent.Templates ?? [], + Functions = agent.Functions ?? [], + Responses = agent.Responses ?? [], + Samples = agent.Samples ?? [], + Utilities = agent.Utilities ?? [], + KnowledgeBases = agent.KnowledgeBases ?? [], IsPublic= agent.IsPublic, Disabled = agent.Disabled, MergeUtility = agent.MergeUtility, IconUrl = agent.IconUrl, MaxMessageCount = agent.MaxMessageCount, - Profiles = agent.Profiles ?? new List(), - RoutingRules = agent.RoutingRules, + Profiles = agent.Profiles ?? [], + RoutingRules = agent.RoutingRules ?? [], + Rules = agent.Rules ?? [], LlmConfig = agent.LlmConfig, Plugin = agent.Plugin, CreatedDateTime = agent.CreatedDateTime, diff --git a/src/Plugins/BotSharp.Plugin.HttpHandler/Functions/HandleHttpRequestFn.cs b/src/Plugins/BotSharp.Plugin.HttpHandler/Functions/HandleHttpRequestFn.cs index d36aafba..52f5075b 100644 --- a/src/Plugins/BotSharp.Plugin.HttpHandler/Functions/HandleHttpRequestFn.cs +++ b/src/Plugins/BotSharp.Plugin.HttpHandler/Functions/HandleHttpRequestFn.cs @@ -1,5 +1,6 @@ using System.Net.Http; using System.Net.Mime; +using BotSharp.Abstraction.Http; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; @@ -13,7 +14,6 @@ public class HandleHttpRequestFn : IFunctionCallback private readonly IServiceProvider _services; private readonly ILogger _logger; private readonly IHttpClientFactory _httpClientFactory; - private readonly IHttpContextAccessor _context; private readonly BotSharpOptions _options; public HandleHttpRequestFn(IServiceProvider services, @@ -25,7 +25,6 @@ public class HandleHttpRequestFn : IFunctionCallback _services = services; _logger = logger; _httpClientFactory = httpClientFactory; - _context = context; _options = options; } @@ -46,7 +45,7 @@ public class HandleHttpRequestFn : IFunctionCallback catch (Exception ex) { var msg = $"Fail when sending http request. Url: {url}, method: {method}, content: {content}"; - _logger.LogWarning($"{msg}\n(Error: {ex.Message})"); + _logger.LogError($"{msg}\n(Error: {ex.Message}\r\n{ex.InnerException})"); message.Content = msg; return false; } @@ -57,7 +56,7 @@ public class HandleHttpRequestFn : IFunctionCallback if (string.IsNullOrEmpty(url)) return null; using var client = _httpClientFactory.CreateClient(); - AddRequestHeaders(client); + PrepareRequestHeaders(client); var (uri, request) = BuildHttpRequest(url, method, content); var response = await client.SendAsync(request); @@ -69,15 +68,12 @@ public class HandleHttpRequestFn : IFunctionCallback return response; } - private void AddRequestHeaders(HttpClient client) + private void PrepareRequestHeaders(HttpClient client) { - client.DefaultRequestHeaders.Add("Authorization", $"{_context.HttpContext.Request.Headers["Authorization"]}"); - - var settings = _services.GetRequiredService(); - var origin = !string.IsNullOrEmpty(settings.Origin) ? settings.Origin : $"{_context.HttpContext.Request.Headers["Origin"]}"; - if (!string.IsNullOrEmpty(origin)) + var hooks = _services.GetServices(); + foreach (var hook in hooks) { - client.DefaultRequestHeaders.Add("Origin", origin); + hook.OnAddHttpHeaders(client.DefaultRequestHeaders); } } diff --git a/src/Plugins/BotSharp.Plugin.HttpHandler/Hooks/BasicHttpRequestHook.cs b/src/Plugins/BotSharp.Plugin.HttpHandler/Hooks/BasicHttpRequestHook.cs new file mode 100644 index 00000000..5de858f2 --- /dev/null +++ b/src/Plugins/BotSharp.Plugin.HttpHandler/Hooks/BasicHttpRequestHook.cs @@ -0,0 +1,40 @@ +using BotSharp.Abstraction.Http; +using Microsoft.AspNetCore.Http; +using System.Net.Http.Headers; + +namespace BotSharp.Plugin.HttpHandler.Hooks; + +public class BasicHttpRequestHook : IHttpRequestHook +{ + private readonly IServiceProvider _services; + private readonly IHttpContextAccessor _context; + + private const string AUTHORIZATION = "Authorization"; + private const string ORIGIN = "Origin"; + + public BasicHttpRequestHook( + IServiceProvider services, + IHttpContextAccessor context) + { + _services = services; + _context = context; + } + + public void OnAddHttpHeaders(HttpHeaders headers) + { + var settings = _services.GetRequiredService(); + + var auth = $"{_context.HttpContext.Request.Headers[AUTHORIZATION]}"; + if (!string.IsNullOrEmpty(auth)) + { + headers.Add(AUTHORIZATION, auth); + } + + var origin = $"{_context.HttpContext.Request.Headers[ORIGIN]}"; + origin = !string.IsNullOrEmpty(settings.Origin) ? settings.Origin : origin; + if (!string.IsNullOrEmpty(origin)) + { + headers.Add(ORIGIN, origin); + } + } +} diff --git a/src/Plugins/BotSharp.Plugin.HttpHandler/HttpHandlerPlugin.cs b/src/Plugins/BotSharp.Plugin.HttpHandler/HttpHandlerPlugin.cs index 9c8cab55..a3c85c0b 100644 --- a/src/Plugins/BotSharp.Plugin.HttpHandler/HttpHandlerPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.HttpHandler/HttpHandlerPlugin.cs @@ -1,4 +1,5 @@ using BotSharp.Abstraction.Agents; +using BotSharp.Abstraction.Http; using BotSharp.Abstraction.Settings; using Microsoft.Extensions.Configuration; @@ -21,5 +22,6 @@ public class HttpHandlerPlugin : IBotSharpPlugin }); services.AddScoped(); + services.AddScoped(); } } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs index 19945124..54c9eae7 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs @@ -21,6 +21,7 @@ public class AgentDocument : MongoBase public List KnowledgeBases { get; set; } public List Profiles { get; set; } public List RoutingRules { get; set; } + public List Rules { get; set; } public AgentLlmConfigMongoElement? LlmConfig { get; set; } public DateTime CreatedTime { get; set; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentRuleMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentRuleMongoElement.cs new file mode 100644 index 00000000..1b346768 --- /dev/null +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentRuleMongoElement.cs @@ -0,0 +1,33 @@ +using BotSharp.Abstraction.Agents.Models; + +namespace BotSharp.Plugin.MongoStorage.Models; + +public class AgentRuleMongoElement +{ + public string Name { get; set; } + public bool Disabled { get; set; } + public string EventName { get; set; } + public string EntityType { get; set; } + + public static AgentRuleMongoElement ToMongoElement(AgentRule rule) + { + return new AgentRuleMongoElement + { + Name = rule.Name, + Disabled = rule.Disabled, + EventName = rule.EventName, + EntityType = rule.EntityType + }; + } + + public static AgentRule ToDomainElement(AgentRuleMongoElement rule) + { + return new AgentRule + { + Name = rule.Name, + Disabled = rule.Disabled, + EventName = rule.EventName, + EntityType = rule.EntityType + }; + } +} diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs index 7f86d144..af615298 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs @@ -61,6 +61,9 @@ public partial class MongoRepository case AgentField.KnowledgeBase: UpdateAgentKnowledgeBases(agent.Id, agent.KnowledgeBases); break; + case AgentField.Rule: + UpdateAgentRules(agent.Id, agent.Rules); + break; case AgentField.MaxMessageCount: UpdateAgentMaxMessageCount(agent.Id, agent.MaxMessageCount); break; @@ -256,6 +259,20 @@ public partial class MongoRepository _dc.Agents.UpdateOne(filter, update); } + private void UpdateAgentRules(string agentId, List rules) + { + if (rules == null) return; + + var elements = rules?.Select(x => AgentRuleMongoElement.ToMongoElement(x))?.ToList() ?? []; + + var filter = Builders.Filter.Eq(x => x.Id, agentId); + var update = Builders.Update + .Set(x => x.Rules, elements) + .Set(x => x.UpdatedTime, DateTime.UtcNow); + + _dc.Agents.UpdateOne(filter, update); + } + private void UpdateAgentLlmConfig(string agentId, AgentLlmConfig? config) { var llmConfig = AgentLlmConfigMongoElement.ToMongoElement(config); @@ -297,12 +314,12 @@ public partial class MongoRepository .Set(x => x.Samples, agent.Samples) .Set(x => x.Utilities, agent.Utilities.Select(u => AgentUtilityMongoElement.ToMongoElement(u)).ToList()) .Set(x => x.KnowledgeBases, agent.KnowledgeBases.Select(u => AgentKnowledgeBaseMongoElement.ToMongoElement(u)).ToList()) + .Set(x => x.Rules, agent.Rules.Select(e => AgentRuleMongoElement.ToMongoElement(e)).ToList()) .Set(x => x.LlmConfig, AgentLlmConfigMongoElement.ToMongoElement(agent.LlmConfig)) .Set(x => x.IsPublic, agent.IsPublic) .Set(x => x.UpdatedTime, DateTime.UtcNow); var res = _dc.Agents.UpdateOne(filter, update); - Console.WriteLine(); } #endregion @@ -455,6 +472,7 @@ public partial class MongoRepository RoutingRules = x.RoutingRules?.Select(r => RoutingRuleMongoElement.ToMongoElement(r))?.ToList() ?? [], Utilities = x.Utilities?.Select(u => AgentUtilityMongoElement.ToMongoElement(u))?.ToList() ?? [], KnowledgeBases = x.KnowledgeBases?.Select(k => AgentKnowledgeBaseMongoElement.ToMongoElement(k))?.ToList() ?? [], + Rules = x.Rules?.Select(e => AgentRuleMongoElement.ToMongoElement(e))?.ToList() ?? [], CreatedTime = x.CreatedDateTime, UpdatedTime = x.UpdatedDateTime }).ToList(); @@ -546,7 +564,8 @@ public partial class MongoRepository Responses = agentDoc.Responses?.Select(r => AgentResponseMongoElement.ToDomainElement(r))?.ToList() ?? [], RoutingRules = agentDoc.RoutingRules?.Select(r => RoutingRuleMongoElement.ToDomainElement(agentDoc.Id, agentDoc.Name, r))?.ToList() ?? [], Utilities = agentDoc.Utilities?.Select(u => AgentUtilityMongoElement.ToDomainElement(u))?.ToList() ?? [], - KnowledgeBases = agentDoc.KnowledgeBases?.Select(x => AgentKnowledgeBaseMongoElement.ToDomainElement(x))?.ToList() ?? [] + KnowledgeBases = agentDoc.KnowledgeBases?.Select(x => AgentKnowledgeBaseMongoElement.ToDomainElement(x))?.ToList() ?? [], + Rules = agentDoc.Rules?.Select(e => AgentRuleMongoElement.ToDomainElement(e))?.ToList() ?? [] }; } }