aster/agents/subagent_scheduler/
config.rs1use serde::{Deserialize, Serialize};
6use std::time::Duration;
7
8use crate::agents::context::ContextInheritanceConfig;
9
10#[derive(Debug, Clone, Serialize, Deserialize)]
12#[serde(rename_all = "camelCase")]
13pub struct SchedulerConfig {
14 pub max_concurrency: usize,
16 pub default_timeout: Duration,
18 pub retry_on_failure: bool,
20 pub stop_on_first_error: bool,
22 pub max_retries: usize,
24 pub retry_delay: Duration,
26 pub context_inheritance: ContextInheritanceConfig,
28 pub auto_summarize: bool,
30 pub summary_max_tokens: usize,
32 pub default_model: Option<String>,
34 pub enable_progress_callback: bool,
36}
37
38impl Default for SchedulerConfig {
39 fn default() -> Self {
40 Self {
41 max_concurrency: 5,
42 default_timeout: Duration::from_secs(300), retry_on_failure: true,
44 stop_on_first_error: false,
45 max_retries: 3,
46 retry_delay: Duration::from_secs(1),
47 context_inheritance: ContextInheritanceConfig::default(),
48 auto_summarize: true,
49 summary_max_tokens: 2000,
50 default_model: None,
51 enable_progress_callback: true,
52 }
53 }
54}
55
56impl SchedulerConfig {
57 pub fn high_concurrency() -> Self {
59 Self {
60 max_concurrency: 10,
61 default_timeout: Duration::from_secs(600),
62 ..Default::default()
63 }
64 }
65
66 pub fn low_concurrency() -> Self {
68 Self {
69 max_concurrency: 2,
70 stop_on_first_error: true,
71 ..Default::default()
72 }
73 }
74
75 pub fn sequential() -> Self {
77 Self {
78 max_concurrency: 1,
79 stop_on_first_error: true,
80 ..Default::default()
81 }
82 }
83
84 pub fn with_max_concurrency(mut self, max: usize) -> Self {
86 self.max_concurrency = max;
87 self
88 }
89
90 pub fn with_timeout(mut self, timeout: Duration) -> Self {
92 self.default_timeout = timeout;
93 self
94 }
95
96 pub fn with_retry(mut self, enabled: bool, max_retries: usize) -> Self {
98 self.retry_on_failure = enabled;
99 self.max_retries = max_retries;
100 self
101 }
102
103 pub fn with_stop_on_first_error(mut self, stop: bool) -> Self {
105 self.stop_on_first_error = stop;
106 self
107 }
108
109 pub fn with_context_inheritance(mut self, config: ContextInheritanceConfig) -> Self {
111 self.context_inheritance = config;
112 self
113 }
114
115 pub fn with_default_model(mut self, model: impl Into<String>) -> Self {
117 self.default_model = Some(model.into());
118 self
119 }
120}
121
122#[cfg(test)]
123mod tests {
124 use super::*;
125
126 #[test]
127 fn test_default_config() {
128 let config = SchedulerConfig::default();
129 assert_eq!(config.max_concurrency, 5);
130 assert!(config.retry_on_failure);
131 assert!(!config.stop_on_first_error);
132 }
133
134 #[test]
135 fn test_high_concurrency_config() {
136 let config = SchedulerConfig::high_concurrency();
137 assert_eq!(config.max_concurrency, 10);
138 }
139
140 #[test]
141 fn test_sequential_config() {
142 let config = SchedulerConfig::sequential();
143 assert_eq!(config.max_concurrency, 1);
144 assert!(config.stop_on_first_error);
145 }
146
147 #[test]
148 fn test_config_builder() {
149 let config = SchedulerConfig::default()
150 .with_max_concurrency(8)
151 .with_stop_on_first_error(true)
152 .with_default_model("sonnet");
153
154 assert_eq!(config.max_concurrency, 8);
155 assert!(config.stop_on_first_error);
156 assert_eq!(config.default_model, Some("sonnet".to_string()));
157 }
158}