Skip to main content

AgentFactory

Trait AgentFactory 

Source
pub trait AgentFactory: Send + Sync {
    // Required methods
    fn create<'life0, 'async_trait>(
        &'life0 self,
        config: AgentConfig,
    ) -> Pin<Box<dyn Future<Output = Result<Arc<RwLock<dyn MoFAAgent>>, AgentError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
    fn type_id(&self) -> &str;
    fn default_capabilities(&self) -> AgentCapabilities;

    // Provided methods
    fn validate_config(&self, config: &AgentConfig) -> Result<(), AgentError> { ... }
    fn description(&self) -> Option<&str> { ... }
}
Expand description

Agent 工厂 Trait

负责创建特定类型的 Agent 实例

§示例

use mofa_kernel::agent::registry::AgentFactory;
use mofa_kernel::agent::config::AgentConfig;

struct LLMAgentFactory;

#[async_trait]
impl AgentFactory for LLMAgentFactory {
    async fn create(&self, config: AgentConfig) -> AgentResult<Arc<RwLock<dyn MoFAAgent>>> {
        let _ = config;
        unimplemented!()
    }

    fn type_id(&self) -> &str {
        "llm"
    }

    fn default_capabilities(&self) -> AgentCapabilities {
        AgentCapabilities::builder()
            .with_tag("llm")
            .with_tag("chat")
            .build()
    }
}

Required Methods§

Source

fn create<'life0, 'async_trait>( &'life0 self, config: AgentConfig, ) -> Pin<Box<dyn Future<Output = Result<Arc<RwLock<dyn MoFAAgent>>, AgentError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

创建 Agent 实例

Source

fn type_id(&self) -> &str

工厂类型标识

Source

fn default_capabilities(&self) -> AgentCapabilities

默认能力

Provided Methods§

Source

fn validate_config(&self, config: &AgentConfig) -> Result<(), AgentError>

验证配置

Source

fn description(&self) -> Option<&str>

工厂描述

Implementors§