pub trait Coordinator: Send + Sync {
// Required methods
fn dispatch<'life0, 'life1, 'async_trait>(
&'life0 self,
task: Task,
ctx: &'life1 AgentContext,
) -> Pin<Box<dyn Future<Output = AgentResult<Vec<DispatchResult>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn aggregate<'life0, 'async_trait>(
&'life0 self,
results: Vec<AgentOutput>,
) -> Pin<Box<dyn Future<Output = AgentResult<AgentOutput>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn pattern(&self) -> CoordinationPattern;
// Provided methods
fn name(&self) -> &str { ... }
fn select_agents<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
task: &'life1 Task,
ctx: &'life2 AgentContext,
) -> Pin<Box<dyn Future<Output = AgentResult<Vec<String>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn requires_all(&self) -> bool { ... }
}Expand description
协调器 Trait
负责多 Agent 的任务分发和结果聚合
§示例
ⓘ
use mofa_kernel::agent::components::coordinator::{Coordinator, CoordinationPattern, Task, DispatchResult};
struct SequentialCoordinator {
agent_ids: Vec<String>,
}
#[async_trait]
impl Coordinator for SequentialCoordinator {
async fn dispatch(&self, task: Task, ctx: &CoreAgentContext) -> AgentResult<Vec<DispatchResult>> {
// Sequential dispatch implementation
}
async fn aggregate(&self, results: Vec<AgentOutput>) -> AgentResult<AgentOutput> {
// Combine results
}
fn pattern(&self) -> CoordinationPattern {
CoordinationPattern::Sequential
}
}Required Methods§
Sourcefn dispatch<'life0, 'life1, 'async_trait>(
&'life0 self,
task: Task,
ctx: &'life1 AgentContext,
) -> Pin<Box<dyn Future<Output = AgentResult<Vec<DispatchResult>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn dispatch<'life0, 'life1, 'async_trait>(
&'life0 self,
task: Task,
ctx: &'life1 AgentContext,
) -> Pin<Box<dyn Future<Output = AgentResult<Vec<DispatchResult>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
分发任务给 Agent(s)
Sourcefn aggregate<'life0, 'async_trait>(
&'life0 self,
results: Vec<AgentOutput>,
) -> Pin<Box<dyn Future<Output = AgentResult<AgentOutput>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn aggregate<'life0, 'async_trait>(
&'life0 self,
results: Vec<AgentOutput>,
) -> Pin<Box<dyn Future<Output = AgentResult<AgentOutput>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
聚合多个 Agent 的结果
Sourcefn pattern(&self) -> CoordinationPattern
fn pattern(&self) -> CoordinationPattern
获取协调模式
Provided Methods§
Sourcefn select_agents<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
task: &'life1 Task,
ctx: &'life2 AgentContext,
) -> Pin<Box<dyn Future<Output = AgentResult<Vec<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn select_agents<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
task: &'life1 Task,
ctx: &'life2 AgentContext,
) -> Pin<Box<dyn Future<Output = AgentResult<Vec<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
选择执行任务的 Agent
Sourcefn requires_all(&self) -> bool
fn requires_all(&self) -> bool
是否需要所有 Agent 完成