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    /// 最大执行步数
45    pub max_steps: Option<usize>,
46
47    /// 执行超时(毫秒)
48    pub timeout_ms: Option<u64>,
49
50    /// 父 SubAgent ID(用于嵌套)
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub parent_id: Option<String>,
53
54    /// 自定义元数据
55    #[serde(default)]
56    pub metadata: serde_json::Value,
57
58    /// Workspace directory for the SubAgent (defaults to ".")
59    #[serde(default = "default_workspace")]
60    pub workspace: String,
61
62    /// Extra directories to scan for agent definition files
63    #[serde(default)]
64    pub agent_dirs: Vec<String>,
65
66    /// Extra directories to scan for skill definition files
67    #[serde(default)]
68    pub skill_dirs: Vec<String>,
69}
70
71/// SubAgent 信息(元数据)
72#[derive(Debug, Clone, Serialize, Deserialize)]
73pub struct SubAgentInfo {
74    /// SubAgent ID
75    pub id: String,
76
77    /// Agent 类型
78    pub agent_type: String,
79
80    /// 任务描述
81    pub description: String,
82
83    /// 当前状态
84    pub state: String,
85
86    /// 父 SubAgent ID
87    pub parent_id: Option<String>,
88
89    /// 创建时间(Unix 时间戳,毫秒)
90    pub created_at: u64,
91
92    /// 最后更新时间(Unix 时间戳,毫秒)
93    pub updated_at: u64,
94
95    /// 当前活动
96    pub current_activity: Option<SubAgentActivity>,
97}
98
99/// SubAgent 当前活动
100#[derive(Debug, Clone, Serialize, Deserialize)]
101#[serde(tag = "type", rename_all = "snake_case")]
102pub enum SubAgentActivity {
103    /// 空闲
104    Idle,
105
106    /// 正在调用工具
107    CallingTool {
108        tool_name: String,
109        args: serde_json::Value,
110    },
111
112    /// 正在请求 LLM
113    RequestingLlm { message_count: usize },
114
115    /// 正在等待控制信号
116    WaitingForControl { reason: String },
117}
118
119impl SubAgentConfig {
120    /// 创建新的 SubAgent 配置
121    pub fn new(agent_type: impl Into<String>, prompt: impl Into<String>) -> Self {
122        Self {
123            agent_type: agent_type.into(),
124            description: String::new(),
125            prompt: prompt.into(),
126            max_steps: None,
127            timeout_ms: None,
128            parent_id: None,
129            metadata: serde_json::Value::Null,
130            workspace: default_workspace(),
131            agent_dirs: Vec::new(),
132            skill_dirs: Vec::new(),
133        }
134    }
135
136    /// 设置描述
137    pub fn with_description(mut self, description: impl Into<String>) -> Self {
138        self.description = description.into();
139        self
140    }
141
142    /// 设置最大步数
143    pub fn with_max_steps(mut self, max_steps: usize) -> Self {
144        self.max_steps = Some(max_steps);
145        self
146    }
147
148    /// 设置超时
149    pub fn with_timeout_ms(mut self, timeout_ms: u64) -> Self {
150        self.timeout_ms = Some(timeout_ms);
151        self
152    }
153
154    /// 设置父 ID
155    pub fn with_parent_id(mut self, parent_id: impl Into<String>) -> Self {
156        self.parent_id = Some(parent_id.into());
157        self
158    }
159
160    /// 设置元数据
161    pub fn with_metadata(mut self, metadata: serde_json::Value) -> Self {
162        self.metadata = metadata;
163        self
164    }
165
166    /// Set the workspace directory for this SubAgent
167    pub fn with_workspace(mut self, workspace: impl Into<String>) -> Self {
168        self.workspace = workspace.into();
169        self
170    }
171
172    /// Add extra directories to scan for agent definition files
173    pub fn with_agent_dirs(mut self, dirs: Vec<String>) -> Self {
174        self.agent_dirs = dirs;
175        self
176    }
177
178    /// Add extra directories to scan for skill definition files
179    pub fn with_skill_dirs(mut self, dirs: Vec<String>) -> Self {
180        self.skill_dirs = dirs;
181        self
182    }
183}
184
185fn default_workspace() -> String {
186    ".".to_string()
187}