Add pizza bot router.

This commit is contained in:
Haiping Chen 2024-01-27 19:02:33 -06:00
parent 2445cb31e0
commit 2b6c2353b6
23 changed files with 94 additions and 61 deletions

View file

@ -103,6 +103,7 @@ BotSharp uses component design, the kernel is kept to a minimum, and business fu
#### Tools #### Tools
- BotSharp.Plugin.RoutingSpeeder - BotSharp.Plugin.RoutingSpeeder
- BotSharp.Plugin.WebDriver
- BotSharp.Plugin.PizzaBot - BotSharp.Plugin.PizzaBot
#### UIs #### UIs

Binary file not shown.

Before

Width:  |  Height:  |  Size: 124 KiB

After

Width:  |  Height:  |  Size: 107 KiB

View file

@ -62,9 +62,6 @@ public class Agent
public bool IsPublic { get; set; } public bool IsPublic { get; set; }
[JsonIgnore]
public bool IsHost { get; set; }
[JsonIgnore] [JsonIgnore]
public PluginDef Plugin { get; set; } public PluginDef Plugin { get; set; }

View file

@ -13,20 +13,12 @@ public partial class AgentService
{ {
var agents = _db.GetAgents(filter); var agents = _db.GetAgents(filter);
// Set IsRouter
var routeSetting = _services.GetRequiredService<RoutingSettings>(); var routeSetting = _services.GetRequiredService<RoutingSettings>();
foreach (var agent in agents) foreach (var agent in agents)
{ {
agent.Plugin = GetPlugin(agent.Id); agent.Plugin = GetPlugin(agent.Id);
} }
// Set IsHost
var agentSetting = _services.GetRequiredService<AgentSettings>();
foreach (var agent in agents)
{
agent.IsHost = agentSetting.HostAgentId == agent.Id;
}
agents = agents.Where(x => x.Installed).ToList(); agents = agents.Where(x => x.Installed).ToList();
var pager = filter?.Pager ?? new Pagination(); var pager = filter?.Pager ?? new Pagination();
return new PagedItems<Agent> return new PagedItems<Agent>

View file

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework> <TargetFramework>netstandard2.1</TargetFramework>
@ -55,6 +55,10 @@
<None Remove="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\planner_prompt.sequential.liquid" /> <None Remove="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\planner_prompt.sequential.liquid" />
<None Remove="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\response_with_function.liquid" /> <None Remove="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\response_with_function.liquid" />
<None Remove="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\welcome.liquid" /> <None Remove="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\welcome.liquid" />
<None Remove="data\agents\dfd9b46d-d00c-40af-8a75-3fbdc2b89869\agent.json" />
<None Remove="data\agents\dfd9b46d-d00c-40af-8a75-3fbdc2b89869\instruction.liquid" />
<None Remove="data\agents\dfd9b46d-d00c-40af-8a75-3fbdc2b89869\templates\instruction.executor.liquid" />
<None Remove="data\agents\dfd9b46d-d00c-40af-8a75-3fbdc2b89869\templates\instruction.reviewer.liquid" />
<None Remove="data\plugins\config.json" /> <None Remove="data\plugins\config.json" />
</ItemGroup> </ItemGroup>
@ -86,6 +90,18 @@
<Content Include="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\welcome.liquid"> <Content Include="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\welcome.liquid">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="data\agents\dfd9b46d-d00c-40af-8a75-3fbdc2b89869\agent.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="data\agents\dfd9b46d-d00c-40af-8a75-3fbdc2b89869\instruction.liquid">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="data\agents\dfd9b46d-d00c-40af-8a75-3fbdc2b89869\templates\instruction.executor.liquid">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="data\agents\dfd9b46d-d00c-40af-8a75-3fbdc2b89869\templates\instruction.reviewer.liquid">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="data\plugins\config.json"> <Content Include="data\plugins\config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>

View file

@ -5,8 +5,7 @@
"type": "task", "type": "task",
"createdDateTime": "2024-01-15T10:39:32Z", "createdDateTime": "2024-01-15T10:39:32Z",
"updatedDateTime": "2024-01-15T14:39:32Z", "updatedDateTime": "2024-01-15T14:39:32Z",
"iconUrl": "/images/users/bot.png", "iconUrl": "/images/logo.png",
"disabled": false, "disabled": false,
"isPublic": true, "isPublic": true
"profiles": [ "standalone" ]
} }

View file

