From 1762675cb01edefb9c8b6f61f6013ea55a70f779 Mon Sep 17 00:00:00 2001 From: Jicheng Lu Date: Sun, 4 May 2025 23:20:52 -0500 Subject: [PATCH] revert --- .../Agents/Enums/AgentField.cs | 1 - .../Agents/Models/Agent.cs | 15 +-- .../Agents/Models/AgentLink.cs | 17 ---- .../Agents/Models/AgentPromptBase.cs | 23 ----- .../Agents/Models/AgentTemplate.cs | 13 ++- .../Constants/TemplateRenderConstant.cs | 6 ++ .../Templating/ITemplateRender.cs | 17 ---- .../Services/AgentService.CreateAgent.cs | 20 ---- .../Services/AgentService.RefreshAgents.cs | 2 - .../Agents/Services/AgentService.Rendering.cs | 25 +---- .../Services/AgentService.UpdateAgent.cs | 4 - .../FileRepository/FileRepository.Agent.cs | 23 ----- .../FileRepository/FileRepository.cs | 25 ----- .../Templating/TemplateRender.cs | 92 ++++++++----------- src/Infrastructure/BotSharp.Core/Using.cs | 1 + .../Agents/Request/AgentCreationModel.cs | 3 - .../Agents/Request/AgentUpdateModel.cs | 6 -- .../ViewModels/Agents/View/AgentViewModel.cs | 2 - .../Collections/AgentDocument.cs | 1 - .../Models/AgentLinkMongoElement.cs | 28 ------ .../Repository/MongoRepository.Agent.cs | 19 ---- 21 files changed, 56 insertions(+), 287 deletions(-) delete mode 100644 src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentLink.cs delete mode 100644 src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentPromptBase.cs create mode 100644 src/Infrastructure/BotSharp.Abstraction/Templating/Constants/TemplateRenderConstant.cs delete mode 100644 src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentLinkMongoElement.cs diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Enums/AgentField.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Enums/AgentField.cs index ebdffe39..0cab0dfb 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Enums/AgentField.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Enums/AgentField.cs @@ -16,7 +16,6 @@ public enum AgentField Instruction, Function, Template, - Link, Response, Sample, LlmConfig, diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs index e43892fa..1ba644e8 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs @@ -46,12 +46,6 @@ public class Agent [JsonIgnore] public List Templates { get; set; } = new(); - /// - /// Links that can be filled into parent prompt - /// - [JsonIgnore] - public List Links { get; set; } = new(); - /// /// Agent tasks /// @@ -88,7 +82,7 @@ public class Agent public PluginDef Plugin { get; set; } [JsonIgnore] - public bool Installed => Plugin.Enabled; + public bool Installed => Plugin?.Enabled == true; /// /// Default is True, user will enable this by installing appropriate plugin. @@ -175,7 +169,6 @@ public class Agent Responses = agent.Responses, Samples = agent.Samples, Templates = agent.Templates, - Links = agent.Links, Utilities = agent.Utilities, McpTools = agent.McpTools, Knowledges = agent.Knowledges, @@ -212,12 +205,6 @@ public class Agent return this; } - public Agent SetLinks(List links) - { - Links = links ?? []; - return this; - } - public Agent SetTasks(List tasks) { Tasks = tasks ?? []; diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentLink.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentLink.cs deleted file mode 100644 index c1bdbfae..00000000 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentLink.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace BotSharp.Abstraction.Agents.Models; - -public class AgentLink : AgentPromptBase -{ - public AgentLink() : base() - { - } - - public AgentLink(string name, string content) : base(name, content) - { - } - - public override string ToString() - { - return base.ToString(); - } -} diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentPromptBase.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentPromptBase.cs deleted file mode 100644 index c199a773..00000000 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentPromptBase.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace BotSharp.Abstraction.Agents.Models; - -public class AgentPromptBase -{ - public string Name { get; set; } - public string Content { get; set; } - - public AgentPromptBase() - { - - } - - public AgentPromptBase(string name, string content) - { - Name = name; - Content = content; - } - - public override string ToString() - { - return Name; - } -} diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentTemplate.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentTemplate.cs index f9225baa..2eb3b4a0 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentTemplate.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentTemplate.cs @@ -1,17 +1,22 @@ namespace BotSharp.Abstraction.Agents.Models; -public class AgentTemplate : AgentPromptBase +public class AgentTemplate { - public AgentTemplate() : base() + public string Name { get; set; } + public string Content { get; set; } + + public AgentTemplate() { } - public AgentTemplate(string name, string content) : base(name, content) + public AgentTemplate(string name, string content) { + Name = name; + Content = content; } public override string ToString() { - return base.ToString(); + return Name; } } diff --git a/src/Infrastructure/BotSharp.Abstraction/Templating/Constants/TemplateRenderConstant.cs b/src/Infrastructure/BotSharp.Abstraction/Templating/Constants/TemplateRenderConstant.cs new file mode 100644 index 00000000..756de8b3 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Templating/Constants/TemplateRenderConstant.cs @@ -0,0 +1,6 @@ +namespace BotSharp.Abstraction.Templating.Constants; + +public static class TemplateRenderConstant +{ + public const string RENDER_AGENT = "render_agent"; +} diff --git a/src/Infrastructure/BotSharp.Abstraction/Templating/ITemplateRender.cs b/src/Infrastructure/BotSharp.Abstraction/Templating/ITemplateRender.cs index 77e942dd..fecc36c4 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Templating/ITemplateRender.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Templating/ITemplateRender.cs @@ -3,22 +3,5 @@ namespace BotSharp.Abstraction.Templating; public interface ITemplateRender { string Render(string template, Dictionary dict); - - /// - /// Register tag - /// - /// - /// A dictionary whose key is identifier and value is its content to render - /// - /// - bool RegisterTag(string tag, Dictionary content, Dictionary? data = null); - - /// - /// Register tags - /// - /// A dictionary whose key is tag and value is its identifier and content to render - /// - /// - bool RegisterTags(Dictionary> tags, Dictionary? data = null); void RegisterType(Type type); } diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.CreateAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.CreateAgent.cs index 9984c222..5becbec6 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.CreateAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.CreateAgent.cs @@ -111,26 +111,6 @@ public partial class AgentService return templates; } - private List GetLinksFromFile(string fileDir) - { - var links = new List(); - var linkDir = Path.Combine(fileDir, "links"); - if (!Directory.Exists(linkDir)) return links; - - foreach (var file in Directory.GetFiles(linkDir)) - { - var extension = Path.GetExtension(file).Substring(1); - if (extension.IsEqualTo(_agentSettings.TemplateFormat)) - { - var name = Path.GetFileNameWithoutExtension(file); - var content = File.ReadAllText(file); - links.Add(new AgentLink(name, content)); - } - } - - return links; - } - private List GetFunctionsFromFile(string fileDir) { var functions = new List(); diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.RefreshAgents.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.RefreshAgents.cs index b659083f..c9b3c90c 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.RefreshAgents.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.RefreshAgents.cs @@ -52,12 +52,10 @@ public partial class AgentService var functions = GetFunctionsFromFile(dir); var responses = GetResponsesFromFile(dir); var templates = GetTemplatesFromFile(dir); - var links = GetLinksFromFile(dir); var samples = GetSamplesFromFile(dir); agent.SetInstruction(defaultInstruction) .SetChannelInstructions(channelInstructions) .SetTemplates(templates) - .SetLinks(links) .SetFunctions(functions) .SetResponses(responses) .SetSamples(samples); diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.Rendering.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.Rendering.cs index 6e63c86b..ef36f4d7 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.Rendering.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.Rendering.cs @@ -22,7 +22,7 @@ public partial class AgentService agent.TemplateDict[t.Key] = t.Value; } - RenderAgentLinks(agent, agent.TemplateDict); + agent.TemplateDict[TemplateRenderConstant.RENDER_AGENT] = agent; var res = render.Render(string.Join("\r\n", instructions), agent.TemplateDict); return res; } @@ -129,6 +129,7 @@ public partial class AgentService } // render liquid template + agent.TemplateDict[TemplateRenderConstant.RENDER_AGENT] = agent; var content = render.Render(template, agent.TemplateDict); HookEmitter.Emit(_services, async hook => @@ -137,26 +138,4 @@ public partial class AgentService return content; } - - private void RenderAgentLinks(Agent agent, Dictionary dict) - { - var render = _services.GetRequiredService(); - - var links = new Dictionary(); - agent.Links ??= []; - - foreach (var link in agent.Links) - { - if (string.IsNullOrWhiteSpace(link.Name) - || string.IsNullOrWhiteSpace(link.Content)) - { - continue; - } - - links[link.Name] = link.Content; - } - - render.RegisterTag("link", links, dict); - return; - } } \ No newline at end of file diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs index 9b15e777..8365639b 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs @@ -38,7 +38,6 @@ public partial class AgentService record.ChannelInstructions = agent.ChannelInstructions ?? []; record.Functions = agent.Functions ?? []; record.Templates = agent.Templates ?? []; - record.Links = agent.Links ?? []; record.Responses = agent.Responses ?? []; record.Samples = agent.Samples ?? []; record.Utilities = agent.Utilities ?? []; @@ -106,7 +105,6 @@ public partial class AgentService .SetInstruction(foundAgent.Instruction) .SetChannelInstructions(foundAgent.ChannelInstructions) .SetTemplates(foundAgent.Templates) - .SetLinks(foundAgent.Links) .SetFunctions(foundAgent.Functions) .SetResponses(foundAgent.Responses) .SetSamples(foundAgent.Samples) @@ -198,12 +196,10 @@ public partial class AgentService var functions = GetFunctionsFromFile(dir); var responses = GetResponsesFromFile(dir); var templates = GetTemplatesFromFile(dir); - var links = GetLinksFromFile(dir); var samples = GetSamplesFromFile(dir); return agent.SetInstruction(defaultInstruction) .SetChannelInstructions(channelInstructions) .SetTemplates(templates) - .SetLinks(links) .SetFunctions(functions) .SetResponses(responses) .SetSamples(samples); diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs index 5219a0b0..930eb13d 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs @@ -51,9 +51,6 @@ namespace BotSharp.Core.Repository case AgentField.Template: UpdateAgentTemplates(agent.Id, agent.Templates); break; - case AgentField.Link: - UpdateAgentLinks(agent.Id, agent.Links); - break; case AgentField.Response: UpdateAgentResponses(agent.Id, agent.Responses); break; @@ -328,23 +325,6 @@ namespace BotSharp.Core.Repository } } - private void UpdateAgentLinks(string agentId, List links) - { - if (links == null) return; - - var (agent, agentFile) = GetAgentFromFile(agentId); - if (agent == null) return; - - var linkDir = Path.Combine(_dbSettings.FileRepository, _agentSettings.DataDir, agentId, AGENT_LINKS_FOLDER); - DeleteBeforeCreateDirectory(linkDir); - - foreach (var link in links) - { - var file = Path.Combine(linkDir, $"{link.Name}.{_agentSettings.TemplateFormat}"); - File.WriteAllText(file, link.Content); - } - } - private void UpdateAgentResponses(string agentId, List responses) { if (responses == null) return; @@ -424,7 +404,6 @@ namespace BotSharp.Core.Repository UpdateAgentInstructions(inputAgent.Id, inputAgent.Instruction, inputAgent.ChannelInstructions); UpdateAgentResponses(inputAgent.Id, inputAgent.Responses); UpdateAgentTemplates(inputAgent.Id, inputAgent.Templates); - UpdateAgentLinks(inputAgent.Id, inputAgent.Links); UpdateAgentFunctions(inputAgent.Id, inputAgent.Functions); UpdateAgentSamples(inputAgent.Id, inputAgent.Samples); } @@ -468,13 +447,11 @@ namespace BotSharp.Core.Repository var functions = FetchFunctions(dir); var samples = FetchSamples(dir); var templates = FetchTemplates(dir); - var links = FetchLinks(dir); var responses = FetchResponses(dir); return record.SetInstruction(defaultInstruction) .SetChannelInstructions(channelInstructions) .SetFunctions(functions) .SetTemplates(templates) - .SetLinks(links) .SetSamples(samples) .SetResponses(responses); } diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs index eecf9b45..5b31f88c 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs @@ -24,7 +24,6 @@ public partial class FileRepository : IBotSharpRepository private const string AGENT_INSTRUCTIONS_FOLDER = "instructions"; private const string AGENT_FUNCTIONS_FOLDER = "functions"; private const string AGENT_TEMPLATES_FOLDER = "templates"; - private const string AGENT_LINKS_FOLDER = "links"; private const string AGENT_RESPONSES_FOLDER = "responses"; private const string AGENT_TASKS_FOLDER = "tasks"; private const string AGENT_TASK_PREFIX = "#metadata"; @@ -229,7 +228,6 @@ public partial class FileRepository : IBotSharpRepository .SetChannelInstructions(channelInstructions) .SetFunctions(FetchFunctions(d)) .SetTemplates(FetchTemplates(d)) - .SetLinks(FetchLinks(d)) .SetResponses(FetchResponses(d)) .SetSamples(FetchSamples(d)); _agents.Add(agent); @@ -402,29 +400,6 @@ public partial class FileRepository : IBotSharpRepository return templates; } - private List FetchLinks(string fileDir) - { - var links = new List(); - var linkDir = Path.Combine(fileDir, AGENT_LINKS_FOLDER); - - if (!Directory.Exists(linkDir)) return links; - - foreach (var file in Directory.GetFiles(linkDir)) - { - var fileName = Path.GetFileName(file); - var splitIdx = fileName.LastIndexOf("."); - var name = fileName.Substring(0, splitIdx); - var extension = fileName.Substring(splitIdx + 1); - if (extension.Equals(_agentSettings.TemplateFormat, StringComparison.OrdinalIgnoreCase)) - { - var content = File.ReadAllText(file); - links.Add(new AgentLink(name, content)); - } - - } - return links; - } - private List FetchTasks(string fileDir) { var tasks = new List(); diff --git a/src/Infrastructure/BotSharp.Core/Templating/TemplateRender.cs b/src/Infrastructure/BotSharp.Core/Templating/TemplateRender.cs index ace11c41..e564e574 100644 --- a/src/Infrastructure/BotSharp.Core/Templating/TemplateRender.cs +++ b/src/Infrastructure/BotSharp.Core/Templating/TemplateRender.cs @@ -5,7 +5,9 @@ using BotSharp.Abstraction.Translation.Models; using Fluid; using Fluid.Ast; using System.Collections; +using System.IO; using System.Reflection; +using System.Text.Encodings.Web; namespace BotSharp.Core.Templating; @@ -33,6 +35,8 @@ public class TemplateRender : ITemplateRender _options.MemberAccessStrategy.Register(); _options.MemberAccessStrategy.Register(); _options.MemberAccessStrategy.Register(); + + _parser.RegisterIdentifierTag("link", RenderIdentifierTag); } public string Render(string template, Dictionary dict) @@ -50,61 +54,6 @@ public class TemplateRender : ITemplateRender return template; } - public bool RegisterTag(string tag, Dictionary content, Dictionary? data = null) - { - _parser.RegisterIdentifierTag(tag, (identifier, writer, encoder, context) => - { - if (content?.TryGetValue(identifier, out var value) == true) - { - var str = Render(value, data ?? []); - writer.Write(str); - } - else - { - writer.Write(string.Empty); - } - return Statement.Normal(); - }); - - return true; - } - - public bool RegisterTags(Dictionary> tags, Dictionary? data = null) - { - if (tags.IsNullOrEmpty()) return false; - - foreach (var item in tags) - { - var tag = item.Key; - if (string.IsNullOrWhiteSpace(tag) - || item.Value.IsNullOrEmpty()) - { - continue; - } - - foreach (var prompt in item.Value) - { - _parser.RegisterIdentifierTag(tag, (identifier, writer, encoder, context) => - { - var found = item.Value.FirstOrDefault(x => x.Name.IsEqualTo(identifier)); - if (found != null) - { - var str = Render(found.Content, data ?? []); - writer.Write(str); - } - else - { - writer.Write(string.Empty); - } - - return Statement.Normal(); - }); - } - } - - return true; - } - public void RegisterType(Type type) { if (type == null || IsStringType(type)) return; @@ -130,6 +79,39 @@ public class TemplateRender : ITemplateRender #region Private methods + private static async ValueTask RenderIdentifierTag(string identifier, TextWriter writer, TextEncoder encoder, TemplateContext context) + { + try + { + var value = await context.Model.GetValueAsync(TemplateRenderConstant.RENDER_AGENT, context); + var agent = value?.ToObjectValue() as Agent; + var found = agent?.Templates?.FirstOrDefault(x => x.Name.IsEqualTo(identifier)); + var key = $"{agent?.Id} | {identifier}"; + + if (found == null || context.AmbientValues.TryGetValue(key, out var visited) && (bool)visited) + { + writer.Write(string.Empty); + } + else if (_parser.TryParse(found.Content, out var t, out _)) + { + context.AmbientValues[key] = true; + var rendered = t.Render(context); + writer.Write(rendered); + context.AmbientValues.Remove(key); + } + else + { + writer.Write(string.Empty); + } + } + catch + { + writer.Write(string.Empty); + } + + return Completion.Normal; + } + private static bool IsStringType(Type type) { return type == typeof(string); diff --git a/src/Infrastructure/BotSharp.Core/Using.cs b/src/Infrastructure/BotSharp.Core/Using.cs index 0afac090..91c12038 100644 --- a/src/Infrastructure/BotSharp.Core/Using.cs +++ b/src/Infrastructure/BotSharp.Core/Using.cs @@ -41,6 +41,7 @@ global using BotSharp.Abstraction.Statistics.Enums; global using BotSharp.Abstraction.Statistics.Services; global using BotSharp.Abstraction.Loggers.Services; global using BotSharp.Abstraction.Infrastructures.Events; +global using BotSharp.Abstraction.Templating.Constants; global using BotSharp.Core.Repository; global using BotSharp.Core.Routing; global using BotSharp.Core.Agents.Services; diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/Request/AgentCreationModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/Request/AgentCreationModel.cs index 61aa89fd..8265ebe4 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/Request/AgentCreationModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/Request/AgentCreationModel.cs @@ -24,8 +24,6 @@ public class AgentCreationModel /// public List Templates { get; set; } = new(); - public List Links { get; set; } = new(); - /// /// LLM callable function definition /// @@ -72,7 +70,6 @@ public class AgentCreationModel Instruction = Instruction, ChannelInstructions = ChannelInstructions, Templates = Templates, - Links = Links, Functions = Functions, Responses = Responses, Samples = Samples, diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/Request/AgentUpdateModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/Request/AgentUpdateModel.cs index 0e9b8ebb..b11a9db0 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/Request/AgentUpdateModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/Request/AgentUpdateModel.cs @@ -25,11 +25,6 @@ public class AgentUpdateModel /// public List? Templates { get; set; } - /// - /// Links - /// - public List? Links { get; set; } - /// /// Samples /// @@ -110,7 +105,6 @@ public class AgentUpdateModel Instruction = Instruction ?? string.Empty, ChannelInstructions = ChannelInstructions ?? [], Templates = Templates ?? [], - Links = Links ?? [], Functions = Functions ?? [], Responses = Responses ?? [], Utilities = Utilities ?? [], diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/View/AgentViewModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/View/AgentViewModel.cs index 6fe468d0..4fede545 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/View/AgentViewModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/View/AgentViewModel.cs @@ -18,7 +18,6 @@ public class AgentViewModel [JsonPropertyName("channel_instructions")] public List ChannelInstructions { get; set; } public List Templates { get; set; } - public List Links { get; set; } public List Functions { get; set; } public List Responses { get; set; } public List Samples { get; set; } @@ -88,7 +87,6 @@ public class AgentViewModel Instruction = agent.Instruction, ChannelInstructions = agent.ChannelInstructions ?? [], Templates = agent.Templates ?? [], - Links = agent.Links ?? [], Functions = agent.Functions ?? [], Responses = agent.Responses ?? [], Samples = agent.Samples ?? [], diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs index 47e7d061..7ebded25 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs @@ -15,7 +15,6 @@ public class AgentDocument : MongoBase public int? MaxMessageCount { get; set; } public List ChannelInstructions { get; set; } public List Templates { get; set; } - public List Links { get; set; } public List Functions { get; set; } public List Responses { get; set; } public List Samples { get; set; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentLinkMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentLinkMongoElement.cs deleted file mode 100644 index f618e03a..00000000 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentLinkMongoElement.cs +++ /dev/null @@ -1,28 +0,0 @@ -using BotSharp.Abstraction.Agents.Models; - -namespace BotSharp.Plugin.MongoStorage.Models; - -[BsonIgnoreExtraElements(Inherited = true)] -public class AgentLinkMongoElement -{ - public string Name { get; set; } = default!; - public string Content { get; set; } = default!; - - public static AgentLinkMongoElement ToMongoElement(AgentLink link) - { - return new AgentLinkMongoElement - { - Name = link.Name, - Content = link.Content - }; - } - - public static AgentLink ToDomainElement(AgentLinkMongoElement mongoLink) - { - return new AgentLink - { - Name = mongoLink.Name, - Content = mongoLink.Content - }; - } -} diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs index 35cde7ee..6eda94ed 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs @@ -52,9 +52,6 @@ public partial class MongoRepository case AgentField.Template: UpdateAgentTemplates(agent.Id, agent.Templates); break; - case AgentField.Link: - UpdateAgentLinks(agent.Id, agent.Links); - break; case AgentField.Response: UpdateAgentResponses(agent.Id, agent.Responses); break; @@ -240,19 +237,6 @@ public partial class MongoRepository _dc.Agents.UpdateOne(filter, update); } - private void UpdateAgentLinks(string agentId, List links) - { - if (links == null) return; - - var linksToUpdate = links.Select(t => AgentLinkMongoElement.ToMongoElement(t)).ToList(); - var filter = Builders.Filter.Eq(x => x.Id, agentId); - var update = Builders.Update - .Set(x => x.Links, linksToUpdate) - .Set(x => x.UpdatedTime, DateTime.UtcNow); - - _dc.Agents.UpdateOne(filter, update); - } - private void UpdateAgentResponses(string agentId, List responses) { if (responses == null || string.IsNullOrWhiteSpace(agentId)) return; @@ -372,7 +356,6 @@ public partial class MongoRepository .Set(x => x.Instruction, agent.Instruction) .Set(x => x.ChannelInstructions, agent.ChannelInstructions.Select(i => ChannelInstructionMongoElement.ToMongoElement(i)).ToList()) .Set(x => x.Templates, agent.Templates.Select(t => AgentTemplateMongoElement.ToMongoElement(t)).ToList()) - .Set(x => x.Links, agent.Links.Select(t => AgentLinkMongoElement.ToMongoElement(t)).ToList()) .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) @@ -555,7 +538,6 @@ public partial class MongoRepository LlmConfig = AgentLlmConfigMongoElement.ToMongoElement(x.LlmConfig), ChannelInstructions = x.ChannelInstructions?.Select(i => ChannelInstructionMongoElement.ToMongoElement(i))?.ToList() ?? [], Templates = x.Templates?.Select(t => AgentTemplateMongoElement.ToMongoElement(t))?.ToList() ?? [], - Links = x.Links?.Select(l => AgentLinkMongoElement.ToMongoElement(l))?.ToList() ?? [], Functions = x.Functions?.Select(f => FunctionDefMongoElement.ToMongoElement(f))?.ToList() ?? [], Responses = x.Responses?.Select(r => AgentResponseMongoElement.ToMongoElement(r))?.ToList() ?? [], RoutingRules = x.RoutingRules?.Select(r => RoutingRuleMongoElement.ToMongoElement(r))?.ToList() ?? [], @@ -652,7 +634,6 @@ public partial class MongoRepository LlmConfig = AgentLlmConfigMongoElement.ToDomainElement(agentDoc.LlmConfig), ChannelInstructions = agentDoc.ChannelInstructions?.Select(i => ChannelInstructionMongoElement.ToDomainElement(i))?.ToList() ?? [], Templates = agentDoc.Templates?.Select(t => AgentTemplateMongoElement.ToDomainElement(t))?.ToList() ?? [], - Links = agentDoc.Links?.Select(l => AgentLinkMongoElement.ToDomainElement(l))?.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() ?? [],