pub struct AgentOrchestrator { /* private fields */ }Expand description
Agent Orchestrator - 主子智能体协调器
基于事件总线实现统一的监控和控制机制。 默认使用内存事件通讯,支持用户自定义 NATS provider。
Implementations§
Source§impl AgentOrchestrator
impl AgentOrchestrator
Sourcepub fn new_memory() -> Self
pub fn new_memory() -> Self
创建新的 orchestrator(使用内存事件通讯)
这是默认的创建方式,适用于单进程场景。
SubAgents 将以占位符模式运行,不执行实际的 LLM 操作。
要执行真实的 LLM 操作,请使用 from_agent()。
Sourcepub fn new(config: OrchestratorConfig) -> Self
pub fn new(config: OrchestratorConfig) -> Self
使用自定义配置创建 orchestrator(占位符模式)
Sourcepub fn from_agent(agent: Arc<Agent>) -> Self
pub fn from_agent(agent: Arc<Agent>) -> Self
Create an orchestrator backed by a real Agent for LLM execution.
SubAgents spawned by this orchestrator will run the actual agent
definition (permissions, system prompt, model, max_steps) loaded from
the agent’s configuration and any extra agent_dirs provided in
SubAgentConfig.
Sourcepub fn from_agent_with_config(
agent: Arc<Agent>,
config: OrchestratorConfig,
) -> Self
pub fn from_agent_with_config( agent: Arc<Agent>, config: OrchestratorConfig, ) -> Self
Create an orchestrator backed by a real Agent with custom config.
Sourcepub fn subscribe_all(&self) -> Receiver<OrchestratorEvent>
pub fn subscribe_all(&self) -> Receiver<OrchestratorEvent>
订阅所有 SubAgent 事件
返回一个接收器,可以接收所有 SubAgent 的事件。
Sourcepub fn subscribe_subagent(&self, id: &str) -> SubAgentEventStream
pub fn subscribe_subagent(&self, id: &str) -> SubAgentEventStream
订阅特定 SubAgent 的事件
返回一个过滤后的接收器,只接收指定 SubAgent 的事件。
Sourcepub async fn spawn_subagent(
&self,
config: SubAgentConfig,
) -> Result<SubAgentHandle>
pub async fn spawn_subagent( &self, config: SubAgentConfig, ) -> Result<SubAgentHandle>
启动新的 SubAgent
返回 SubAgent 句柄,可用于控制和查询状态。
Sourcepub async fn spawn(&self, slot: AgentSlot) -> Result<SubAgentHandle>
pub async fn spawn(&self, slot: AgentSlot) -> Result<SubAgentHandle>
Spawn a subagent from a unified AgentSlot declaration.
Convenience wrapper around spawn_subagent that accepts the unified slot
type. The role field is ignored here — for team-based workflows use
run_team instead.
Sourcepub async fn run_team(
&self,
goal: impl Into<String>,
workspace: impl Into<String>,
slots: Vec<AgentSlot>,
) -> Result<TeamRunResult>
pub async fn run_team( &self, goal: impl Into<String>, workspace: impl Into<String>, slots: Vec<AgentSlot>, ) -> Result<TeamRunResult>
Run a goal through a Lead → Worker → Reviewer team built from AgentSlots.
Requires from_agent() mode — returns an error if no backing Agent is
configured. Each slot’s role field determines its position in the team;
slots without a role default to Worker. Agent definitions are loaded
from each slot’s agent_dirs and looked up by agent_type.
Sourcepub async fn send_control(&self, id: &str, signal: ControlSignal) -> Result<()>
pub async fn send_control(&self, id: &str, signal: ControlSignal) -> Result<()>
发送控制信号到 SubAgent
Sourcepub async fn pause_subagent(&self, id: &str) -> Result<()>
pub async fn pause_subagent(&self, id: &str) -> Result<()>
暂停 SubAgent
Sourcepub async fn resume_subagent(&self, id: &str) -> Result<()>
pub async fn resume_subagent(&self, id: &str) -> Result<()>
恢复 SubAgent
Sourcepub async fn cancel_subagent(&self, id: &str) -> Result<()>
pub async fn cancel_subagent(&self, id: &str) -> Result<()>
取消 SubAgent
Sourcepub async fn adjust_subagent_params(
&self,
id: &str,
max_steps: Option<usize>,
timeout_ms: Option<u64>,
) -> Result<()>
pub async fn adjust_subagent_params( &self, id: &str, max_steps: Option<usize>, timeout_ms: Option<u64>, ) -> Result<()>
调整 SubAgent 参数
Sourcepub async fn get_subagent_state(&self, id: &str) -> Option<SubAgentState>
pub async fn get_subagent_state(&self, id: &str) -> Option<SubAgentState>
获取 SubAgent 状态
Sourcepub async fn get_all_states(&self) -> HashMap<String, SubAgentState>
pub async fn get_all_states(&self) -> HashMap<String, SubAgentState>
获取所有 SubAgent 的状态
Sourcepub async fn active_count(&self) -> usize
pub async fn active_count(&self) -> usize
获取活跃的 SubAgent 数量
Sourcepub async fn list_subagents(&self) -> Vec<SubAgentInfo>
pub async fn list_subagents(&self) -> Vec<SubAgentInfo>
获取所有 SubAgent 的信息列表
Sourcepub async fn get_subagent_info(&self, id: &str) -> Option<SubAgentInfo>
pub async fn get_subagent_info(&self, id: &str) -> Option<SubAgentInfo>
获取特定 SubAgent 的详细信息
Sourcepub async fn get_active_activities(&self) -> HashMap<String, SubAgentActivity>
pub async fn get_active_activities(&self) -> HashMap<String, SubAgentActivity>
获取所有活跃 SubAgent 的当前活动
Sourcepub async fn get_handle(&self, id: &str) -> Option<SubAgentHandle>
pub async fn get_handle(&self, id: &str) -> Option<SubAgentHandle>
获取 SubAgent 句柄(用于直接控制)
Sourcepub async fn pending_external_tasks_for(
&self,
subagent_id: &str,
) -> Vec<ExternalTask>
pub async fn pending_external_tasks_for( &self, subagent_id: &str, ) -> Vec<ExternalTask>
Complete a pending external task for a SubAgent.
Call this after processing an OrchestratorEvent::ExternalTaskPending
event. The subagent_id and task_id identify the waiting tool call;
result is the outcome produced by the external worker.
Returns true if the task was found and unblocked, false if the
subagent or task ID was not found (e.g., already timed out).
Return any external tasks currently waiting for the given SubAgent.
Returns an empty list if the SubAgent does not exist or has no pending external tasks (e.g. when running with the default Internal lane mode).