From 8d798a43993e065c66e2f1f5131fd09ce23f2e8a Mon Sep 17 00:00:00 2001 From: Jicheng Lu Date: Mon, 24 Jun 2024 23:34:30 -0500 Subject: [PATCH] add agent tools api --- .../BotSharp.Abstraction/Agents/IAgentService.cs | 2 ++ .../BotSharp.Core/Agents/Services/AgentService.cs | 11 +++++++++++ .../BotSharp.OpenAPI/Controllers/AgentController.cs | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs index b435a4d1..c2368cd2 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs @@ -51,4 +51,6 @@ public interface IAgentService List GetAgentsByUser(string userId); PluginDef GetPlugin(string agentId); + + IEnumerable GetAgentTools(); } diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs index da1b8cf1..69e67c30 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs @@ -1,4 +1,5 @@ using System.IO; +using System.Reflection; namespace BotSharp.Core.Agents.Services; @@ -53,4 +54,14 @@ public partial class AgentService : IAgentService var agents = _db.GetAgentsByUser(userId); return agents; } + + public IEnumerable GetAgentTools() + { + var tools = typeof(AgentTool).GetFields(BindingFlags.Public | BindingFlags.Static) + .Where(f => f.IsLiteral && f.FieldType == typeof(string)) + .Select(x => x.GetRawConstantValue()?.ToString()) + .ToList(); + + return tools; + } } diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs index a7b5652d..5d34ec77 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs @@ -140,4 +140,10 @@ public class AgentController : ControllerBase { return await _agentService.DeleteAgent(agentId); } + + [HttpGet("/agent/tools")] + public IEnumerable GetAgentTools() + { + return _agentService.GetAgentTools(); + } } \ No newline at end of file