@ -0,0 +1,11 @@
{
"id": "dfd9b46d-d00c-40af-8a75-3fbdc2b89869",
"name": "Evaluator",
"description": "Evaluate the performance of the LLM agents",
"createdDateTime": "2023-08-18T00:00:00Z",
"updatedDateTime": "2023-08-18T00:00:00Z",
"disabled": true,
"llmConfig": {
"model": "gpt-35-turbo-instruct"
}
}

View file

@ -25,23 +25,37 @@ public class AgentController : ControllerBase
[HttpGet("/agent/{id}")] [HttpGet("/agent/{id}")]
public async Task<AgentViewModel> GetAgent([FromRoute] string id) public async Task<AgentViewModel> GetAgent([FromRoute] string id)
{ {
var agent = await _agentService.GetAgent(id); var agents = await GetAgents(new AgentFilter
return AgentViewModel.FromAgent(agent); {
AgentIds = new List<string> { id }
});
return agents.Items.First();
} }
[HttpGet("/agents")] [HttpGet("/agents")]
public async Task<PagedItems<AgentViewModel>> GetAgents([FromQuery] AgentFilter filter) public async Task<PagedItems<AgentViewModel>> GetAgents([FromQuery] AgentFilter filter)
{ {
var agentSetting = _services.GetRequiredService<AgentSettings>();
var pagedAgents = await _agentService.GetAgents(filter); var pagedAgents = await _agentService.GetAgents(filter);
// prerender agent
var items = new List<Agent>(); var items = new List<Agent>();
foreach (var agent in pagedAgents.Items) foreach (var agent in pagedAgents.Items)
{ {
var renderedAgent = await _agentService.LoadAgent(agent.Id); var renderedAgent = await _agentService.LoadAgent(agent.Id);
items.Add(renderedAgent); items.Add(renderedAgent);
} }
// Set IsHost
var agents = items.Select(x => AgentViewModel.FromAgent(x)).ToList();
foreach(var agent in agents)
{
agent.IsHost = agentSetting.HostAgentId == agent.Id;
}
return new PagedItems<AgentViewModel> return new PagedItems<AgentViewModel>
{ {
Items = items.Select(x => AgentViewModel.FromAgent(x)).ToList(), Items = agents,
Count = pagedAgents.Count Count = pagedAgents.Count
}; };
} }

View file

@ -37,6 +37,7 @@ public class ConversationController : ControllerBase
var conversations = await service.GetConversations(filter); var conversations = await service.GetConversations(filter);
var userService = _services.GetRequiredService<IUserService>(); var userService = _services.GetRequiredService<IUserService>();
var agentService = _services.GetRequiredService<IAgentService>();
var list = conversations.Items var list = conversations.Items
.Select(x => ConversationViewModel.FromSession(x)) .Select(x => ConversationViewModel.FromSession(x))
.ToList(); .ToList();
@ -45,6 +46,9 @@ public class ConversationController : ControllerBase
{ {
var user = await userService.GetUser(item.User.Id); var user = await userService.GetUser(item.User.Id);
item.User = UserViewModel.FromUser(user); item.User = UserViewModel.FromUser(user);
var agent = await agentService.GetAgent(item.AgentId);
item.AgentName = agent.Name;
} }
return new PagedItems<ConversationViewModel> return new PagedItems<ConversationViewModel>

View file

@ -62,7 +62,6 @@ public class AgentViewModel
Responses = agent.Responses, Responses = agent.Responses,
Samples = agent.Samples, Samples = agent.Samples,
IsPublic= agent.IsPublic, IsPublic= agent.IsPublic,
IsHost = agent.IsHost,
Disabled = agent.Disabled, Disabled = agent.Disabled,
IconUrl = agent.IconUrl, IconUrl = agent.IconUrl,
Profiles = agent.Profiles ?? new List<string>(), Profiles = agent.Profiles ?? new List<string>(),

View file

@ -9,13 +9,13 @@ public class ConversationViewModel
[JsonPropertyName("agent_id")] [JsonPropertyName("agent_id")]
public string AgentId { get; set; } public string AgentId { get; set; }
[JsonPropertyName("agent_name")]
public string AgentName { get; set; }
public string Title { get; set; } = string.Empty; public string Title { get; set; } = string.Empty;
public UserViewModel User { get; set; } = new UserViewModel(); public UserViewModel User { get; set; } = new UserViewModel();
[JsonPropertyName("unread_msg_count")]
public int UnreadMsgCount { get; set; }
public string Event { get; set; } public string Event { get; set; }
public string Channel { get; set; } = ConversationChannel.OpenAPI; public string Channel { get; set; } = ConversationChannel.OpenAPI;

