coro_core/agent/
config.rs

1//! Agent configuration structures
2
3use serde::{Deserialize, Serialize};
4
5/// Output mode for the agent
6#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
7pub enum OutputMode {
8    /// Debug mode with detailed logging and verbose output
9    Debug,
10    /// Normal mode with clean, user-friendly output
11    Normal,
12}
13
14impl Default for OutputMode {
15    fn default() -> Self {
16        Self::Normal
17    }
18}
19
20/// Configuration for an agent
21#[derive(Debug, Clone, Serialize, Deserialize)]
22pub struct AgentConfig {
23    /// Maximum number of execution steps
24    pub max_steps: usize,
25
26    /// Whether to enable lakeview integration
27    pub enable_lakeview: bool,
28
29    /// List of tools available to this agent
30    pub tools: Vec<String>,
31
32    /// Output mode for the agent (debug or normal)
33    #[serde(default)]
34    pub output_mode: OutputMode,
35
36    /// Custom system prompt for the agent (optional)
37    /// If not provided, the default system prompt will be used
38    #[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
59/// Builder for creating agents with resolved LLM configuration
60pub struct AgentBuilder {
61    llm_config: crate::config::ResolvedLlmConfig,
62    agent_config: AgentConfig,
63    abort_controller: Option<super::AbortController>,
64}
65
66impl AgentBuilder {
67    /// Create a new agent builder with LLM configuration
68    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    /// Set agent configuration
77    pub fn with_agent_config(mut self, agent_config: AgentConfig) -> Self {
78        self.agent_config = agent_config;
79        self
80    }
81
82    /// Set maximum steps
83    pub fn with_max_steps(mut self, max_steps: usize) -> Self {
84        self.agent_config.max_steps = max_steps;
85        self
86    }
87
88    /// Set tools
89    pub fn with_tools(mut self, tools: Vec<String>) -> Self {
90        self.agent_config.tools = tools;
91        self
92    }
93
94    /// Set output mode
95    pub fn with_output_mode(mut self, output_mode: OutputMode) -> Self {
96        self.agent_config.output_mode = output_mode;
97        self
98    }
99
100    /// Set system prompt
101    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    /// Inject a global AbortController for cancellation support
107    pub fn with_cancellation(mut self, controller: super::AbortController) -> Self {
108        self.abort_controller = Some(controller);
109        self
110    }
111
112    /// Build the agent with the given output handler
113    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    /// Build the agent with custom output handler and tool registry
127    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    /// Build the agent with null output (for testing)
143    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}