Add AgentIds to IBotSharpPlugin

This commit is contained in:
Haiping Chen 2024-01-12 18:31:25 -06:00
parent dadb0b49e0
commit 39a6d2ed05
7 changed files with 32 additions and 8 deletions

View file

@ -17,7 +17,7 @@ public interface IBotSharpPlugin
/// <summary>
/// Has build-in agent profile with this plugin
/// </summary>
bool WithAgent => false;
string[] AgentIds => new string[0];
void RegisterDI(IServiceCollection services, IConfiguration config);

View file

@ -9,8 +9,8 @@ public class PluginDef
[JsonPropertyName("icon_url")]
public string IconUrl { get; set; }
[JsonPropertyName("with_agent")]
public bool WithAgent { get; set; }
[JsonPropertyName("agent_ids")]
public string[] AgentIds { get; set; }
public bool Enabled { get; set; }

View file

@ -56,7 +56,7 @@ public class PluginLoader
Description = module.Description,
Assembly = assemblyName,
IconUrl = module.IconUrl,
WithAgent = module.WithAgent,
AgentIds = module.AgentIds,
Menus = module.GetMenus(),
});
Console.Write($"Loaded plugin ");
@ -104,6 +104,15 @@ public class PluginLoader
config.EnabledPlugins.Add(id);
db.SavePluginConfig(config);
}
// enable agents
var agentService = services.GetRequiredService<IAgentService>();
foreach (var agentId in plugin.AgentIds)
{
var agent = agentService.LoadAgent(agentId).Result;
agent.Disabled = false;
agentService.UpdateAgent(agent, AgentField.Disabled);
}
}
else
{
@ -112,6 +121,15 @@ public class PluginLoader
config.EnabledPlugins.Remove(id);
db.SavePluginConfig(config);
}
// disable agents
var agentService = services.GetRequiredService<IAgentService>();
foreach (var agentId in plugin.AgentIds)
{
var agent = agentService.LoadAgent(agentId).Result;
agent.Disabled = true;
agentService.UpdateAgent(agent, AgentField.Disabled);
}
}
return plugin;
}

View file

@ -8,7 +8,7 @@ public class HttpHandlerPlugin : IBotSharpPlugin
public string Name => "HTTP Handler";
public string Description => "Empower agent to handle HTTP request in RESTful API or GraphQL";
public string IconUrl => "https://lirp.cdn-website.com/6f8d6d8a/dms3rep/multi/opt/API_Icon-640w.png";
public bool WithAgent => true;
public string[] AgentIds => new[] { "87c458fc-ec5f-40ae-8ed6-05dda8a07523" };
public void RegisterDI(IServiceCollection services, IConfiguration config)
{

View file

@ -9,7 +9,7 @@ public class KnowledgeBasePlugin : IBotSharpPlugin
public string Name => "Knowledge Base";
public string Description => "Embedding private data and feed them into LLM in the conversation.";
public string IconUrl => "https://cdn-icons-png.flaticon.com/512/9592/9592995.png";
public bool WithAgent => true;
public string[] AgentIds => new[] { "f5679799-ba89-4fef-936a-bcc311e5f14d" };
public void RegisterDI(IServiceCollection services, IConfiguration config)
{

View file

@ -10,7 +10,7 @@ public class WebDriverPlugin : IBotSharpPlugin
public string Name => "Web Driver";
public string Description => "Empower agent to manipulate web browser in automation tools.";
public string IconUrl => "https://cdn-icons-png.flaticon.com/512/8576/8576378.png";
public bool WithAgent => true;
public string[] AgentIds => new[] { "f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b" };
public void RegisterDI(IServiceCollection services, IConfiguration config)
{

View file

@ -9,7 +9,13 @@ public class PizzaBotPlugin : IBotSharpPlugin
public string Name => "Pizza AI Assistant";
public string Description => "An example of an enterprise-grade AI Chatbot.";
public string IconUrl => "https://cdn-icons-png.flaticon.com/512/6978/6978255.png";
public bool WithAgent => true;
public string[] AgentIds => new[]
{
"b284db86-e9c2-4c25-a59e-4649797dd130",
"c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd",
"dfd9b46d-d00c-40af-8a75-3fbdc2b89869",
"fe8c60aa-b114-4ef3-93cb-a8efeac80f75"
};
public void RegisterDI(IServiceCollection services, IConfiguration config)
{