diff --git a/README.md b/README.md index 12541290..aa892ce0 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,7 @@ BotSharp uses component design, the kernel is kept to a minimum, and business fu #### Tools - BotSharp.Plugin.RoutingSpeeder +- BotSharp.Plugin.WebDriver - BotSharp.Plugin.PizzaBot #### UIs diff --git a/docs/static/screenshots/agent-builder-agents.png b/docs/static/screenshots/agent-builder-agents.png index 5f8643a9..db661494 100644 Binary files a/docs/static/screenshots/agent-builder-agents.png and b/docs/static/screenshots/agent-builder-agents.png differ diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs index a36ccc26..6b18b652 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs @@ -62,9 +62,6 @@ public class Agent public bool IsPublic { get; set; } - [JsonIgnore] - public bool IsHost { get; set; } - [JsonIgnore] public PluginDef Plugin { get; set; } diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs index 15be18f9..6f840edb 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs @@ -13,20 +13,12 @@ public partial class AgentService { var agents = _db.GetAgents(filter); - // Set IsRouter var routeSetting = _services.GetRequiredService(); foreach (var agent in agents) { agent.Plugin = GetPlugin(agent.Id); } - // Set IsHost - var agentSetting = _services.GetRequiredService(); - foreach (var agent in agents) - { - agent.IsHost = agentSetting.HostAgentId == agent.Id; - } - agents = agents.Where(x => x.Installed).ToList(); var pager = filter?.Pager ?? new Pagination(); return new PagedItems diff --git a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj index fadeacd1..8f706a7b 100644 --- a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj +++ b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -55,6 +55,10 @@ + + + + @@ -86,6 +90,18 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + PreserveNewest diff --git a/src/Infrastructure/BotSharp.Core/data/agents/01e2fc5c-2c89-4ec7-8470-7688608b496c/agent.json b/src/Infrastructure/BotSharp.Core/data/agents/01e2fc5c-2c89-4ec7-8470-7688608b496c/agent.json index b17531f4..d75a4483 100644 --- a/src/Infrastructure/BotSharp.Core/data/agents/01e2fc5c-2c89-4ec7-8470-7688608b496c/agent.json +++ b/src/Infrastructure/BotSharp.Core/data/agents/01e2fc5c-2c89-4ec7-8470-7688608b496c/agent.json @@ -5,8 +5,7 @@ "type": "task", "createdDateTime": "2024-01-15T10:39:32Z", "updatedDateTime": "2024-01-15T14:39:32Z", - "iconUrl": "/images/users/bot.png", + "iconUrl": "/images/logo.png", "disabled": false, - "isPublic": true, - "profiles": [ "standalone" ] + "isPublic": true } \ No newline at end of file diff --git a/src/Infrastructure/BotSharp.Core/data/agents/dfd9b46d-d00c-40af-8a75-3fbdc2b89869/agent.json b/src/Infrastructure/BotSharp.Core/data/agents/dfd9b46d-d00c-40af-8a75-3fbdc2b89869/agent.json new file mode 100644 index 00000000..e9bac6f5 --- /dev/null +++ b/src/Infrastructure/BotSharp.Core/data/agents/dfd9b46d-d00c-40af-8a75-3fbdc2b89869/agent.json @@ -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" + } +} \ No newline at end of file diff --git a/tests/BotSharp.Plugin.PizzaBot/data/agents/dfd9b46d-d00c-40af-8a75-3fbdc2b89869/instruction.liquid b/src/Infrastructure/BotSharp.Core/data/agents/dfd9b46d-d00c-40af-8a75-3fbdc2b89869/instruction.liquid similarity index 100% rename from tests/BotSharp.Plugin.PizzaBot/data/agents/dfd9b46d-d00c-40af-8a75-3fbdc2b89869/instruction.liquid rename to src/Infrastructure/BotSharp.Core/data/agents/dfd9b46d-d00c-40af-8a75-3fbdc2b89869/instruction.liquid diff --git a/tests/BotSharp.Plugin.PizzaBot/data/agents/dfd9b46d-d00c-40af-8a75-3fbdc2b89869/templates/instruction.executor.liquid b/src/Infrastructure/BotSharp.Core/data/agents/dfd9b46d-d00c-40af-8a75-3fbdc2b89869/templates/instruction.executor.liquid similarity index 100% rename from tests/BotSharp.Plugin.PizzaBot/data/agents/dfd9b46d-d00c-40af-8a75-3fbdc2b89869/templates/instruction.executor.liquid rename to src/Infrastructure/BotSharp.Core/data/agents/dfd9b46d-d00c-40af-8a75-3fbdc2b89869/templates/instruction.executor.liquid diff --git a/tests/BotSharp.Plugin.PizzaBot/data/agents/dfd9b46d-d00c-40af-8a75-3fbdc2b89869/templates/instruction.reviewer.liquid b/src/Infrastructure/BotSharp.Core/data/agents/dfd9b46d-d00c-40af-8a75-3fbdc2b89869/templates/instruction.reviewer.liquid similarity index 100% rename from tests/BotSharp.Plugin.PizzaBot/data/agents/dfd9b46d-d00c-40af-8a75-3fbdc2b89869/templates/instruction.reviewer.liquid rename to src/Infrastructure/BotSharp.Core/data/agents/dfd9b46d-d00c-40af-8a75-3fbdc2b89869/templates/instruction.reviewer.liquid diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs index 9183be01..35873b9e 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs @@ -25,23 +25,37 @@ public class AgentController : ControllerBase [HttpGet("/agent/{id}")] public async Task GetAgent([FromRoute] string id) { - var agent = await _agentService.GetAgent(id); - return AgentViewModel.FromAgent(agent); + var agents = await GetAgents(new AgentFilter + { + AgentIds = new List { id } + }); + return agents.Items.First(); } - + [HttpGet("/agents")] public async Task> GetAgents([FromQuery] AgentFilter filter) { + var agentSetting = _services.GetRequiredService(); var pagedAgents = await _agentService.GetAgents(filter); + + // prerender agent var items = new List(); foreach (var agent in pagedAgents.Items) { var renderedAgent = await _agentService.LoadAgent(agent.Id); 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 { - Items = items.Select(x => AgentViewModel.FromAgent(x)).ToList(), + Items = agents, Count = pagedAgents.Count }; } diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs index 58378ba5..af921621 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs @@ -37,6 +37,7 @@ public class ConversationController : ControllerBase var conversations = await service.GetConversations(filter); var userService = _services.GetRequiredService(); + var agentService = _services.GetRequiredService(); var list = conversations.Items .Select(x => ConversationViewModel.FromSession(x)) .ToList(); @@ -45,6 +46,9 @@ public class ConversationController : ControllerBase { var user = await userService.GetUser(item.User.Id); item.User = UserViewModel.FromUser(user); + + var agent = await agentService.GetAgent(item.AgentId); + item.AgentName = agent.Name; } return new PagedItems diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs index 3c35b3af..536f5b5d 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs @@ -62,7 +62,6 @@ public class AgentViewModel Responses = agent.Responses, Samples = agent.Samples, IsPublic= agent.IsPublic, - IsHost = agent.IsHost, Disabled = agent.Disabled, IconUrl = agent.IconUrl, Profiles = agent.Profiles ?? new List(), diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/ConversationViewModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/ConversationViewModel.cs index a863763e..0823023d 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/ConversationViewModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/ConversationViewModel.cs @@ -9,13 +9,13 @@ public class ConversationViewModel [JsonPropertyName("agent_id")] public string AgentId { get; set; } + [JsonPropertyName("agent_name")] + public string AgentName { get; set; } + public string Title { get; set; } = string.Empty; public UserViewModel User { get; set; } = new UserViewModel(); - [JsonPropertyName("unread_msg_count")] - public int UnreadMsgCount { get; set; } - public string Event { get; set; } public string Channel { get; set; } = ConversationChannel.OpenAPI; diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/agent.json b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/agent.json index 6ed53683..290a88d0 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/agent.json +++ b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/agent.json @@ -9,5 +9,11 @@ "profiles": [ "default" ], "llmConfig": { "max_recursion_depth": 10 - } + }, + "routingRules": [ + { + "type": "fallback", + "redirectTo": "01e2fc5c-2c89-4ec7-8470-7688608b496c" + } + ] } \ No newline at end of file diff --git a/tests/BotSharp.Plugin.PizzaBot/BotSharp.Plugin.PizzaBot.csproj b/tests/BotSharp.Plugin.PizzaBot/BotSharp.Plugin.PizzaBot.csproj index 415fcd70..4328eb4d 100644 --- a/tests/BotSharp.Plugin.PizzaBot/BotSharp.Plugin.PizzaBot.csproj +++ b/tests/BotSharp.Plugin.PizzaBot/BotSharp.Plugin.PizzaBot.csproj @@ -20,6 +20,8 @@ + + @@ -27,11 +29,6 @@ - - - - - @@ -42,6 +39,12 @@ + + PreserveNewest + + + PreserveNewest + PreserveNewest @@ -63,21 +66,6 @@ PreserveNewest - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - PreserveNewest @@ -105,8 +93,4 @@ - - - - diff --git a/tests/BotSharp.Plugin.PizzaBot/PizzaBotPlugin.cs b/tests/BotSharp.Plugin.PizzaBot/PizzaBotPlugin.cs index d3d4c3a6..6fa37ce6 100644 --- a/tests/BotSharp.Plugin.PizzaBot/PizzaBotPlugin.cs +++ b/tests/BotSharp.Plugin.PizzaBot/PizzaBotPlugin.cs @@ -11,6 +11,7 @@ public class PizzaBotPlugin : IBotSharpPlugin public string IconUrl => "https://cdn-icons-png.flaticon.com/512/6978/6978255.png"; public string[] AgentIds => new[] { + "8970b1e5-d260-4e2c-90b1-f1415a257c18", "b284db86-e9c2-4c25-a59e-4649797dd130", "c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd", "dfd9b46d-d00c-40af-8a75-3fbdc2b89869", diff --git a/tests/BotSharp.Plugin.PizzaBot/data/agents/8970b1e5-d260-4e2c-90b1-f1415a257c18/agent.json b/tests/BotSharp.Plugin.PizzaBot/data/agents/8970b1e5-d260-4e2c-90b1-f1415a257c18/agent.json new file mode 100644 index 00000000..e57ba894 --- /dev/null +++ b/tests/BotSharp.Plugin.PizzaBot/data/agents/8970b1e5-d260-4e2c-90b1-f1415a257c18/agent.json @@ -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" + } + ] +} \ No newline at end of file diff --git a/tests/BotSharp.Plugin.PizzaBot/data/agents/dfd9b46d-d00c-40af-8a75-3fbdc2b89869/templates/task.place_pizza_order.liquid b/tests/BotSharp.Plugin.PizzaBot/data/agents/8970b1e5-d260-4e2c-90b1-f1415a257c18/templates/task.place_pizza_order.liquid similarity index 100% rename from tests/BotSharp.Plugin.PizzaBot/data/agents/dfd9b46d-d00c-40af-8a75-3fbdc2b89869/templates/task.place_pizza_order.liquid rename to tests/BotSharp.Plugin.PizzaBot/data/agents/8970b1e5-d260-4e2c-90b1-f1415a257c18/templates/task.place_pizza_order.liquid diff --git a/tests/BotSharp.Plugin.PizzaBot/data/agents/b284db86-e9c2-4c25-a59e-4649797dd130/agent.json b/tests/BotSharp.Plugin.PizzaBot/data/agents/b284db86-e9c2-4c25-a59e-4649797dd130/agent.json index 09c08cb6..949e201c 100644 --- a/tests/BotSharp.Plugin.PizzaBot/data/agents/b284db86-e9c2-4c25-a59e-4649797dd130/agent.json +++ b/tests/BotSharp.Plugin.PizzaBot/data/agents/b284db86-e9c2-4c25-a59e-4649797dd130/agent.json @@ -4,7 +4,7 @@ "createdDateTime": "2023-08-18T14:39:32.2349685Z", "updatedDateTime": "2023-08-18T14:39:32.2349686Z", "id": "b284db86-e9c2-4c25-a59e-4649797dd130", - "allowRouting": true, + "disabled": true, "isPublic": true, "profiles": [ "pizza" ], "routingRules": [ diff --git a/tests/BotSharp.Plugin.PizzaBot/data/agents/c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd/agent.json b/tests/BotSharp.Plugin.PizzaBot/data/agents/c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd/agent.json index 23323f63..4751fb78 100644 --- a/tests/BotSharp.Plugin.PizzaBot/data/agents/c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd/agent.json +++ b/tests/BotSharp.Plugin.PizzaBot/data/agents/c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd/agent.json @@ -4,7 +4,7 @@ "createdDateTime": "2023-07-26T02:29:25.123224Z", "updatedDateTime": "2023-07-26T02:29:25.123274Z", "id": "c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd", - "allowRouting": true, + "disabled": true, "isPublic": true, "profiles": [ "pizza" ] } \ No newline at end of file diff --git a/tests/BotSharp.Plugin.PizzaBot/data/agents/dfd9b46d-d00c-40af-8a75-3fbdc2b89869/agent.json b/tests/BotSharp.Plugin.PizzaBot/data/agents/dfd9b46d-d00c-40af-8a75-3fbdc2b89869/agent.json deleted file mode 100644 index 26f15972..00000000 --- a/tests/BotSharp.Plugin.PizzaBot/data/agents/dfd9b46d-d00c-40af-8a75-3fbdc2b89869/agent.json +++ /dev/null @@ -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" - } - } \ No newline at end of file diff --git a/tests/BotSharp.Plugin.PizzaBot/data/agents/fe8c60aa-b114-4ef3-93cb-a8efeac80f75/agent.json b/tests/BotSharp.Plugin.PizzaBot/data/agents/fe8c60aa-b114-4ef3-93cb-a8efeac80f75/agent.json index eba914f7..af5d6cd9 100644 --- a/tests/BotSharp.Plugin.PizzaBot/data/agents/fe8c60aa-b114-4ef3-93cb-a8efeac80f75/agent.json +++ b/tests/BotSharp.Plugin.PizzaBot/data/agents/fe8c60aa-b114-4ef3-93cb-a8efeac80f75/agent.json @@ -4,8 +4,9 @@ "createdDateTime": "2023-07-26T02:29:25.123224Z", "updatedDateTime": "2023-07-26T02:29:25.123274Z", "id": "fe8c60aa-b114-4ef3-93cb-a8efeac80f75", - "allowRouting": true, + "disabled": true, "isPublic": true, + "profiles": [ "pizza" ], "routingRules": [ { "field": "order_number",