add agent tools api

This commit is contained in:
Jicheng Lu 2024-06-24 23:34:30 -05:00
parent f65eeddb8e
commit 8d798a4399
3 changed files with 19 additions and 0 deletions

View file

@ -51,4 +51,6 @@ public interface IAgentService
List<Agent> GetAgentsByUser(string userId);
PluginDef GetPlugin(string agentId);
IEnumerable<string> GetAgentTools();
}

View file

@ -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<string> 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;
}
}

View file

@ -140,4 +140,10 @@ public class AgentController : ControllerBase
{
return await _agentService.DeleteAgent(agentId);
}
[HttpGet("/agent/tools")]
public IEnumerable<string> GetAgentTools()
{
return _agentService.GetAgentTools();
}
}