View file

@ -9,5 +9,11 @@
"profiles": [ "default" ], "profiles": [ "default" ],
"llmConfig": { "llmConfig": {
"max_recursion_depth": 10 "max_recursion_depth": 10
} },
"routingRules": [
{
"type": "fallback",
"redirectTo": "01e2fc5c-2c89-4ec7-8470-7688608b496c"
}
]
} }

View file

@ -20,6 +20,8 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Remove="data\agents\8970b1e5-d260-4e2c-90b1-f1415a257c18\agent.json" />
<None Remove="data\agents\8970b1e5-d260-4e2c-90b1-f1415a257c18\templates\task.place_pizza_order.liquid" />
<None Remove="data\agents\b284db86-e9c2-4c25-a59e-4649797dd130\agent.json" /> <None Remove="data\agents\b284db86-e9c2-4c25-a59e-4649797dd130\agent.json" />
<None Remove="data\agents\b284db86-e9c2-4c25-a59e-4649797dd130\functions.json" /> <None Remove="data\agents\b284db86-e9c2-4c25-a59e-4649797dd130\functions.json" />
<None Remove="data\agents\b284db86-e9c2-4c25-a59e-4649797dd130\instruction.liquid" /> <None Remove="data\agents\b284db86-e9c2-4c25-a59e-4649797dd130\instruction.liquid" />
@ -27,11 +29,6 @@
<None Remove="data\agents\c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd\functions.json" /> <None Remove="data\agents\c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd\functions.json" />
<None Remove="data\agents\c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd\instruction.liquid" /> <None Remove="data\agents\c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd\instruction.liquid" />
<None Remove="data\agents\c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd\responses\func.get_pizza_price.0.liquid" /> <None Remove="data\agents\c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd\responses\func.get_pizza_price.0.liquid" />
<None Remove="data\agents\dfd9b46d-d00c-40af-8a75-3fbdc2b89869\agent.json" />
<None Remove="data\agents\dfd9b46d-d00c-40af-8a75-3fbdc2b89869\instruction.liquid" />
<None Remove="data\agents\dfd9b46d-d00c-40af-8a75-3fbdc2b89869\templates\instruction.executor.liquid" />
<None Remove="data\agents\dfd9b46d-d00c-40af-8a75-3fbdc2b89869\templates\instruction.reviewer.liquid" />
<None Remove="data\agents\dfd9b46d-d00c-40af-8a75-3fbdc2b89869\templates\task.place_pizza_order.liquid" />
<None Remove="data\agents\fe8c60aa-b114-4ef3-93cb-a8efeac80f75\agent.json" /> <None Remove="data\agents\fe8c60aa-b114-4ef3-93cb-a8efeac80f75\agent.json" />
<None Remove="data\agents\fe8c60aa-b114-4ef3-93cb-a8efeac80f75\functions.json" /> <None Remove="data\agents\fe8c60aa-b114-4ef3-93cb-a8efeac80f75\functions.json" />
<None Remove="data\agents\fe8c60aa-b114-4ef3-93cb-a8efeac80f75\instruction.liquid" /> <None Remove="data\agents\fe8c60aa-b114-4ef3-93cb-a8efeac80f75\instruction.liquid" />
@ -42,6 +39,12 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="data\agents\8970b1e5-d260-4e2c-90b1-f1415a257c18\agent.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="data\agents\8970b1e5-d260-4e2c-90b1-f1415a257c18\templates\task.place_pizza_order.liquid">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="data\agents\b284db86-e9c2-4c25-a59e-4649797dd130\agent.json"> <Content Include="data\agents\b284db86-e9c2-4c25-a59e-4649797dd130\agent.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
@ -63,21 +66,6 @@
<Content Include="data\agents\c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd\responses\func.get_pizza_price.0.liquid"> <Content Include="data\agents\c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd\responses\func.get_pizza_price.0.liquid">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="data\agents\dfd9b46d-d00c-40af-8a75-3fbdc2b89869\agent.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="data\agents\dfd9b46d-d00c-40af-8a75-3fbdc2b89869\instruction.liquid">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="data\agents\dfd9b46d-d00c-40af-8a75-3fbdc2b89869\templates\instruction.executor.liquid">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="data\agents\dfd9b46d-d00c-40af-8a75-3fbdc2b89869\templates\instruction.reviewer.liquid">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="data\agents\dfd9b46d-d00c-40af-8a75-3fbdc2b89869\templates\task.place_pizza_order.liquid">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="data\agents\fe8c60aa-b114-4ef3-93cb-a8efeac80f75\agent.json"> <Content Include="data\agents\fe8c60aa-b114-4ef3-93cb-a8efeac80f75\agent.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
@ -105,8 +93,4 @@
<ProjectReference Include="..\..\src\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" /> <ProjectReference Include="..\..\src\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="data\agents\NewFolder\" />
</ItemGroup>
</Project> </Project>

