coro_core/agent/
config.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
7pub enum OutputMode {
8 Debug,
10 Normal,
12}
13
14impl Default for OutputMode {
15 fn default() -> Self {
16 Self::Normal
17 }
18}
19
20#[derive(Debug, Clone, Serialize, Deserialize)]
22pub struct AgentConfig {
23 pub max_steps: usize,
25
26 pub enable_lakeview: bool,
28
29 pub tools: Vec<String>,
31
32 #[serde(default)]
34 pub output_mode: OutputMode,
35
36 #[serde(default)]
39 pub system_prompt: Option<String>,
40}
41
42impl Default for AgentConfig {
43 fn default() -> Self {
44 Self {
45 max_steps: 200,
46 enable_lakeview: true,
47 tools: vec![
48 "bash".to_string(),
49 "str_replace_based_edit_tool".to_string(),
50 "sequentialthinking".to_string(),
51 "task_done".to_string(),
52 ],
53 output_mode: OutputMode::default(),
54 system_prompt: None,
55 }
56 }
57}
58
59pub struct AgentBuilder {
61 llm_config: crate::config::ResolvedLlmConfig,
62 agent_config: AgentConfig,
63 abort_controller: Option<super::AbortController>,
64}
65
66impl AgentBuilder {
67 pub fn new(llm_config: crate::config::ResolvedLlmConfig) -> Self {
69 Self {
70 llm_config,
71 agent_config: AgentConfig::default(),
72 abort_controller: None,
73 }
74 }
75
76 pub fn with_agent_config(mut self, agent_config: AgentConfig) -> Self {
78 self.agent_config = agent_config;
79 self
80 }
81
82 pub fn with_max_steps(mut self, max_steps: usize) -> Self {
84 self.agent_config.max_steps = max_steps;
85 self
86 }
87
88 pub fn with_tools(mut self, tools: Vec<String>) -> Self {
90 self.agent_config.tools = tools;
91 self
92 }
93
94 pub fn with_output_mode(mut self, output_mode: OutputMode) -> Self {
96 self.agent_config.output_mode = output_mode;
97 self
98 }
99
100 pub fn with_system_prompt(mut self, system_prompt: Option<String>) -> Self {
102 self.agent_config.system_prompt = system_prompt;
103 self
104 }
105
106 pub fn with_cancellation(mut self, controller: super::AbortController) -> Self {
108 self.abort_controller = Some(controller);
109 self
110 }
111
112 pub async fn build_with_output(
114 self,
115 output: Box<dyn crate::output::AgentOutput>,
116 ) -> crate::error::Result<super::AgentCore> {
117 super::AgentCore::new_with_llm_config(
118 self.agent_config,
119 self.llm_config,
120 output,
121 self.abort_controller,
122 )
123 .await
124 }
125
126 pub async fn build_with_output_and_registry(
128 self,
129 output: Box<dyn crate::output::AgentOutput>,
130 tool_registry: crate::tools::ToolRegistry,
131 ) -> crate::error::Result<super::AgentCore> {
132 super::AgentCore::new_with_output_and_registry(
133 self.agent_config,
134 self.llm_config,
135 output,
136 tool_registry,
137 self.abort_controller,
138 )
139 .await
140 }
141
142 pub async fn build(self) -> crate::error::Result<super::AgentCore> {
144 use crate::output::events::NullOutput;
145 self.build_with_output(Box::new(NullOutput)).await
146 }
147}