pub trait AgentPluginSupport: MoFAAgent {
// Required methods
fn register_plugin(
&mut self,
plugin: Box<dyn AgentPlugin>,
) -> AgentResult<()>;
fn unregister_plugin(&mut self, plugin_id: &str) -> AgentResult<()>;
}Expand description
Agent 插件支持扩展
提供插件管理能力,允许在运行时动态扩展 Agent 功能。 这个 trait 是可选的,只有需要插件系统的 Agent 才需要实现。
§提供的方法
register_plugin()- 注册插件unregister_plugin()- 注销插件
§示例
ⓘ
use mofa_kernel::agent::core::AgentPluginSupport;
#[async_trait]
impl AgentPluginSupport for MyAgent {
fn register_plugin(&mut self, plugin: Box<dyn AgentPlugin>) -> AgentResult<()> {
self.plugins.push(plugin);
Ok(())
}
fn unregister_plugin(&mut self, plugin_id: &str) -> AgentResult<()> {
self.plugins.retain(|p| p.id() != plugin_id);
Ok(())
}
}