use crate::compress::CompressionConfig;
pub const MAX_ITERATIONS: usize = 200;
#[derive(Debug, Clone)]
pub struct AgentConfig {
pub max_iterations: usize,
pub max_retries: u32,
pub retry_delay_ms: u64,
pub max_tool_result_size: usize,
pub max_todo_reminders: usize,
pub iteration_warning_threshold: usize,
pub compression: CompressionConfig,
pub max_tokens: u32,
pub context_size_override: Option<u32>,
pub think: bool,
}
impl Default for AgentConfig {
fn default() -> Self {
Self {
max_iterations: MAX_ITERATIONS,
max_retries: 5,
retry_delay_ms: 1000,
max_tool_result_size: 50_000,
max_todo_reminders: 2,
iteration_warning_threshold: MAX_ITERATIONS.saturating_sub(10),
compression: CompressionConfig::default(),
max_tokens: crate::constants::QUICK_ACTION_MAX_TOKENS,
context_size_override: None,
think: false,
}
}
}
impl AgentConfig {
pub fn new(
max_tokens: u32,
context_size_override: Option<u32>,
think: bool,
compression: CompressionConfig,
) -> Self {
Self {
max_tokens,
context_size_override,
think,
compression,
..Self::default()
}
}
pub fn with_max_iterations(max_iterations: usize) -> Self {
Self {
max_iterations,
iteration_warning_threshold: max_iterations.saturating_sub(10),
..Self::default()
}
}
pub fn with_compression(compression: CompressionConfig) -> Self {
Self {
compression,
..Self::default()
}
}
pub fn simple_task() -> Self {
Self {
max_iterations: 50,
iteration_warning_threshold: 40,
max_tool_result_size: 10_000,
..Self::default()
}
}
pub fn complex_task() -> Self {
Self {
max_iterations: 300,
iteration_warning_threshold: 290,
max_tool_result_size: 100_000,
max_todo_reminders: 3,
..Self::default()
}
}
pub fn max_tokens(&self) -> u32 {
self.max_tokens
}
pub fn context_size_override(&self) -> Option<u32> {
self.context_size_override
}
pub fn think(&self) -> bool {
self.think
}
pub fn compression_config(&self) -> &CompressionConfig {
&self.compression
}
pub fn compression_config_mut(&mut self) -> &mut CompressionConfig {
&mut self.compression
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_default_config_matches_hardcoded_values() {
let config = AgentConfig::default();
assert_eq!(config.max_iterations, 200, "max_iterations default changed");
assert_eq!(config.max_retries, 5, "max_retries default changed");
assert_eq!(config.retry_delay_ms, 1000, "retry_delay_ms default changed");
assert_eq!(config.max_tool_result_size, 50_000, "max_tool_result_size default changed");
assert_eq!(config.max_todo_reminders, 2, "max_todo_reminders default changed");
assert_eq!(config.iteration_warning_threshold, 190, "iteration_warning_threshold default changed");
}
#[test]
fn test_with_max_iterations_adjusts_warning_threshold() {
let config = AgentConfig::with_max_iterations(100);
assert_eq!(config.max_iterations, 100);
assert_eq!(config.iteration_warning_threshold, 90, "warning threshold should be max - 10");
}
#[test]
fn test_with_max_iterations_handles_small_values() {
let config = AgentConfig::with_max_iterations(5);
assert_eq!(config.iteration_warning_threshold, 0, "threshold should use saturating_sub");
}
#[test]
fn test_simple_task_optimization() {
let config = AgentConfig::simple_task();
assert_eq!(config.max_iterations, 50, "simple tasks should have lower iteration limit");
assert_eq!(config.max_tool_result_size, 10_000, "simple tasks should have smaller result size");
}
#[test]
fn test_complex_task_optimization() {
let config = AgentConfig::complex_task();
assert_eq!(config.max_iterations, 300, "complex tasks should have higher iteration limit");
assert_eq!(config.max_tool_result_size, 100_000, "complex tasks should have larger result size");
assert_eq!(config.max_todo_reminders, 3, "complex tasks should allow more reminders");
}
}