1use crate::tools::Tool;
6use std::collections::HashMap;
7use std::sync::Arc;
8
9#[cfg(feature = "serde")]
10use serde::{Deserialize, Serialize};
11
12#[derive(Debug, Clone)]
14#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
15pub struct AgentConfig {
16 pub name: String,
17 pub description: String,
18 pub system_prompt: String,
19 pub temperature: f32,
20 pub max_tokens: Option<usize>,
21 pub tools: Vec<String>,
22}
23
24impl Default for AgentConfig {
25 fn default() -> Self {
26 Self {
27 name: "assistant".to_string(),
28 description: "A helpful AI assistant".to_string(),
29 system_prompt: "You are a helpful AI assistant.".to_string(),
30 temperature: 0.7,
31 max_tokens: Some(1000),
32 tools: Vec::new(),
33 }
34 }
35}
36
37pub struct AgentBuilder {
39 config: AgentConfig,
40 tools: HashMap<String, Arc<dyn Tool>>,
41}
42
43impl AgentBuilder {
44 pub fn new(name: impl Into<String>) -> Self {
45 Self {
46 config: AgentConfig {
47 name: name.into(),
48 ..Default::default()
49 },
50 tools: HashMap::new(),
51 }
52 }
53
54 pub fn with_description(mut self, description: impl Into<String>) -> Self {
55 self.config.description = description.into();
56 self
57 }
58
59 pub fn with_system_prompt(mut self, prompt: impl Into<String>) -> Self {
60 self.config.system_prompt = prompt.into();
61 self
62 }
63
64 pub fn with_temperature(mut self, temperature: f32) -> Self {
65 self.config.temperature = temperature.clamp(0.0, 2.0);
66 self
67 }
68
69 pub fn with_tool(mut self, name: String, tool: Arc<dyn Tool>) -> Self {
70 self.config.tools.push(name.clone());
71 self.tools.insert(name, tool);
72 self
73 }
74}
75
76pub trait Agent: Send + Sync {
78 fn name(&self) -> &str;
80
81 fn description(&self) -> &str;
83
84 fn config(&self) -> &AgentConfig;
86}