walrus_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
15#[derive(Debug, Clone, Serialize, Deserialize)]
21pub struct AgentConfig {
22 #[serde(skip)]
24 pub name: String,
25 #[serde(default)]
27 pub description: String,
28 #[serde(skip)]
30 pub system_prompt: String,
31 #[serde(default)]
33 pub model: Option<String>,
34 #[serde(default = "default_max_iterations")]
36 pub max_iterations: usize,
37 #[serde(skip)]
39 pub tool_choice: ToolChoice,
40 #[serde(default)]
42 pub thinking: bool,
43 #[serde(default)]
45 pub heartbeat: HeartbeatConfig,
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}
64
65fn default_max_iterations() -> usize {
66 DEFAULT_MAX_ITERATIONS
67}
68
69fn default_compact_threshold() -> Option<usize> {
70 Some(DEFAULT_COMPACT_THRESHOLD)
71}
72
73impl Default for AgentConfig {
74 fn default() -> Self {
75 Self {
76 name: String::new(),
77 description: String::new(),
78 system_prompt: String::new(),
79 model: None,
80 max_iterations: DEFAULT_MAX_ITERATIONS,
81 tool_choice: ToolChoice::Auto,
82 thinking: false,
83 heartbeat: HeartbeatConfig::default(),
84 members: Vec::new(),
85 skills: Vec::new(),
86 mcps: Vec::new(),
87 tools: Vec::new(),
88 compact_threshold: default_compact_threshold(),
89 }
90 }
91}
92
93impl AgentConfig {
94 pub fn new(name: impl Into<String>) -> Self {
96 Self {
97 name: name.into(),
98 ..Default::default()
99 }
100 }
101
102 pub fn system_prompt(mut self, prompt: impl Into<String>) -> Self {
104 self.system_prompt = prompt.into();
105 self
106 }
107
108 pub fn description(mut self, desc: impl Into<String>) -> Self {
110 self.description = desc.into();
111 self
112 }
113
114 pub fn model(mut self, name: impl Into<String>) -> Self {
116 self.model = Some(name.into());
117 self
118 }
119
120 pub fn thinking(mut self, enabled: bool) -> Self {
122 self.thinking = enabled;
123 self
124 }
125}
126
127#[derive(Debug, Clone, Serialize, Deserialize, Default)]
129pub struct HeartbeatConfig {
130 #[serde(default)]
132 pub interval: u64,
133 #[serde(default)]
135 pub prompt: String,
136}