From 731355d1101bba477158ad7b92c425d58b060460 Mon Sep 17 00:00:00 2001 From: geffzhang Date: Mon, 24 Feb 2025 09:04:44 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=20Rename=20Agent=20Context=20Prot?= =?UTF-8?q?ocols?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Agents/AgentHookBase.cs | 2 +- .../Agents/Enums/AgentField.cs | 2 +- .../BotSharp.Abstraction/Agents/IAgentHook.cs | 2 +- .../Agents/Models/Agent.cs | 8 ++--- .../Agents/Models/{AgentMCP.cs => AgentCP.cs} | 26 +++++++------- .../Agents/Hooks/BasicAgentHook.cs | 10 +++--- .../Agents/Services/AgentService.LoadAgent.cs | 4 +-- .../Services/AgentService.UpdateAgent.cs | 4 +-- .../FileRepository/FileRepository.Agent.cs | 10 +++--- .../ViewModels/Agents/AgentCreationModel.cs | 4 +-- .../ViewModels/Agents/AgentUpdateModel.cs | 6 ++-- .../ViewModels/Agents/AgentViewModel.cs | 4 +-- .../Collections/AgentDocument.cs | 2 +- ...MongoElement.cs => AgentCPMongoElement.cs} | 34 +++++++++---------- .../Repository/MongoRepository.Agent.cs | 14 ++++---- 15 files changed, 66 insertions(+), 66 deletions(-) rename src/Infrastructure/BotSharp.Abstraction/Agents/Models/{AgentMCP.cs => AgentCP.cs} (54%) rename src/Plugins/BotSharp.Plugin.MongoStorage/Models/{AgentMcpMongoElement.cs => AgentCPMongoElement.cs} (51%) diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs index ff52bb46..295d3bc2 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs @@ -60,7 +60,7 @@ public abstract class AgentHookBase : IAgentHook } - public virtual void OnAgentMCPLoaded(Agent agent) + public virtual void OnAgentCPLoaded(Agent agent) { } diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Enums/AgentField.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Enums/AgentField.cs index e02d02d7..413f9eb8 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Enums/AgentField.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Enums/AgentField.cs @@ -19,7 +19,7 @@ public enum AgentField Sample, LlmConfig, Utility, - Mcp, + Acp, KnowledgeBase, Rule, MaxMessageCount diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentHook.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentHook.cs index 21bf8b5b..59920408 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentHook.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentHook.cs @@ -27,7 +27,7 @@ public interface IAgentHook void OnAgentUtilityLoaded(Agent agent); - void OnAgentMCPLoaded(Agent agent); + void OnAgentCPLoaded(Agent agent); /// /// Triggered when agent is loaded completely. diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs index bed77d43..da57d33b 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs @@ -106,7 +106,7 @@ public class Agent /// /// Agent MCP /// - public List Mcps { get; set; } = new(); + public List Acps { get; set; } = new(); /// /// Agent rules @@ -161,7 +161,7 @@ public class Agent Responses = agent.Responses, Samples = agent.Samples, Utilities = agent.Utilities, - Mcps = agent.Mcps, + Acps = agent.Acps, Knowledges = agent.Knowledges, IsPublic = agent.IsPublic, Disabled = agent.Disabled, @@ -304,9 +304,9 @@ public class Agent return this; } - public Agent SetMcps(List mcps) + public Agent SetMcps(List mcps) { - Mcps = mcps ?? []; + Acps = mcps ?? []; return this; } } diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentMCP.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentCP.cs similarity index 54% rename from src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentMCP.cs rename to src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentCP.cs index 98a186dc..735e7dc8 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentMCP.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentCP.cs @@ -1,6 +1,6 @@ namespace BotSharp.Abstraction.Agents.Models; -public class AgentMCP +public class AgentCP { public string Name { get; set; } @@ -8,18 +8,18 @@ public class AgentMCP public bool Disabled { get; set; } - public IEnumerable Functions { get; set; } = []; - public IEnumerable Templates { get; set; } = []; + public IEnumerable Functions { get; set; } = []; + public IEnumerable Templates { get; set; } = []; - public AgentMCP() + public AgentCP() { } - public AgentMCP( + public AgentCP( string name, - IEnumerable? functions = null, - IEnumerable? templates = null) + IEnumerable? functions = null, + IEnumerable? templates = null) { Name = name; Functions = functions ?? []; @@ -33,27 +33,27 @@ public class AgentMCP } -public class MCPFunction : MCPBase +public class ACPFunction : MCPBase { - public MCPFunction() + public ACPFunction() { } - public MCPFunction(string name) + public ACPFunction(string name) { Name = name; } } -public class MCPTemplate : MCPBase +public class ACPTemplate : MCPBase { - public MCPTemplate() + public ACPTemplate() { } - public MCPTemplate(string name) + public ACPTemplate(string name) { Name = name; } diff --git a/src/Infrastructure/BotSharp.Core/Agents/Hooks/BasicAgentHook.cs b/src/Infrastructure/BotSharp.Core/Agents/Hooks/BasicAgentHook.cs index b3bf3868..bcb15bd3 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Hooks/BasicAgentHook.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Hooks/BasicAgentHook.cs @@ -42,7 +42,7 @@ public class BasicAgentHook : AgentHookBase } } - public override void OnAgentMCPLoaded(Agent agent) + public override void OnAgentCPLoaded(Agent agent) { if (agent.Type == AgentType.Routing) return; @@ -53,9 +53,9 @@ public class BasicAgentHook : AgentHookBase agent.SecondaryFunctions ??= []; agent.SecondaryInstructions ??= []; - agent.Mcps ??= []; + agent.Acps ??= []; - var (functions, templates) = GetMCPContent(agent); + var (functions, templates) = GetACPContent(agent); foreach (var fn in functions) { @@ -116,12 +116,12 @@ public class BasicAgentHook : AgentHookBase return (functionNames, templateNames); } - private (IEnumerable, IEnumerable) GetMCPContent(Agent agent) + private (IEnumerable, IEnumerable) GetACPContent(Agent agent) { List functionDefs = new List(); IEnumerable templates = new List(); var mcpClientManager = _services.GetRequiredService(); - var mcps = agent.Mcps; + var mcps = agent.Acps; foreach (var item in mcps) { var ua = mcpClientManager.Factory.GetClientAsync(item.ServerId).Result; diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs index 411c2e89..70722c6a 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs @@ -72,9 +72,9 @@ public partial class AgentService hook.OnAgentUtilityLoaded(agent); } - if(agent.Mcps != null) + if(agent.Acps != null) { - hook.OnAgentMCPLoaded(agent); + hook.OnAgentCPLoaded(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 8fdb2c9b..30a621c4 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs @@ -40,7 +40,7 @@ public partial class AgentService record.Responses = agent.Responses ?? []; record.Samples = agent.Samples ?? []; record.Utilities = agent.Utilities ?? []; - record.Mcps = agent.Mcps ?? []; + record.Acps = agent.Acps ?? []; record.KnowledgeBases = agent.KnowledgeBases ?? []; record.Rules = agent.Rules ?? []; if (agent.LlmConfig != null && !agent.LlmConfig.IsInherit) @@ -107,7 +107,7 @@ public partial class AgentService .SetResponses(foundAgent.Responses) .SetSamples(foundAgent.Samples) .SetUtilities(foundAgent.Utilities) - .SetMcps(foundAgent.Mcps) + .SetMcps(foundAgent.Acps) .SetKnowledgeBases(foundAgent.KnowledgeBases) .SetRules(foundAgent.Rules) .SetLlmConfig(foundAgent.LlmConfig); diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs index eeee97d2..8b7b547a 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs @@ -60,8 +60,8 @@ namespace BotSharp.Core.Repository case AgentField.Utility: UpdateAgentUtilities(agent.Id, agent.MergeUtility, agent.Utilities); break; - case AgentField.Mcp: - UpdateAgentMcp(agent.Id, agent.Mcps); + case AgentField.Acp: + UpdateAgentCP(agent.Id, agent.Acps); break; case AgentField.KnowledgeBase: UpdateAgentKnowledgeBases(agent.Id, agent.KnowledgeBases); @@ -194,7 +194,7 @@ namespace BotSharp.Core.Repository File.WriteAllText(agentFile, json); } - private void UpdateAgentMcp(string agentId, List mcps) + private void UpdateAgentCP(string agentId, List mcps) { if (mcps == null) return; @@ -202,7 +202,7 @@ namespace BotSharp.Core.Repository if (agent == null) return; - agent.Mcps = mcps; + agent.Acps = mcps; agent.UpdatedDateTime = DateTime.UtcNow; var json = JsonSerializer.Serialize(agent, _options); File.WriteAllText(agentFile, json); @@ -377,7 +377,7 @@ namespace BotSharp.Core.Repository agent.Profiles = inputAgent.Profiles; agent.Labels = inputAgent.Labels; agent.Utilities = inputAgent.Utilities; - agent.Mcps = inputAgent.Mcps; + agent.Acps = inputAgent.Acps; agent.KnowledgeBases = inputAgent.KnowledgeBases; agent.RoutingRules = inputAgent.RoutingRules; agent.Rules = inputAgent.Rules; diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentCreationModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentCreationModel.cs index e8af9018..6432b355 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentCreationModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentCreationModel.cs @@ -55,7 +55,7 @@ public class AgentCreationModel public int? MaxMessageCount { get; set; } public List Utilities { get; set; } = new(); - public List Mcps { get; set; } = new(); + public List Acps { get; set; } = new(); public List RoutingRules { get; set; } = new(); public List KnowledgeBases { get; set; } = new(); public List Rules { get; set; } = new(); @@ -74,7 +74,7 @@ public class AgentCreationModel Responses = Responses, Samples = Samples, Utilities = Utilities, - Mcps = Mcps, + Acps = Acps, IsPublic = IsPublic, Type = Type, Disabled = Disabled, diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs index be2e2a36..c5295891 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs @@ -40,9 +40,9 @@ public class AgentUpdateModel public List? Utilities { get; set; } /// - /// Mcps + /// Acps /// - public List? Mcps { get; set; } + public List? Acps { get; set; } /// /// knowledge bases @@ -108,7 +108,7 @@ public class AgentUpdateModel Functions = Functions ?? [], Responses = Responses ?? [], Utilities = Utilities ?? [], - Mcps = Mcps ?? [], + Acps = Acps ?? [], KnowledgeBases = KnowledgeBases ?? [], Rules = Rules ?? [], LlmConfig = LlmConfig ?? new() diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs index 54109da6..934322cb 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs @@ -24,7 +24,7 @@ public class AgentViewModel [JsonPropertyName("merge_utility")] public bool MergeUtility { get; set; } public List Utilities { get; set; } - public List Mcps { get; set; } + public List Acps { get; set; } [JsonPropertyName("knowledge_bases")] public List KnowledgeBases { get; set; } @@ -87,7 +87,7 @@ public class AgentViewModel Responses = agent.Responses ?? [], Samples = agent.Samples ?? [], Utilities = agent.Utilities ?? [], - Mcps = agent.Mcps ?? [], + Acps = agent.Acps ?? [], KnowledgeBases = agent.KnowledgeBases ?? [], IsPublic= agent.IsPublic, Disabled = agent.Disabled, diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs index f6b82dd8..6be40cf6 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs @@ -18,7 +18,7 @@ public class AgentDocument : MongoBase public List Responses { get; set; } public List Samples { get; set; } public List Utilities { get; set; } - public List Mcps { get; set; } + public List Mcps { get; set; } public List KnowledgeBases { get; set; } public List Profiles { get; set; } public List Labels { get; set; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentMcpMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentCPMongoElement.cs similarity index 51% rename from src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentMcpMongoElement.cs rename to src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentCPMongoElement.cs index 5090e1ba..eb149736 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentMcpMongoElement.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentCPMongoElement.cs @@ -8,64 +8,64 @@ using System.Threading.Tasks; namespace BotSharp.Plugin.MongoStorage.Models; [BsonIgnoreExtraElements(Inherited = true)] -public class AgentMcpMongoElement +public class AgentCPMongoElement { public string Name { get; set; } public string ServerId { get; set; } public bool Disabled { get; set; } - public List Functions { get; set; } = []; - public List Templates { get; set; } = []; + public List Functions { get; set; } = []; + public List Templates { get; set; } = []; - public static AgentMcpMongoElement ToMongoElement(AgentMCP utility) + public static AgentCPMongoElement ToMongoElement(AgentCP utility) { - return new AgentMcpMongoElement + return new AgentCPMongoElement { Name = utility.Name, Disabled = utility.Disabled, - Functions = utility.Functions?.Select(x => new McpFunctionMongoElement(x.Name))?.ToList() ?? [], - Templates = utility.Templates?.Select(x => new McpTemplateMongoElement(x.Name))?.ToList() ?? [] + Functions = utility.Functions?.Select(x => new AcpFunctionMongoElement(x.Name))?.ToList() ?? [], + Templates = utility.Templates?.Select(x => new AcpTemplateMongoElement(x.Name))?.ToList() ?? [] }; } - public static AgentMCP ToDomainElement(AgentMcpMongoElement utility) + public static AgentCP ToDomainElement(AgentCPMongoElement utility) { - return new AgentMCP + return new AgentCP { Name = utility.Name, Disabled = utility.Disabled, - Functions = utility.Functions?.Select(x => new MCPFunction(x.Name))?.ToList() ?? [], - Templates = utility.Templates?.Select(x => new MCPTemplate(x.Name))?.ToList() ?? [] + Functions = utility.Functions?.Select(x => new ACPFunction(x.Name))?.ToList() ?? [], + Templates = utility.Templates?.Select(x => new ACPTemplate(x.Name))?.ToList() ?? [] }; } } -public class McpFunctionMongoElement +public class AcpFunctionMongoElement { public string Name { get; set; } - public McpFunctionMongoElement() + public AcpFunctionMongoElement() { } - public McpFunctionMongoElement(string name) + public AcpFunctionMongoElement(string name) { Name = name; } } -public class McpTemplateMongoElement +public class AcpTemplateMongoElement { public string Name { get; set; } - public McpTemplateMongoElement() + public AcpTemplateMongoElement() { } - public McpTemplateMongoElement(string name) + public AcpTemplateMongoElement(string name) { Name = name; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs index 68aa17a9..98fee01a 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs @@ -61,8 +61,8 @@ public partial class MongoRepository case AgentField.Utility: UpdateAgentUtilities(agent.Id, agent.MergeUtility, agent.Utilities); break; - case AgentField.Mcp: - UpdateAgentMcps(agent.Id, agent.Mcps); + case AgentField.Acp: + UpdateAgentMcps(agent.Id, agent.Acps); break; case AgentField.KnowledgeBase: UpdateAgentKnowledgeBases(agent.Id, agent.KnowledgeBases); @@ -264,11 +264,11 @@ public partial class MongoRepository _dc.Agents.UpdateOne(filter, update); } - private void UpdateAgentMcps(string agentId, List mcps) + private void UpdateAgentMcps(string agentId, List mcps) { if (mcps == null) return; - var elements = mcps?.Select(x => AgentMcpMongoElement.ToMongoElement(x))?.ToList() ?? []; + var elements = mcps?.Select(x => AgentCPMongoElement.ToMongoElement(x))?.ToList() ?? []; var filter = Builders.Filter.Eq(x => x.Id, agentId); var update = Builders.Update @@ -346,7 +346,7 @@ public partial class MongoRepository .Set(x => x.Responses, agent.Responses.Select(r => AgentResponseMongoElement.ToMongoElement(r)).ToList()) .Set(x => x.Samples, agent.Samples) .Set(x => x.Utilities, agent.Utilities.Select(u => AgentUtilityMongoElement.ToMongoElement(u)).ToList()) - .Set(x => x.Mcps, agent.Mcps.Select(u => AgentMcpMongoElement.ToMongoElement(u)).ToList()) + .Set(x => x.Mcps, agent.Acps.Select(u => AgentCPMongoElement.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)) @@ -527,7 +527,7 @@ public partial class MongoRepository Responses = x.Responses?.Select(r => AgentResponseMongoElement.ToMongoElement(r))?.ToList() ?? [], RoutingRules = x.RoutingRules?.Select(r => RoutingRuleMongoElement.ToMongoElement(r))?.ToList() ?? [], Utilities = x.Utilities?.Select(u => AgentUtilityMongoElement.ToMongoElement(u))?.ToList() ?? [], - Mcps = x.Mcps?.Select(u => AgentMcpMongoElement.ToMongoElement(u))?.ToList() ?? [], + Mcps = x.Acps?.Select(u => AgentCPMongoElement.ToMongoElement(u))?.ToList() ?? [], KnowledgeBases = x.KnowledgeBases?.Select(k => AgentKnowledgeBaseMongoElement.ToMongoElement(k))?.ToList() ?? [], Rules = x.Rules?.Select(e => AgentRuleMongoElement.ToMongoElement(e))?.ToList() ?? [], CreatedTime = x.CreatedDateTime, @@ -622,7 +622,7 @@ 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() ?? [], - Mcps = agentDoc.Mcps?.Select(u => AgentMcpMongoElement.ToDomainElement(u))?.ToList() ?? [], + Acps = agentDoc.Mcps?.Select(u => AgentCPMongoElement.ToDomainElement(u))?.ToList() ?? [], KnowledgeBases = agentDoc.KnowledgeBases?.Select(x => AgentKnowledgeBaseMongoElement.ToDomainElement(x))?.ToList() ?? [], Rules = agentDoc.Rules?.Select(e => AgentRuleMongoElement.ToDomainElement(e))?.ToList() ?? [] };