mofa_kernel/agent/registry.rs
1//! Agent 工厂接口
2//!
3//! Kernel 仅保留抽象接口;注册中心实现位于运行时层 (mofa-runtime)。
4
5use crate::agent::capabilities::AgentCapabilities;
6use crate::agent::config::AgentConfig;
7use crate::agent::core::MoFAAgent;
8use crate::agent::error::AgentResult;
9use async_trait::async_trait;
10use std::sync::Arc;
11use tokio::sync::RwLock;
12
13/// Agent 工厂 Trait
14///
15/// 负责创建特定类型的 Agent 实例
16///
17/// # 示例
18///
19/// ```rust,ignore
20/// use mofa_kernel::agent::registry::AgentFactory;
21/// use mofa_kernel::agent::config::AgentConfig;
22///
23/// struct LLMAgentFactory;
24///
25/// #[async_trait]
26/// impl AgentFactory for LLMAgentFactory {
27/// async fn create(&self, config: AgentConfig) -> AgentResult<Arc<RwLock<dyn MoFAAgent>>> {
28/// let _ = config;
29/// unimplemented!()
30/// }
31///
32/// fn type_id(&self) -> &str {
33/// "llm"
34/// }
35///
36/// fn default_capabilities(&self) -> AgentCapabilities {
37/// AgentCapabilities::builder()
38/// .with_tag("llm")
39/// .with_tag("chat")
40/// .build()
41/// }
42/// }
43/// ```
44#[async_trait]
45pub trait AgentFactory: Send + Sync {
46 /// 创建 Agent 实例
47 async fn create(&self, config: AgentConfig) -> AgentResult<Arc<RwLock<dyn MoFAAgent>>>;
48
49 /// 工厂类型标识
50 fn type_id(&self) -> &str;
51
52 /// 默认能力
53 fn default_capabilities(&self) -> AgentCapabilities;
54
55 /// 验证配置
56 fn validate_config(&self, config: &AgentConfig) -> AgentResult<()> {
57 let _ = config;
58 Ok(())
59 }
60
61 /// 工厂描述
62 fn description(&self) -> Option<&str> {
63 None
64 }
65}