Skip to main content

a3s_code_core/orchestrator/
mod.rs

1//! Agent Orchestrator - 主子智能体协调器
2//!
3//! 基于 a3s-event 实现的统一事件总线,支持:
4//! - 实时监控所有子智能体的行为、规划和执行
5//! - 主智能体动态控制子智能体(暂停、恢复、取消、参数调整)
6//! - 可插拔的事件 provider(默认内存,可选 NATS)
7//!
8//! ## 架构
9//!
10//! ```text
11//! AgentOrchestrator (主智能体)
12//!     ↓ 订阅事件
13//! ┌───────────────────────────────┐
14//! │   a3s-event EventBus          │
15//! │ (Memory / NATS / Custom)      │
16//! └───────────────────────────────┘
17//!     ↑ 发布事件    ↓ 控制信号
18//! SubAgentWrapper (子智能体)
19//! ```
20//!
21//! ## 使用示例
22//!
23//! ```rust,no_run
24//! use a3s_code_core::orchestrator::{AgentOrchestrator, SubAgentConfig};
25//!
26//! # async fn example() -> anyhow::Result<()> {
27//! // 创建 orchestrator (默认使用内存 provider)
28//! let orchestrator = AgentOrchestrator::new_memory();
29//!
30//! // 订阅所有事件
31//! let mut events = orchestrator.subscribe_all().await?;
32//!
33//! // 启动子智能体
34//! let handle = orchestrator.spawn_subagent(SubAgentConfig {
35//!     agent_type: "general".to_string(),
36//!     description: "Analyze code".to_string(),
37//!     prompt: "Use glob to find Python files".to_string(),
38//!     permissive: true,
39//!     max_steps: Some(10),
40//! }).await?;
41//!
42//! // 监控事件
43//! tokio::spawn(async move {
44//!     while let Some(event) = events.recv().await {
45//!         println!("Event: {:?}", event);
46//!     }
47//! });
48//!
49//! // 控制子智能体
50//! orchestrator.pause_subagent(&handle.id).await?;
51//! orchestrator.resume_subagent(&handle.id).await?;
52//!
53//! # Ok(())
54//! # }
55//! ```
56
57mod agent;
58mod config;
59mod control;
60mod events;
61mod handle;
62mod state;
63mod wrapper;
64
65#[cfg(test)]
66mod tests;
67
68pub use crate::agent_teams::TeamRole;
69pub use agent::AgentOrchestrator;
70pub use config::{AgentSlot, OrchestratorConfig, SubAgentActivity, SubAgentConfig, SubAgentInfo};
71pub use control::ControlSignal;
72pub use events::{OrchestratorEvent, SubAgentEventPayload};
73pub use handle::SubAgentHandle;
74pub use state::SubAgentState;
75pub use wrapper::SubAgentWrapper;