crabtalk_core/agent/
config.rs1use crate::model::ToolChoice;
7use serde::{Deserialize, Serialize};
8
9const DEFAULT_MAX_ITERATIONS: usize = 16;
11
12const DEFAULT_COMPACT_THRESHOLD: usize = 100_000;
14
15const DEFAULT_COMPACT_TOOL_MAX_LEN: usize = 1024;
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
24pub struct AgentConfig {
25 #[serde(skip)]
27 pub name: String,
28 #[serde(default)]
30 pub description: String,
31 #[serde(skip)]
33 pub system_prompt: String,
34 #[serde(default)]
36 pub model: Option<String>,
37 #[serde(default = "default_max_iterations")]
39 pub max_iterations: usize,
40 #[serde(skip)]
42 pub tool_choice: ToolChoice,
43 #[serde(default)]
45 pub thinking: bool,
46 #[serde(default)]
48 pub members: Vec<String>,
49 #[serde(default)]
51 pub skills: Vec<String>,
52 #[serde(default)]
54 pub mcps: Vec<String>,
55 #[serde(skip)]
57 pub tools: Vec<String>,
58 #[serde(default = "default_compact_threshold")]
62 pub compact_threshold: Option<usize>,
63 #[serde(default = "default_compact_tool_max_len")]
66 pub compact_tool_max_len: usize,
67}
68
69fn default_max_iterations() -> usize {
70 DEFAULT_MAX_ITERATIONS
71}
72
73fn default_compact_threshold() -> Option<usize> {
74 Some(DEFAULT_COMPACT_THRESHOLD)
75}
76
77fn default_compact_tool_max_len() -> usize {
78 DEFAULT_COMPACT_TOOL_MAX_LEN
79}
80
81impl Default for AgentConfig {
82 fn default() -> Self {
83 Self {
84 name: String::new(),
85 description: String::new(),
86 system_prompt: String::new(),
87 model: None,
88 max_iterations: DEFAULT_MAX_ITERATIONS,
89 tool_choice: ToolChoice::Auto,
90 thinking: false,
91 members: Vec::new(),
92 skills: Vec::new(),
93 mcps: Vec::new(),
94 tools: Vec::new(),
95 compact_threshold: default_compact_threshold(),
96 compact_tool_max_len: DEFAULT_COMPACT_TOOL_MAX_LEN,
97 }
98 }
99}
100
101impl AgentConfig {
102 pub fn new(name: impl Into<String>) -> Self {
104 Self {
105 name: name.into(),
106 ..Default::default()
107 }
108 }
109
110 pub fn system_prompt(mut self, prompt: impl Into<String>) -> Self {
112 self.system_prompt = prompt.into();
113 self
114 }
115
116 pub fn description(mut self, desc: impl Into<String>) -> Self {
118 self.description = desc.into();
119 self
120 }
121
122 pub fn model(mut self, name: impl Into<String>) -> Self {
124 self.model = Some(name.into());
125 self
126 }
127
128 pub fn thinking(mut self, enabled: bool) -> Self {
130 self.thinking = enabled;
131 self
132 }
133}