View file

@ -11,6 +11,7 @@ public class PizzaBotPlugin : IBotSharpPlugin
public string IconUrl => "https://cdn-icons-png.flaticon.com/512/6978/6978255.png"; public string IconUrl => "https://cdn-icons-png.flaticon.com/512/6978/6978255.png";
public string[] AgentIds => new[] public string[] AgentIds => new[]
{ {
"8970b1e5-d260-4e2c-90b1-f1415a257c18",
"b284db86-e9c2-4c25-a59e-4649797dd130", "b284db86-e9c2-4c25-a59e-4649797dd130",
"c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd", "c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd",
"dfd9b46d-d00c-40af-8a75-3fbdc2b89869", "dfd9b46d-d00c-40af-8a75-3fbdc2b89869",

View file

@ -0,0 +1,18 @@
{
"id": "8970b1e5-d260-4e2c-90b1-f1415a257c18",
"name": "Pizza Bot",
"description": "AI assistant that can help customer place pizza order.",
"type": "routing",
"createdDateTime": "2023-08-18T10:39:32.2349685Z",
"updatedDateTime": "2023-08-18T14:39:32.2349686Z",
"iconUrl": "https://cdn-icons-png.flaticon.com/512/6978/6978255.png",
"disabled": true,
"isPublic": true,
"profiles": [ "pizza" ],
"routingRules": [
{
"type": "planner",
"field": "NaviePlanner"
}
]
}

View file

@ -4,7 +4,7 @@
"createdDateTime": "2023-08-18T14:39:32.2349685Z", "createdDateTime": "2023-08-18T14:39:32.2349685Z",
"updatedDateTime": "2023-08-18T14:39:32.2349686Z", "updatedDateTime": "2023-08-18T14:39:32.2349686Z",
"id": "b284db86-e9c2-4c25-a59e-4649797dd130", "id": "b284db86-e9c2-4c25-a59e-4649797dd130",
"allowRouting": true, "disabled": true,
"isPublic": true, "isPublic": true,
"profiles": [ "pizza" ], "profiles": [ "pizza" ],
"routingRules": [ "routingRules": [

View file

@ -4,7 +4,7 @@
"createdDateTime": "2023-07-26T02:29:25.123224Z", "createdDateTime": "2023-07-26T02:29:25.123224Z",
"updatedDateTime": "2023-07-26T02:29:25.123274Z", "updatedDateTime": "2023-07-26T02:29:25.123274Z",
"id": "c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd", "id": "c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd",
"allowRouting": true, "disabled": true,
"isPublic": true, "isPublic": true,
"profiles": [ "pizza" ] "profiles": [ "pizza" ]
} }

View file

@ -1,10 +0,0 @@
{
"name": "EvaluationAgent",
"description": "Evaluate the performance of the LLM agents",
"createdDateTime": "2023-08-18T00:00:00Z",
"updatedDateTime": "2023-08-18T00:00:00Z",
"id": "dfd9b46d-d00c-40af-8a75-3fbdc2b89869",
"llmConfig": {
"model": "gpt-35-turbo-instruct"
}
}

View file

@ -4,8 +4,9 @@
"createdDateTime": "2023-07-26T02:29:25.123224Z", "createdDateTime": "2023-07-26T02:29:25.123224Z",
"updatedDateTime": "2023-07-26T02:29:25.123274Z", "updatedDateTime": "2023-07-26T02:29:25.123274Z",
"id": "fe8c60aa-b114-4ef3-93cb-a8efeac80f75", "id": "fe8c60aa-b114-4ef3-93cb-a8efeac80f75",
"allowRouting": true, "disabled": true,
"isPublic": true, "isPublic": true,
"profiles": [ "pizza" ],
"routingRules": [ "routingRules": [
{ {
"field": "order_number", "field": "order_number",