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    /// Workspace directory for the SubAgent (defaults to ".")
63    #[serde(default = "default_workspace")]
64    pub workspace: String,
65
66    /// Extra directories to scan for agent definition files
67    #[serde(default)]
68    pub agent_dirs: Vec<String>,
69
70    /// Lane queue configuration for External/Hybrid tool dispatch.
71    ///
72    /// When set, the SubAgent's session is created with this queue config,
73    /// enabling tools to be routed to external workers.  Any lane not
74    /// explicitly configured falls back to Internal mode.
75    #[serde(skip_serializing_if = "Option::is_none")]
76    pub lane_config: Option<crate::queue::SessionQueueConfig>,
77}
78
79/// SubAgent 信息(元数据)
80#[derive(Debug, Clone, Serialize, Deserialize)]
81pub struct SubAgentInfo {
82    /// SubAgent ID
83    pub id: String,
84
85    /// Agent 类型
86    pub agent_type: String,
87
88    /// 任务描述
89    pub description: String,
90
91    /// 当前状态
92    pub state: String,
93
94    /// 父 SubAgent ID
95    pub parent_id: Option<String>,
96
97    /// 创建时间(Unix 时间戳,毫秒)
98    pub created_at: u64,
99
100    /// 最后更新时间(Unix 时间戳,毫秒)
101    pub updated_at: u64,
102
103    /// 当前活动
104    pub current_activity: Option<SubAgentActivity>,
105}
106
107/// SubAgent 当前活动
108#[derive(Debug, Clone, Serialize, Deserialize)]
109#[serde(tag = "type", rename_all = "snake_case")]
110pub enum SubAgentActivity {
111    /// 空闲
112    Idle,
113
114    /// 正在调用工具
115    CallingTool {
116        tool_name: String,
117        args: serde_json::Value,
118    },
119
120    /// 正在请求 LLM
121    RequestingLlm { message_count: usize },
122
123    /// 正在等待控制信号
124    WaitingForControl { reason: String },
125}
126
127impl SubAgentConfig {
128    /// 创建新的 SubAgent 配置
129    pub fn new(agent_type: impl Into<String>, prompt: impl Into<String>) -> Self {
130        Self {
131            agent_type: agent_type.into(),
132            description: String::new(),
133            prompt: prompt.into(),
134            permissive: false,
135            max_steps: None,
136            timeout_ms: None,
137            parent_id: None,
138            metadata: serde_json::Value::Null,
139            workspace: default_workspace(),
140            agent_dirs: Vec::new(),
141            lane_config: None,
142        }
143    }
144
145    /// 设置描述
146    pub fn with_description(mut self, description: impl Into<String>) -> Self {
147        self.description = description.into();
148        self
149    }
150
151    /// 设置宽松模式
152    pub fn with_permissive(mut self, permissive: bool) -> Self {
153        self.permissive = permissive;
154        self
155    }
156
157    /// 设置最大步数
158    pub fn with_max_steps(mut self, max_steps: usize) -> Self {
159        self.max_steps = Some(max_steps);
160        self
161    }
162
163    /// 设置超时
164    pub fn with_timeout_ms(mut self, timeout_ms: u64) -> Self {
165        self.timeout_ms = Some(timeout_ms);
166        self
167    }
168
169    /// 设置父 ID
170    pub fn with_parent_id(mut self, parent_id: impl Into<String>) -> Self {
171        self.parent_id = Some(parent_id.into());
172        self
173    }
174
175    /// 设置元数据
176    pub fn with_metadata(mut self, metadata: serde_json::Value) -> Self {
177        self.metadata = metadata;
178        self
179    }
180
181    /// Set the workspace directory for this SubAgent
182    pub fn with_workspace(mut self, workspace: impl Into<String>) -> Self {
183        self.workspace = workspace.into();
184        self
185    }
186
187    /// Add extra directories to scan for agent definition files
188    pub fn with_agent_dirs(mut self, dirs: Vec<String>) -> Self {
189        self.agent_dirs = dirs;
190        self
191    }
192
193    /// Set lane queue configuration for External/Hybrid tool dispatch
194    pub fn with_lane_config(mut self, config: crate::queue::SessionQueueConfig) -> Self {
195        self.lane_config = Some(config);
196        self
197    }
198}
199
200fn default_workspace() -> String {
201    ".".to_string()
202}