agents_runtime/agent/
config.rs1use crate::middleware::{AgentMiddleware, HitlPolicy};
7use agents_core::agent::PlannerHandle;
8use agents_core::persistence::Checkpointer;
9use agents_core::tools::ToolBox;
10use std::collections::{HashMap, HashSet};
11use std::sync::Arc;
12
13#[derive(Default)]
29pub struct CreateDeepAgentParams {
30 pub tools: Vec<ToolBox>,
31 pub instructions: String,
32 pub middleware: Vec<Arc<dyn AgentMiddleware>>,
33 pub model: Option<Arc<dyn agents_core::llm::LanguageModel>>,
34 pub subagents: Vec<SubAgentConfig>,
35 pub context_schema: Option<String>,
36 pub checkpointer: Option<Arc<dyn Checkpointer>>,
37 pub tool_configs: HashMap<String, HitlPolicy>,
38}
39
40pub struct DeepAgentConfig {
44 pub instructions: String,
45 pub planner: Arc<dyn PlannerHandle>,
46 pub tools: Vec<ToolBox>,
47 pub subagent_configs: Vec<SubAgentConfig>,
48 pub summarization: Option<SummarizationConfig>,
49 pub tool_interrupts: HashMap<String, HitlPolicy>,
50 pub builtin_tools: Option<HashSet<String>>,
51 pub auto_general_purpose: bool,
52 pub enable_prompt_caching: bool,
53 pub checkpointer: Option<Arc<dyn Checkpointer>>,
54 pub event_dispatcher: Option<Arc<agents_core::events::EventDispatcher>>,
55 pub enable_pii_sanitization: bool,
56}
57
58impl DeepAgentConfig {
59 pub fn new(instructions: impl Into<String>, planner: Arc<dyn PlannerHandle>) -> Self {
60 Self {
61 instructions: instructions.into(),
62 planner,
63 tools: Vec::new(),
64 subagent_configs: Vec::new(),
65 summarization: None,
66 tool_interrupts: HashMap::new(),
67 builtin_tools: None,
68 auto_general_purpose: true,
69 enable_prompt_caching: false,
70 checkpointer: None,
71 event_dispatcher: None,
72 enable_pii_sanitization: true, }
74 }
75
76 pub fn with_tool(mut self, tool: ToolBox) -> Self {
77 self.tools.push(tool);
78 self
79 }
80
81 pub fn with_subagent_config(mut self, config: SubAgentConfig) -> Self {
83 self.subagent_configs.push(config);
84 self
85 }
86
87 pub fn with_subagent_configs<I>(mut self, configs: I) -> Self
89 where
90 I: IntoIterator<Item = SubAgentConfig>,
91 {
92 self.subagent_configs.extend(configs);
93 self
94 }
95
96 pub fn with_summarization(mut self, config: SummarizationConfig) -> Self {
97 self.summarization = Some(config);
98 self
99 }
100
101 pub fn with_tool_interrupt(mut self, tool_name: impl Into<String>, policy: HitlPolicy) -> Self {
102 self.tool_interrupts.insert(tool_name.into(), policy);
103 self
104 }
105
106 pub fn with_builtin_tools<I, S>(mut self, names: I) -> Self
110 where
111 I: IntoIterator<Item = S>,
112 S: Into<String>,
113 {
114 let set: HashSet<String> = names.into_iter().map(|s| s.into()).collect();
115 self.builtin_tools = Some(set);
116 self
117 }
118
119 pub fn with_auto_general_purpose(mut self, enabled: bool) -> Self {
122 self.auto_general_purpose = enabled;
123 self
124 }
125
126 pub fn with_prompt_caching(mut self, enabled: bool) -> Self {
129 self.enable_prompt_caching = enabled;
130 self
131 }
132
133 pub fn with_checkpointer(mut self, checkpointer: Arc<dyn Checkpointer>) -> Self {
135 self.checkpointer = Some(checkpointer);
136 self
137 }
138
139 pub fn with_event_broadcaster(
141 mut self,
142 broadcaster: Arc<dyn agents_core::events::EventBroadcaster>,
143 ) -> Self {
144 if self.event_dispatcher.is_none() {
145 self.event_dispatcher = Some(Arc::new(agents_core::events::EventDispatcher::new()));
146 }
147 if let Some(dispatcher) = Arc::get_mut(self.event_dispatcher.as_mut().unwrap()) {
148 dispatcher.add_broadcaster(broadcaster);
149 }
150 self
151 }
152
153 pub fn with_event_dispatcher(
155 mut self,
156 dispatcher: Arc<agents_core::events::EventDispatcher>,
157 ) -> Self {
158 self.event_dispatcher = Some(dispatcher);
159 self
160 }
161
162 pub fn with_pii_sanitization(mut self, enabled: bool) -> Self {
171 self.enable_pii_sanitization = enabled;
172 self
173 }
174}
175
176pub struct SubAgentConfig {
195 pub name: String,
197 pub description: String,
198 pub instructions: String,
199
200 pub model: Option<Arc<dyn agents_core::llm::LanguageModel>>,
202 pub tools: Option<Vec<ToolBox>>,
203 pub builtin_tools: Option<HashSet<String>>,
204 pub enable_prompt_caching: bool,
205}
206
207impl SubAgentConfig {
208 pub fn new(
210 name: impl Into<String>,
211 description: impl Into<String>,
212 instructions: impl Into<String>,
213 ) -> Self {
214 Self {
215 name: name.into(),
216 description: description.into(),
217 instructions: instructions.into(),
218 model: None,
219 tools: None,
220 builtin_tools: None,
221 enable_prompt_caching: false,
222 }
223 }
224
225 pub fn with_model(mut self, model: Arc<dyn agents_core::llm::LanguageModel>) -> Self {
227 self.model = Some(model);
228 self
229 }
230
231 pub fn with_tools(mut self, tools: Vec<ToolBox>) -> Self {
233 self.tools = Some(tools);
234 self
235 }
236
237 pub fn with_builtin_tools(mut self, tools: HashSet<String>) -> Self {
239 self.builtin_tools = Some(tools);
240 self
241 }
242
243 pub fn with_prompt_caching(mut self, enabled: bool) -> Self {
245 self.enable_prompt_caching = enabled;
246 self
247 }
248}
249
250impl IntoIterator for SubAgentConfig {
251 type Item = SubAgentConfig;
252 type IntoIter = std::iter::Once<SubAgentConfig>;
253
254 fn into_iter(self) -> Self::IntoIter {
255 std::iter::once(self)
256 }
257}
258
259#[derive(Clone)]
261pub struct SummarizationConfig {
262 pub messages_to_keep: usize,
263 pub summary_note: String,
264}