pub struct AgentRegistry { /* private fields */ }Expand description
Agent 注册中心
提供 Agent 的注册、发现、工厂创建功能
§示例
ⓘ
use mofa_runtime::agent::AgentRegistry;
use mofa_kernel::agent::config::AgentConfig;
let registry = AgentRegistry::new();
// 注册工厂
registry.register_factory(Arc::new(LLMAgentFactory)).await?;
// 通过工厂创建 Agent
let config = AgentConfig::new("agent-1", "My Agent", "llm");
let agent = registry.create("llm", config).await?;
// 注册 Agent
registry.register(agent).await?;
// 查找 Agent
let found = registry.get("agent-1").await;Implementations§
Source§impl AgentRegistry
impl AgentRegistry
Sourcepub fn new() -> AgentRegistry
pub fn new() -> AgentRegistry
创建新的注册中心
Sourcepub async fn register(
&self,
agent: Arc<RwLock<dyn MoFAAgent>>,
) -> Result<(), AgentError>
pub async fn register( &self, agent: Arc<RwLock<dyn MoFAAgent>>, ) -> Result<(), AgentError>
注册 Agent
Sourcepub async fn unregister(&self, id: &str) -> Result<bool, AgentError>
pub async fn unregister(&self, id: &str) -> Result<bool, AgentError>
移除 Agent
Sourcepub async fn get_metadata(&self, id: &str) -> Option<AgentMetadata>
pub async fn get_metadata(&self, id: &str) -> Option<AgentMetadata>
获取 Agent 元数据
Sourcepub async fn list(&self) -> Vec<AgentMetadata>
pub async fn list(&self) -> Vec<AgentMetadata>
列出所有 Agent
Sourcepub async fn find_by_capabilities(
&self,
requirements: &AgentRequirements,
) -> Vec<AgentMetadata>
pub async fn find_by_capabilities( &self, requirements: &AgentRequirements, ) -> Vec<AgentMetadata>
按能力要求查找 Agent
Sourcepub async fn find_by_tag(&self, tag: &str) -> Vec<AgentMetadata>
pub async fn find_by_tag(&self, tag: &str) -> Vec<AgentMetadata>
按标签查找 Agent
按多个标签查找 Agent (交集)
Sourcepub async fn find_by_state(&self, state: AgentState) -> Vec<AgentMetadata>
pub async fn find_by_state(&self, state: AgentState) -> Vec<AgentMetadata>
按状态查找 Agent
Sourcepub async fn register_factory(
&self,
factory: Arc<dyn AgentFactory>,
) -> Result<(), AgentError>
pub async fn register_factory( &self, factory: Arc<dyn AgentFactory>, ) -> Result<(), AgentError>
注册 Agent 工厂
Sourcepub async fn get_factory(&self, type_id: &str) -> Option<Arc<dyn AgentFactory>>
pub async fn get_factory(&self, type_id: &str) -> Option<Arc<dyn AgentFactory>>
获取 Agent 工厂
Sourcepub async fn unregister_factory(
&self,
type_id: &str,
) -> Result<bool, AgentError>
pub async fn unregister_factory( &self, type_id: &str, ) -> Result<bool, AgentError>
移除 Agent 工厂
Sourcepub async fn list_factory_types(&self) -> Vec<String>
pub async fn list_factory_types(&self) -> Vec<String>
列出所有工厂类型
Sourcepub async fn create(
&self,
type_id: &str,
config: AgentConfig,
) -> Result<Arc<RwLock<dyn MoFAAgent>>, AgentError>
pub async fn create( &self, type_id: &str, config: AgentConfig, ) -> Result<Arc<RwLock<dyn MoFAAgent>>, AgentError>
通过工厂创建 Agent
Sourcepub async fn create_and_register(
&self,
type_id: &str,
config: AgentConfig,
) -> Result<Arc<RwLock<dyn MoFAAgent>>, AgentError>
pub async fn create_and_register( &self, type_id: &str, config: AgentConfig, ) -> Result<Arc<RwLock<dyn MoFAAgent>>, AgentError>
创建并注册 Agent
Sourcepub async fn initialize_all(
&self,
ctx: &AgentContext,
) -> Result<Vec<String>, AgentError>
pub async fn initialize_all( &self, ctx: &AgentContext, ) -> Result<Vec<String>, AgentError>
初始化所有 Agent
Sourcepub async fn shutdown_all(&self) -> Result<Vec<String>, AgentError>
pub async fn shutdown_all(&self) -> Result<Vec<String>, AgentError>
关闭所有 Agent
Sourcepub async fn clear(&self) -> Result<usize, AgentError>
pub async fn clear(&self) -> Result<usize, AgentError>
清空所有 Agent
Source§impl AgentRegistry
impl AgentRegistry
Sourcepub async fn stats(&self) -> RegistryStats
pub async fn stats(&self) -> RegistryStats
获取统计信息
Trait Implementations§
Source§impl Default for AgentRegistry
impl Default for AgentRegistry
Source§fn default() -> AgentRegistry
fn default() -> AgentRegistry
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for AgentRegistry
impl !RefUnwindSafe for AgentRegistry
impl Send for AgentRegistry
impl Sync for AgentRegistry
impl Unpin for AgentRegistry
impl UnsafeUnpin for AgentRegistry
impl !UnwindSafe for AgentRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Message for T
impl<T> Message for T
Source§fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
Convert a BoxedMessage to this concrete type
Source§fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
Convert this message to a BoxedMessage