Add AgentFilter.
This commit is contained in:
parent
27e0c4b307
commit
1286f35d8b
BIN
docs/static/screenshots/agent-builder-agents.png
vendored
BIN
docs/static/screenshots/agent-builder-agents.png
vendored
Binary file not shown.
|
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 124 KiB |
|
|
@ -1,3 +1,5 @@
|
|||
using BotSharp.Abstraction.Repositories.Filters;
|
||||
|
||||
namespace BotSharp.Abstraction.Agents;
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -7,7 +9,7 @@ public interface IAgentService
|
|||
{
|
||||
Task<Agent> CreateAgent(Agent agent);
|
||||
Task RefreshAgents();
|
||||
Task<List<Agent>> GetAgents(bool? allowRouting = null);
|
||||
Task<List<Agent>> GetAgents(AgentFilter filter);
|
||||
|
||||
/// <summary>
|
||||
/// Load agent configurations and trigger hooks
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ public class Agent
|
|||
public bool AllowRouting { get; set; }
|
||||
|
||||
public bool Disabled { get; set; }
|
||||
public string IconUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Profile by channel
|
||||
|
|
|
|||
|
|
@ -6,5 +6,6 @@ public class AgentFilter
|
|||
public bool? Disabled { get; set; }
|
||||
public bool? AllowRouting { get; set; }
|
||||
public bool? IsPublic { get; set; }
|
||||
public bool? IsRouter { get; set; }
|
||||
public List<string>? AgentIds { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,9 +8,8 @@ public partial class AgentService
|
|||
#if !DEBUG
|
||||
[MemoryCache(10 * 60)]
|
||||
#endif
|
||||
public async Task<List<Agent>> GetAgents(bool? allowRouting = null)
|
||||
public async Task<List<Agent>> GetAgents(AgentFilter filter)
|
||||
{
|
||||
var filter = new AgentFilter { AllowRouting = allowRouting };
|
||||
var agents = _db.GetAgents(filter);
|
||||
return await Task.FromResult(agents);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using BotSharp.Abstraction.Agents.Models;
|
||||
using BotSharp.Abstraction.Functions.Models;
|
||||
using BotSharp.Abstraction.Planning;
|
||||
using BotSharp.Abstraction.Repositories.Filters;
|
||||
using BotSharp.Abstraction.Routing.Models;
|
||||
using BotSharp.Abstraction.Routing.Settings;
|
||||
using BotSharp.Abstraction.Templating;
|
||||
|
|
@ -108,7 +109,10 @@ public class NaivePlanner : IPlaner
|
|||
private void FixMalformedResponse(FunctionCallFromLlm args)
|
||||
{
|
||||
var agentService = _services.GetRequiredService<IAgentService>();
|
||||
var agents = agentService.GetAgents(allowRouting: true).Result;
|
||||
var agents = agentService.GetAgents(new AgentFilter
|
||||
{
|
||||
AllowRouting = true
|
||||
}).Result;
|
||||
var malformed = false;
|
||||
|
||||
// Sometimes it populate malformed Function in Agent name
|
||||
|
|
|
|||
|
|
@ -6,24 +6,26 @@ using BotSharp.Abstraction.Agents.Models;
|
|||
using MongoDB.Driver;
|
||||
using BotSharp.Abstraction.Routing.Models;
|
||||
using BotSharp.Abstraction.Repositories.Filters;
|
||||
using BotSharp.Abstraction.Utilities;
|
||||
using BotSharp.Abstraction.Conversations.Models;
|
||||
using BotSharp.Abstraction.Repositories.Models;
|
||||
using BotSharp.Abstraction.Routing.Settings;
|
||||
|
||||
namespace BotSharp.Core.Repository;
|
||||
|
||||
public class FileRepository : IBotSharpRepository
|
||||
{
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly BotSharpDatabaseSettings _dbSettings;
|
||||
private readonly AgentSettings _agentSettings;
|
||||
private readonly ConversationSetting _conversationSettings;
|
||||
private JsonSerializerOptions _options;
|
||||
|
||||
public FileRepository(
|
||||
IServiceProvider services,
|
||||
BotSharpDatabaseSettings dbSettings,
|
||||
AgentSettings agentSettings,
|
||||
ConversationSetting conversationSettings)
|
||||
{
|
||||
_services = services;
|
||||
_dbSettings = dbSettings;
|
||||
_agentSettings = agentSettings;
|
||||
_conversationSettings = conversationSettings;
|
||||
|
|
@ -542,6 +544,14 @@ public class FileRepository : IBotSharpRepository
|
|||
query = query.Where(x => x.IsPublic == filter.IsPublic);
|
||||
}
|
||||
|
||||
if (filter.IsRouter.HasValue)
|
||||
{
|
||||
var route = _services.GetRequiredService<RoutingSettings>();
|
||||
query = filter.IsRouter.Value ?
|
||||
query.Where(x => x.Id == route.AgentId) :
|
||||
query.Where(x => x.Id != route.AgentId);
|
||||
}
|
||||
|
||||
if (filter.AgentIds != null)
|
||||
{
|
||||
query = query.Where(x => filter.AgentIds.Contains(x.Id));
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ public class AgentController : ControllerBase
|
|||
}
|
||||
|
||||
[HttpGet("/agents")]
|
||||
public async Task<List<AgentViewModel>> GetAgents()
|
||||
public async Task<List<AgentViewModel>> GetAgents([FromQuery] AgentFilter filter)
|
||||
{
|
||||
var agents = await _agentService.GetAgents();
|
||||
var agents = await _agentService.GetAgents(filter);
|
||||
return agents.Select(x => AgentViewModel.FromAgent(x)).ToList();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ public class AgentViewModel
|
|||
[JsonPropertyName("allow_routing")]
|
||||
public bool AllowRouting { get; set; }
|
||||
public bool Disabled { get; set; }
|
||||
[JsonPropertyName("icon_url")]
|
||||
public string IconUrl { get; set; }
|
||||
public List<string> Profiles { get; set; }
|
||||
|
||||
[JsonPropertyName("routing_rules")]
|
||||
|
|
@ -51,6 +53,7 @@ public class AgentViewModel
|
|||
Samples = agent.Samples,
|
||||
IsPublic= agent.IsPublic,
|
||||
Disabled = agent.Disabled,
|
||||
IconUrl = agent.IconUrl,
|
||||
AllowRouting = agent.AllowRouting,
|
||||
Profiles = agent.Profiles,
|
||||
RoutingRules = agent.RoutingRules,
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using BotSharp.Abstraction.Functions.Models;
|
|||
using BotSharp.Abstraction.Repositories.Filters;
|
||||
using BotSharp.Abstraction.Repositories.Models;
|
||||
using BotSharp.Abstraction.Routing.Models;
|
||||
using BotSharp.Abstraction.Routing.Settings;
|
||||
using BotSharp.Abstraction.Users.Models;
|
||||
using BotSharp.Plugin.MongoStorage.Collections;
|
||||
using BotSharp.Plugin.MongoStorage.Models;
|
||||
|
|
@ -461,6 +462,14 @@ public class MongoRepository : IBotSharpRepository
|
|||
query = query.Where(x => x.IsPublic == filter.IsPublic);
|
||||
}
|
||||
|
||||
if (filter.IsRouter.HasValue)
|
||||
{
|
||||
var route = _services.GetRequiredService<RoutingSettings>();
|
||||
query = filter.IsRouter.Value ?
|
||||
query.Where(x => x.Id == route.AgentId) :
|
||||
query.Where(x => x.Id != route.AgentId);
|
||||
}
|
||||
|
||||
if (filter.AgentIds != null)
|
||||
{
|
||||
query = query.Where(x => filter.AgentIds.Contains(x.Id));
|
||||
|
|
|
|||
|
|
@ -71,4 +71,9 @@ app.UseBotSharp();
|
|||
app.UseCors("MyCorsPolicy");
|
||||
#endif
|
||||
|
||||
// Host BotSharp UI built in adapter-static
|
||||
app.UseFileServer();
|
||||
app.UseDefaultFiles();
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.Run();
|
||||
|
|
|
|||
|
|
@ -68,5 +68,9 @@
|
|||
<ProjectReference Include="..\Plugins\BotSharp.Plugin.ChatHub\BotSharp.Plugin.ChatHub.csproj" />
|
||||
<ProjectReference Include="..\Plugins\BotSharp.Plugin.TelegramBots\BotSharp.Plugin.TelegramBots.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="wwwroot\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -4,5 +4,6 @@
|
|||
"createdDateTime": "2023-08-18T14:39:32.2349685Z",
|
||||
"updatedDateTime": "2023-08-18T14:39:32.2349686Z",
|
||||
"id": "01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a",
|
||||
"iconUrl": "https://cdn.iconscout.com/icon/premium/png-256-thumb/route-1613278-1368497.png",
|
||||
"isPublic": true
|
||||
}
|
||||
BIN
src/WebStarter/wwwroot/favicon.ico
Normal file
BIN
src/WebStarter/wwwroot/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
Binary file not shown.
Binary file not shown.
Loading…
Reference in a new issue