Skip to main content

a3s_code_core/orchestrator/
config.rs

1//! Orchestrator configuration
2
3use serde::{Deserialize, Serialize};
4
5/// Orchestrator 配置
6#[derive(Debug, Clone)]
7pub struct OrchestratorConfig {
8    /// 事件通道缓冲区大小
9    pub event_buffer_size: usize,
10
11    /// 控制信号通道缓冲区大小
12    pub control_buffer_size: usize,
13
14    /// SubAgent 最大并发数
15    pub max_concurrent_subagents: usize,
16
17    /// 事件主题前缀
18    pub subject_prefix: String,
19}
20
21impl Default for OrchestratorConfig {
22    fn default() -> Self {
23        Self {
24            event_buffer_size: 1000,
25            control_buffer_size: 100,
26            max_concurrent_subagents: 50,
27            subject_prefix: "agent".to_string(),
28        }
29    }
30}
31
32/// SubAgent 配置
33#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct SubAgentConfig {
35    /// Agent 类型 (general, explore, plan, etc.)
36    pub agent_type: String,
37
38    /// 任务描述
39    pub description: String,
40
41    /// 执行提示词
42    pub prompt: String,
43
44    /// 是否启用宽松模式(绕过 HITL)
45    #[serde(default)]
46    pub permissive: bool,
47
48    /// 最大执行步数
49    pub max_steps: Option<usize>,
50
51    /// 执行超时(毫秒)
52    pub timeout_ms: Option<u64>,
53
54    /// 父 SubAgent ID(用于嵌套)
55    #[serde(skip_serializing_if = "Option::is_none")]
56    pub parent_id: Option<String>,
57
58    /// 自定义元数据
59    #[serde(default)]
60    pub metadata: serde_json::Value,
61}
62
63/// SubAgent 信息(元数据)
64#[derive(Debug, Clone, Serialize, Deserialize)]
65pub struct SubAgentInfo {
66    /// SubAgent ID
67    pub id: String,
68
69    /// Agent 类型
70    pub agent_type: String,
71
72    /// 任务描述
73    pub description: String,
74
75    /// 当前状态
76    pub state: String,
77
78    /// 父 SubAgent ID
79    pub parent_id: Option<String>,
80
81    /// 创建时间(Unix 时间戳,毫秒)
82    pub created_at: u64,
83
84    /// 最后更新时间(Unix 时间戳,毫秒)
85    pub updated_at: u64,
86
87    /// 当前活动
88    pub current_activity: Option<SubAgentActivity>,
89}
90
91/// SubAgent 当前活动
92#[derive(Debug, Clone, Serialize, Deserialize)]
93#[serde(tag = "type", rename_all = "snake_case")]
94pub enum SubAgentActivity {
95    /// 空闲
96    Idle,
97
98    /// 正在调用工具
99    CallingTool {
100        tool_name: String,
101        args: serde_json::Value,
102    },
103
104    /// 正在请求 LLM
105    RequestingLlm { message_count: usize },
106
107    /// 正在等待控制信号
108    WaitingForControl { reason: String },
109}
110
111impl SubAgentConfig {
112    /// 创建新的 SubAgent 配置
113    pub fn new(agent_type: impl Into<String>, prompt: impl Into<String>) -> Self {
114        Self {
115            agent_type: agent_type.into(),
116            description: String::new(),
117            prompt: prompt.into(),
118            permissive: false,
119            max_steps: None,
120            timeout_ms: None,
121            parent_id: None,
122            metadata: serde_json::Value::Null,
123        }
124    }
125
126    /// 设置描述
127    pub fn with_description(mut self, description: impl Into<String>) -> Self {
128        self.description = description.into();
129        self
130    }
131
132    /// 设置宽松模式
133    pub fn with_permissive(mut self, permissive: bool) -> Self {
134        self.permissive = permissive;
135        self
136    }
137
138    /// 设置最大步数
139    pub fn with_max_steps(mut self, max_steps: usize) -> Self {
140        self.max_steps = Some(max_steps);
141        self
142    }
143
144    /// 设置超时
145    pub fn with_timeout_ms(mut self, timeout_ms: u64) -> Self {
146        self.timeout_ms = Some(timeout_ms);
147        self
148    }
149
150    /// 设置父 ID
151    pub fn with_parent_id(mut self, parent_id: impl Into<String>) -> Self {
152        self.parent_id = Some(parent_id.into());
153        self
154    }
155
156    /// 设置元数据
157    pub fn with_metadata(mut self, metadata: serde_json::Value) -> Self {
158        self.metadata = metadata;
159        self
160    }
161}