use ai_agent_sdk::{Agent, EnvConfig, get_auto_compact_threshold};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("--- Example 14: Memory Compaction Demo ---\n");
let config = EnvConfig::load();
let model = config.model.unwrap_or_else(|| "claude-sonnet-4-6".to_string());
println!("Using model: {}", model);
println!("Auto-compact threshold: {} tokens\n", get_auto_compact_threshold(&model));
let mut agent = Agent::new(&model, 10);
let paragraph = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. \
Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. \
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris. \
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore. \
Eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident. \
Sunt in culpa qui officia deserunt mollit anim id est laborum.";
for i in 1..=5 {
println!("--- Turn {} ---", i);
let prompt = format!(
"Turn {}: Remember this: {}. Just say 'OK turn {}' if you understand.",
i, paragraph, i
);
let result = agent.prompt(&prompt).await?;
println!("Messages: {}", agent.get_messages().len());
println!("Response: {}\n", result.text.trim().lines().next().unwrap_or(""));
}
println!("--- Final Query ---");
let result = agent.prompt("What did I ask you to remember in turn 1?").await?;
println!("Messages: {}", agent.get_messages().len());
println!("Response: {}\n", result.text.trim().lines().next().unwrap_or(""));
println!("=== done ===");
Ok(())
}