Skip to main content

agent_works/multi_agent/
config.rs

1//! Multi-agent configuration.
2//!
3//! Controls whether multi-agent capabilities are enabled and sets resource limits.
4//! Multi-agent is enabled by default — users who don't need it can disable via
5//! `.without_multi_agent()` or feature gate.
6
7/// Configuration for the multi-agent subsystem.
8///
9/// # Default
10///
11/// Multi-agent is **enabled** by default with limits of 8 sub-agents and depth 1.
12/// Disable it with:
13///
14/// ```rust,ignore
15/// use agent_works::AgentBuilder;
16///
17/// let agent = AgentBuilder::new(client)
18///     .without_multi_agent()
19///     .build()?;
20/// ```
21///
22/// # Limits
23///
24/// Limits only take effect when `enabled` is `true`.
25#[derive(Clone, Debug)]
26pub struct MultiAgentConfig {
27    /// Enable multi-agent capabilities.
28    ///
29    /// When `true` (default): all 6 multi-agent tools are registered, and the main
30    /// agent's system prompt is augmented with usage guidance.
31    ///
32    /// When `false`: no multi-agent tools are registered, and the system
33    /// prompt does not mention multi-agent capabilities.
34    pub enabled: bool,
35
36    /// Maximum number of concurrent sub-agents.
37    ///
38    /// Default: 8. Only enforced when `enabled` is `true`.
39    pub max_sub_agents: usize,
40
41    /// Maximum nesting depth for sub-agents.
42    ///
43    /// Default: 1 (only direct children of root can spawn). A value of 0 means
44    /// no sub-agents can be spawned at all. Only enforced when `enabled` is `true`.
45    pub max_agent_depth: i32,
46}
47
48impl Default for MultiAgentConfig {
49    fn default() -> Self {
50        Self {
51            enabled: true,
52            max_sub_agents: 8,
53            max_agent_depth: 1,
54        }
55    }
56}
57
58impl MultiAgentConfig {
59    /// Create a config with multi-agent enabled and default limits.
60    pub fn enabled() -> Self {
61        Self {
62            enabled: true,
63            ..Default::default()
64        }
65    }
66
67    /// Create a config with multi-agent enabled and custom limits.
68    pub fn with_limits(max_sub_agents: usize, max_agent_depth: i32) -> Self {
69        Self {
70            enabled: true,
71            max_sub_agents,
72            max_agent_depth,
73        }
74    }
75}
76
77#[cfg(test)]
78mod tests {
79    use super::*;
80
81    #[test]
82    fn default_is_enabled() {
83        let config = MultiAgentConfig::default();
84        assert!(config.enabled);
85        assert_eq!(config.max_sub_agents, 8);
86        assert_eq!(config.max_agent_depth, 1);
87    }
88
89    #[test]
90    fn enabled_shortcut() {
91        let config = MultiAgentConfig::enabled();
92        assert!(config.enabled);
93        assert_eq!(config.max_sub_agents, 8);
94        assert_eq!(config.max_agent_depth, 1);
95    }
96
97    #[test]
98    fn with_limits() {
99        let config = MultiAgentConfig::with_limits(4, 2);
100        assert!(config.enabled);
101        assert_eq!(config.max_sub_agents, 4);
102        assert_eq!(config.max_agent_depth, 2);
103    }
104}