walrus_core/agent/
config.rs1use crate::model::ToolChoice;
7use compact_str::CompactString;
8use serde::{Deserialize, Serialize};
9
10const DEFAULT_MAX_ITERATIONS: usize = 16;
12
13const DEFAULT_COMPACT_THRESHOLD: usize = 100_000;
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
22pub struct AgentConfig {
23 #[serde(skip)]
25 pub name: CompactString,
26 #[serde(default)]
28 pub description: CompactString,
29 #[serde(skip)]
31 pub system_prompt: String,
32 #[serde(default)]
34 pub model: Option<CompactString>,
35 #[serde(default = "default_max_iterations")]
37 pub max_iterations: usize,
38 #[serde(skip)]
40 pub tool_choice: ToolChoice,
41 #[serde(default)]
43 pub thinking: bool,
44 #[serde(default)]
46 pub heartbeat: HeartbeatConfig,
47 #[serde(default)]
49 pub members: Vec<String>,
50 #[serde(default)]
52 pub skills: Vec<String>,
53 #[serde(default)]
55 pub mcps: Vec<String>,
56 #[serde(skip)]
58 pub tools: Vec<CompactString>,
59 #[serde(default = "default_compact_threshold")]
63 pub compact_threshold: Option<usize>,
64}
65
66fn default_max_iterations() -> usize {
67 DEFAULT_MAX_ITERATIONS
68}
69
70fn default_compact_threshold() -> Option<usize> {
71 Some(DEFAULT_COMPACT_THRESHOLD)
72}
73
74impl Default for AgentConfig {
75 fn default() -> Self {
76 Self {
77 name: CompactString::default(),
78 description: CompactString::default(),
79 system_prompt: String::new(),
80 model: None,
81 max_iterations: DEFAULT_MAX_ITERATIONS,
82 tool_choice: ToolChoice::Auto,
83 thinking: false,
84 heartbeat: HeartbeatConfig::default(),
85 members: Vec::new(),
86 skills: Vec::new(),
87 mcps: Vec::new(),
88 tools: Vec::new(),
89 compact_threshold: default_compact_threshold(),
90 }
91 }
92}
93
94impl AgentConfig {
95 pub fn new(name: impl Into<CompactString>) -> Self {
97 Self {
98 name: name.into(),
99 ..Default::default()
100 }
101 }
102
103 pub fn system_prompt(mut self, prompt: impl Into<String>) -> Self {
105 self.system_prompt = prompt.into();
106 self
107 }
108
109 pub fn description(mut self, desc: impl Into<CompactString>) -> Self {
111 self.description = desc.into();
112 self
113 }
114
115 pub fn model(mut self, name: impl Into<CompactString>) -> Self {
117 self.model = Some(name.into());
118 self
119 }
120
121 pub fn thinking(mut self, enabled: bool) -> Self {
123 self.thinking = enabled;
124 self
125 }
126}
127
128#[derive(Debug, Clone, Serialize, Deserialize, Default)]
130pub struct HeartbeatConfig {
131 #[serde(default)]
133 pub interval: u64,
134 #[serde(default)]
136 pub prompt: String,
137}