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}
56
57impl DeepAgentConfig {
58 pub fn new(instructions: impl Into<String>, planner: Arc<dyn PlannerHandle>) -> Self {
59 Self {
60 instructions: instructions.into(),
61 planner,
62 tools: Vec::new(),
63 subagent_configs: Vec::new(),
64 summarization: None,
65 tool_interrupts: HashMap::new(),
66 builtin_tools: None,
67 auto_general_purpose: true,
68 enable_prompt_caching: false,
69 checkpointer: None,
70 event_dispatcher: None,
71 }
72 }
73
74 pub fn with_tool(mut self, tool: ToolBox) -> Self {
75 self.tools.push(tool);
76 self
77 }
78
79 pub fn with_subagent_config(mut self, config: SubAgentConfig) -> Self {
81 self.subagent_configs.push(config);
82 self
83 }
84
85 pub fn with_subagent_configs<I>(mut self, configs: I) -> Self
87 where
88 I: IntoIterator<Item = SubAgentConfig>,
89 {
90 self.subagent_configs.extend(configs);
91 self
92 }
93
94 pub fn with_summarization(mut self, config: SummarizationConfig) -> Self {
95 self.summarization = Some(config);
96 self
97 }
98
99 pub fn with_tool_interrupt(mut self, tool_name: impl Into<String>, policy: HitlPolicy) -> Self {
100 self.tool_interrupts.insert(tool_name.into(), policy);
101 self
102 }
103
104 pub fn with_builtin_tools<I, S>(mut self, names: I) -> Self
108 where
109 I: IntoIterator<Item = S>,
110 S: Into<String>,
111 {
112 let set: HashSet<String> = names.into_iter().map(|s| s.into()).collect();
113 self.builtin_tools = Some(set);
114 self
115 }
116
117 pub fn with_auto_general_purpose(mut self, enabled: bool) -> Self {
120 self.auto_general_purpose = enabled;
121 self
122 }
123
124 pub fn with_prompt_caching(mut self, enabled: bool) -> Self {
127 self.enable_prompt_caching = enabled;
128 self
129 }
130
131 pub fn with_checkpointer(mut self, checkpointer: Arc<dyn Checkpointer>) -> Self {
133 self.checkpointer = Some(checkpointer);
134 self
135 }
136
137 pub fn with_event_broadcaster(
139 mut self,
140 broadcaster: Arc<dyn agents_core::events::EventBroadcaster>,
141 ) -> Self {
142 if self.event_dispatcher.is_none() {
143 self.event_dispatcher = Some(Arc::new(agents_core::events::EventDispatcher::new()));
144 }
145 if let Some(dispatcher) = Arc::get_mut(self.event_dispatcher.as_mut().unwrap()) {
146 dispatcher.add_broadcaster(broadcaster);
147 }
148 self
149 }
150
151 pub fn with_event_dispatcher(
153 mut self,
154 dispatcher: Arc<agents_core::events::EventDispatcher>,
155 ) -> Self {
156 self.event_dispatcher = Some(dispatcher);
157 self
158 }
159}
160
161pub struct SubAgentConfig {
180 pub name: String,
182 pub description: String,
183 pub instructions: String,
184
185 pub model: Option<Arc<dyn agents_core::llm::LanguageModel>>,
187 pub tools: Option<Vec<ToolBox>>,
188 pub builtin_tools: Option<HashSet<String>>,
189 pub enable_prompt_caching: bool,
190}
191
192impl SubAgentConfig {
193 pub fn new(
195 name: impl Into<String>,
196 description: impl Into<String>,
197 instructions: impl Into<String>,
198 ) -> Self {
199 Self {
200 name: name.into(),
201 description: description.into(),
202 instructions: instructions.into(),
203 model: None,
204 tools: None,
205 builtin_tools: None,
206 enable_prompt_caching: false,
207 }
208 }
209
210 pub fn with_model(mut self, model: Arc<dyn agents_core::llm::LanguageModel>) -> Self {
212 self.model = Some(model);
213 self
214 }
215
216 pub fn with_tools(mut self, tools: Vec<ToolBox>) -> Self {
218 self.tools = Some(tools);
219 self
220 }
221
222 pub fn with_builtin_tools(mut self, tools: HashSet<String>) -> Self {
224 self.builtin_tools = Some(tools);
225 self
226 }
227
228 pub fn with_prompt_caching(mut self, enabled: bool) -> Self {
230 self.enable_prompt_caching = enabled;
231 self
232 }
233}
234
235impl IntoIterator for SubAgentConfig {
236 type Item = SubAgentConfig;
237 type IntoIter = std::iter::Once<SubAgentConfig>;
238
239 fn into_iter(self) -> Self::IntoIter {
240 std::iter::once(self)
241 }
242}
243
244#[derive(Clone)]
246pub struct SummarizationConfig {
247 pub messages_to_keep: usize,
248 pub summary_note: String,
249}