Skip to main content

AgentPluginSupport

Trait AgentPluginSupport 

Source
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(())
    }
}

Required Methods§

Source

fn register_plugin(&mut self, plugin: Box<dyn AgentPlugin>) -> AgentResult<()>

注册插件

向 Agent 注册一个新插件,扩展其功能。

§参数
  • plugin: 插件对象,实现 AgentPlugin trait
§返回

返回错误如果插件已存在或注册失败

Source

fn unregister_plugin(&mut self, plugin_id: &str) -> AgentResult<()>

注销插件

从 Agent 中移除一个插件。

§参数
  • plugin_id: 要移除的插件 ID
§返回

返回错误如果插件不存在

Implementors§