1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
//! Agent configuration.
//!
//! Defines configuration options for creating and customizing agents.
use crate::types::AgentId;
use serde::{Deserialize, Serialize};
#[cfg(feature = "agent-skills")]
use std::path::PathBuf;
/// Configuration for creating a new agent.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct AgentConfig {
/// Optional pre-assigned ID for the agent
pub id: Option<AgentId>,
/// The system prompt that defines the agent's behavior
pub system_prompt: String,
/// Optional display name for the agent
pub name: Option<String>,
/// Maximum number of messages to keep in conversation history
pub max_conversation_length: usize,
/// Whether to enable streaming responses
pub enable_streaming: bool,
/// Names of builtin tools to enable for this agent.
///
/// If empty, no builtin tools are enabled.
/// Use `with_all_builtins()` to enable all available builtin tools.
#[serde(default)]
pub tools: Vec<String>,
/// Paths to skill files or directories to load for this agent.
///
/// Only available when the `agent-skills` feature is enabled.
#[cfg(feature = "agent-skills")]
#[serde(default)]
pub skill_paths: Vec<PathBuf>,
}
impl AgentConfig {
/// Creates a new agent configuration with the given system prompt.
///
/// # Arguments
///
/// * `system_prompt` - The system prompt that defines the agent's behavior
///
/// # Examples
///
/// ```
/// use acton_ai::agent::AgentConfig;
///
/// let config = AgentConfig::new("You are a helpful assistant.");
/// assert!(!config.system_prompt.is_empty());
/// ```
#[must_use]
pub fn new(system_prompt: impl Into<String>) -> Self {
Self {
id: None,
system_prompt: system_prompt.into(),
name: None,
max_conversation_length: 100,
enable_streaming: true,
tools: Vec::new(),
#[cfg(feature = "agent-skills")]
skill_paths: Vec::new(),
}
}
/// Sets a pre-assigned ID for the agent.
#[must_use]
pub fn with_id(mut self, id: AgentId) -> Self {
self.id = Some(id);
self
}
/// Sets a display name for the agent.
#[must_use]
pub fn with_name(mut self, name: impl Into<String>) -> Self {
self.name = Some(name.into());
self
}
/// Sets the maximum conversation length.
#[must_use]
pub fn with_max_conversation_length(mut self, length: usize) -> Self {
self.max_conversation_length = length;
self
}
/// Enables or disables streaming responses.
#[must_use]
pub fn with_streaming(mut self, enable: bool) -> Self {
self.enable_streaming = enable;
self
}
/// Sets the list of builtin tools to enable for this agent.
///
/// # Arguments
///
/// * `tools` - Names of builtin tools to enable (e.g., "read_file", "bash")
///
/// # Example
///
/// ```rust
/// use acton_ai::agent::AgentConfig;
///
/// let config = AgentConfig::new("You are helpful.")
/// .with_tools(&["read_file", "write_file", "glob"]);
/// ```
#[must_use]
pub fn with_tools(mut self, tools: &[&str]) -> Self {
self.tools = tools.iter().map(|s| (*s).to_string()).collect();
self
}
/// Enables all available builtin tools for this agent.
///
/// This is a convenience method equivalent to calling `with_tools` with
/// all available tool names.
///
/// # Example
///
/// ```rust
/// use acton_ai::agent::AgentConfig;
///
/// let config = AgentConfig::new("You are helpful.")
/// .with_all_builtins();
/// ```
#[must_use]
pub fn with_all_builtins(mut self) -> Self {
use crate::tools::builtins::BuiltinTools;
self.tools = BuiltinTools::available()
.iter()
.map(|s| (*s).to_string())
.collect();
self
}
/// Adds a single tool to the list of enabled tools.
///
/// # Arguments
///
/// * `tool` - Name of the builtin tool to add
///
/// # Example
///
/// ```rust
/// use acton_ai::agent::AgentConfig;
///
/// let config = AgentConfig::new("You are helpful.")
/// .with_tool("read_file")
/// .with_tool("write_file");
/// ```
#[must_use]
pub fn with_tool(mut self, tool: impl Into<String>) -> Self {
self.tools.push(tool.into());
self
}
/// Sets the skill paths to load for this agent.
///
/// Only available when the `agent-skills` feature is enabled.
///
/// # Arguments
///
/// * `paths` - Paths to skill files or directories
///
/// # Example
///
/// ```rust,ignore
/// use acton_ai::agent::AgentConfig;
/// use std::path::PathBuf;
///
/// let config = AgentConfig::new("You are helpful.")
/// .with_skill_paths(&[PathBuf::from("./skills")]);
/// ```
#[cfg(feature = "agent-skills")]
#[must_use]
pub fn with_skill_paths(mut self, paths: &[PathBuf]) -> Self {
self.skill_paths = paths.to_vec();
self
}
/// Adds a single skill path to the list of paths to load.
///
/// Only available when the `agent-skills` feature is enabled.
///
/// # Arguments
///
/// * `path` - Path to a skill file or directory
///
/// # Example
///
/// ```rust,ignore
/// use acton_ai::agent::AgentConfig;
/// use std::path::PathBuf;
///
/// let config = AgentConfig::new("You are helpful.")
/// .with_skill_path(PathBuf::from("./skills/coding.md"))
/// .with_skill_path(PathBuf::from("./skills/debugging"));
/// ```
#[cfg(feature = "agent-skills")]
#[must_use]
pub fn with_skill_path(mut self, path: impl Into<PathBuf>) -> Self {
self.skill_paths.push(path.into());
self
}
/// Returns the agent ID, generating a new one if not set.
#[must_use]
pub fn agent_id(&self) -> AgentId {
self.id.clone().unwrap_or_default()
}
}
impl Default for AgentConfig {
fn default() -> Self {
Self::new("You are a helpful AI assistant.")
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn new_creates_config_with_system_prompt() {
let config = AgentConfig::new("Custom prompt");
assert_eq!(config.system_prompt, "Custom prompt");
assert!(config.id.is_none());
assert!(config.name.is_none());
}
#[test]
fn default_has_reasonable_values() {
let config = AgentConfig::default();
assert!(!config.system_prompt.is_empty());
assert_eq!(config.max_conversation_length, 100);
assert!(config.enable_streaming);
}
#[test]
fn builder_pattern() {
let id = AgentId::new();
let config = AgentConfig::new("Test")
.with_id(id.clone())
.with_name("TestAgent")
.with_max_conversation_length(50)
.with_streaming(false);
assert_eq!(config.id, Some(id));
assert_eq!(config.name, Some("TestAgent".to_string()));
assert_eq!(config.max_conversation_length, 50);
assert!(!config.enable_streaming);
}
#[test]
fn agent_id_generates_new_when_none() {
let config = AgentConfig::new("Test");
let id1 = config.agent_id();
let id2 = config.agent_id();
// Each call generates a new ID when not pre-set
assert_ne!(id1, id2);
}
#[test]
fn agent_id_returns_preset_when_set() {
let preset_id = AgentId::new();
let config = AgentConfig::new("Test").with_id(preset_id.clone());
let id1 = config.agent_id();
let id2 = config.agent_id();
assert_eq!(id1, preset_id);
assert_eq!(id2, preset_id);
}
#[test]
fn serialization_roundtrip() {
let config = AgentConfig::new("Test agent")
.with_name("TestBot")
.with_max_conversation_length(50);
let json = serde_json::to_string(&config).unwrap();
let deserialized: AgentConfig = serde_json::from_str(&json).unwrap();
assert_eq!(config, deserialized);
}
#[test]
fn with_tools_sets_tool_list() {
let config = AgentConfig::new("Test").with_tools(&["read_file", "write_file", "glob"]);
assert_eq!(config.tools.len(), 3);
assert!(config.tools.contains(&"read_file".to_string()));
assert!(config.tools.contains(&"write_file".to_string()));
assert!(config.tools.contains(&"glob".to_string()));
}
#[test]
fn with_tool_adds_single_tool() {
let config = AgentConfig::new("Test")
.with_tool("read_file")
.with_tool("write_file");
assert_eq!(config.tools.len(), 2);
assert!(config.tools.contains(&"read_file".to_string()));
assert!(config.tools.contains(&"write_file".to_string()));
}
#[test]
fn with_all_builtins_adds_all_tools() {
let config = AgentConfig::new("Test").with_all_builtins();
// Should have all 10 builtin tools
assert_eq!(config.tools.len(), 10);
assert!(config.tools.contains(&"read_file".to_string()));
assert!(config.tools.contains(&"bash".to_string()));
assert!(config.tools.contains(&"calculate".to_string()));
assert!(config.tools.contains(&"rust_code".to_string()));
}
#[test]
fn default_has_no_tools() {
let config = AgentConfig::default();
assert!(config.tools.is_empty());
}
#[test]
fn serialization_roundtrip_with_tools() {
let config = AgentConfig::new("Test agent").with_tools(&["read_file", "bash"]);
let json = serde_json::to_string(&config).unwrap();
let deserialized: AgentConfig = serde_json::from_str(&json).unwrap();
assert_eq!(config, deserialized);
assert_eq!(deserialized.tools, vec!["read_file", "bash"]);
}
#[cfg(feature = "agent-skills")]
mod skills_tests {
use super::*;
#[test]
fn with_skill_paths_sets_paths() {
let config = AgentConfig::new("Test")
.with_skill_paths(&[PathBuf::from("./skills"), PathBuf::from("./more-skills")]);
assert_eq!(config.skill_paths.len(), 2);
assert!(config.skill_paths.contains(&PathBuf::from("./skills")));
assert!(config.skill_paths.contains(&PathBuf::from("./more-skills")));
}
#[test]
fn with_skill_path_adds_single_path() {
let config = AgentConfig::new("Test")
.with_skill_path("./skills/coding.md")
.with_skill_path("./skills/debugging");
assert_eq!(config.skill_paths.len(), 2);
assert!(config
.skill_paths
.contains(&PathBuf::from("./skills/coding.md")));
assert!(config
.skill_paths
.contains(&PathBuf::from("./skills/debugging")));
}
#[test]
fn default_has_no_skill_paths() {
let config = AgentConfig::default();
assert!(config.skill_paths.is_empty());
}
#[test]
fn serialization_roundtrip_with_skill_paths() {
let config =
AgentConfig::new("Test agent").with_skill_paths(&[PathBuf::from("./skills")]);
let json = serde_json::to_string(&config).unwrap();
let deserialized: AgentConfig = serde_json::from_str(&json).unwrap();
assert_eq!(config, deserialized);
assert_eq!(deserialized.skill_paths, vec![PathBuf::from("./skills")]);
}
}
}