Skip to main content

driven/agents/
mod.rs

1//! Expanded Agent Library
2//!
3//! Provides 15+ specialized AI agent personas for different development tasks,
4//! matching and exceeding BMAD-METHOD capabilities.
5
6mod builtin;
7mod registry;
8
9#[cfg(test)]
10mod property_tests;
11
12pub use builtin::*;
13pub use registry::AgentRegistry;
14
15use serde::{Deserialize, Serialize};
16use std::collections::HashMap;
17
18/// A specialized AI agent with defined persona and capabilities
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct Agent {
21    /// Unique identifier for the agent
22    pub id: String,
23    /// Display name
24    pub name: String,
25    /// Professional title
26    pub title: String,
27    /// Icon/emoji for the agent
28    pub icon: String,
29    /// Agent's persona definition
30    pub persona: AgentPersona,
31    /// List of capabilities this agent has
32    pub capabilities: Vec<String>,
33    /// Workflows this agent can execute
34    pub workflows: Vec<String>,
35    /// Other agents this agent can delegate to
36    pub delegates_to: Vec<String>,
37    /// Whether this is a built-in agent
38    #[serde(default)]
39    pub builtin: bool,
40}
41
42/// Defines an agent's personality and behavior
43#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct AgentPersona {
45    /// The agent's role description
46    pub role: String,
47    /// Identity statement - who the agent is
48    pub identity: String,
49    /// Communication style
50    pub communication_style: String,
51    /// Core principles the agent follows
52    pub principles: Vec<String>,
53    /// Personality traits
54    pub traits: Vec<String>,
55}
56
57impl Agent {
58    /// Create a new agent with the given parameters
59    pub fn new(
60        id: impl Into<String>,
61        name: impl Into<String>,
62        title: impl Into<String>,
63        icon: impl Into<String>,
64        persona: AgentPersona,
65    ) -> Self {
66        Self {
67            id: id.into(),
68            name: name.into(),
69            title: title.into(),
70            icon: icon.into(),
71            persona,
72            capabilities: Vec::new(),
73            workflows: Vec::new(),
74            delegates_to: Vec::new(),
75            builtin: false,
76        }
77    }
78
79    /// Add a capability to this agent
80    pub fn with_capability(mut self, capability: impl Into<String>) -> Self {
81        self.capabilities.push(capability.into());
82        self
83    }
84
85    /// Add multiple capabilities
86    pub fn with_capabilities(mut self, capabilities: Vec<String>) -> Self {
87        self.capabilities.extend(capabilities);
88        self
89    }
90
91    /// Add a workflow this agent can execute
92    pub fn with_workflow(mut self, workflow: impl Into<String>) -> Self {
93        self.workflows.push(workflow.into());
94        self
95    }
96
97    /// Add multiple workflows
98    pub fn with_workflows(mut self, workflows: Vec<String>) -> Self {
99        self.workflows.extend(workflows);
100        self
101    }
102
103    /// Add an agent this agent can delegate to
104    pub fn with_delegate(mut self, delegate: impl Into<String>) -> Self {
105        self.delegates_to.push(delegate.into());
106        self
107    }
108
109    /// Mark as built-in agent
110    pub fn as_builtin(mut self) -> Self {
111        self.builtin = true;
112        self
113    }
114
115    /// Check if this agent has a specific capability
116    pub fn has_capability(&self, capability: &str) -> bool {
117        self.capabilities.iter().any(|c| c == capability)
118    }
119
120    /// Check if this agent can delegate to another agent
121    pub fn can_delegate_to(&self, agent_id: &str) -> bool {
122        self.delegates_to.iter().any(|d| d == agent_id)
123    }
124}
125
126impl AgentPersona {
127    /// Create a new agent persona
128    pub fn new(
129        role: impl Into<String>,
130        identity: impl Into<String>,
131        communication_style: impl Into<String>,
132    ) -> Self {
133        Self {
134            role: role.into(),
135            identity: identity.into(),
136            communication_style: communication_style.into(),
137            principles: Vec::new(),
138            traits: Vec::new(),
139        }
140    }
141
142    /// Add a principle
143    pub fn with_principle(mut self, principle: impl Into<String>) -> Self {
144        self.principles.push(principle.into());
145        self
146    }
147
148    /// Add multiple principles
149    pub fn with_principles(mut self, principles: Vec<String>) -> Self {
150        self.principles.extend(principles);
151        self
152    }
153
154    /// Add a trait
155    pub fn with_trait(mut self, trait_: impl Into<String>) -> Self {
156        self.traits.push(trait_.into());
157        self
158    }
159
160    /// Add multiple traits
161    pub fn with_traits(mut self, traits: Vec<String>) -> Self {
162        self.traits.extend(traits);
163        self
164    }
165}
166
167/// A request to delegate work from one agent to another
168#[derive(Debug, Clone, Serialize, Deserialize)]
169pub struct DelegationRequest {
170    /// The agent making the delegation
171    pub from_agent: String,
172    /// The agent receiving the delegation
173    pub to_agent: String,
174    /// The task or context being delegated
175    pub task: String,
176    /// Additional context for the delegation
177    pub context: HashMap<String, String>,
178}
179
180impl DelegationRequest {
181    /// Create a new delegation request
182    pub fn new(
183        from_agent: impl Into<String>,
184        to_agent: impl Into<String>,
185        task: impl Into<String>,
186    ) -> Self {
187        Self {
188            from_agent: from_agent.into(),
189            to_agent: to_agent.into(),
190            task: task.into(),
191            context: HashMap::new(),
192        }
193    }
194
195    /// Add context to the delegation
196    pub fn with_context(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
197        self.context.insert(key.into(), value.into());
198        self
199    }
200}
201
202/// Result of a delegation operation
203#[derive(Debug, Clone)]
204pub struct DelegationResult {
205    /// Whether the delegation was successful
206    pub success: bool,
207    /// The agent that handled the delegation
208    pub handled_by: String,
209    /// Any output from the delegation
210    pub output: Option<String>,
211    /// Error message if delegation failed
212    pub error: Option<String>,
213}
214
215impl DelegationResult {
216    /// Create a successful delegation result
217    pub fn success(handled_by: impl Into<String>, output: Option<String>) -> Self {
218        Self {
219            success: true,
220            handled_by: handled_by.into(),
221            output,
222            error: None,
223        }
224    }
225
226    /// Create a failed delegation result
227    pub fn failure(error: impl Into<String>) -> Self {
228        Self {
229            success: false,
230            handled_by: String::new(),
231            output: None,
232            error: Some(error.into()),
233        }
234    }
235}