1mod 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#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct Agent {
21 pub id: String,
23 pub name: String,
25 pub title: String,
27 pub icon: String,
29 pub persona: AgentPersona,
31 pub capabilities: Vec<String>,
33 pub workflows: Vec<String>,
35 pub delegates_to: Vec<String>,
37 #[serde(default)]
39 pub builtin: bool,
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct AgentPersona {
45 pub role: String,
47 pub identity: String,
49 pub communication_style: String,
51 pub principles: Vec<String>,
53 pub traits: Vec<String>,
55}
56
57impl Agent {
58 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 pub fn with_capability(mut self, capability: impl Into<String>) -> Self {
81 self.capabilities.push(capability.into());
82 self
83 }
84
85 pub fn with_capabilities(mut self, capabilities: Vec<String>) -> Self {
87 self.capabilities.extend(capabilities);
88 self
89 }
90
91 pub fn with_workflow(mut self, workflow: impl Into<String>) -> Self {
93 self.workflows.push(workflow.into());
94 self
95 }
96
97 pub fn with_workflows(mut self, workflows: Vec<String>) -> Self {
99 self.workflows.extend(workflows);
100 self
101 }
102
103 pub fn with_delegate(mut self, delegate: impl Into<String>) -> Self {
105 self.delegates_to.push(delegate.into());
106 self
107 }
108
109 pub fn as_builtin(mut self) -> Self {
111 self.builtin = true;
112 self
113 }
114
115 pub fn has_capability(&self, capability: &str) -> bool {
117 self.capabilities.iter().any(|c| c == capability)
118 }
119
120 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 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 pub fn with_principle(mut self, principle: impl Into<String>) -> Self {
144 self.principles.push(principle.into());
145 self
146 }
147
148 pub fn with_principles(mut self, principles: Vec<String>) -> Self {
150 self.principles.extend(principles);
151 self
152 }
153
154 pub fn with_trait(mut self, trait_: impl Into<String>) -> Self {
156 self.traits.push(trait_.into());
157 self
158 }
159
160 pub fn with_traits(mut self, traits: Vec<String>) -> Self {
162 self.traits.extend(traits);
163 self
164 }
165}
166
167#[derive(Debug, Clone, Serialize, Deserialize)]
169pub struct DelegationRequest {
170 pub from_agent: String,
172 pub to_agent: String,
174 pub task: String,
176 pub context: HashMap<String, String>,
178}
179
180impl DelegationRequest {
181 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 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#[derive(Debug, Clone)]
204pub struct DelegationResult {
205 pub success: bool,
207 pub handled_by: String,
209 pub output: Option<String>,
211 pub error: Option<String>,
213}
214
215impl DelegationResult {
216 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 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}