use dotenv::dotenv;
use std::env;
use swarms_rs::{
Agent, agent::swarms_agent::SwarmsAgentBuilder, llm::provider::openai::OpenAI,
logging::init_logger, structs::agent::AgentConfig,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
init_logger();
dotenv().ok();
let api_key = env::var("OPENAI_API_KEY").unwrap_or_else(|_| {
println!("⚠️ OPENAI_API_KEY not set, using demo key (will show API errors)");
"demo-key".to_string()
});
let model = OpenAI::new(api_key).set_model("gpt-4o-mini");
let config = AgentConfig::builder()
.agent_name("LoggingDemoAgent")
.user_name("TestUser")
.description("An agent to demonstrate comprehensive logging")
.temperature(0.7)
.max_loops(2)
.max_tokens(100)
.enable_plan(Some("Plan this task step by step".to_string()))
.enable_autosave()
.retry_attempts(1)
.build();
let agent = SwarmsAgentBuilder::new_with_model(model)
.config((*config).clone())
.system_prompt("You are a helpful assistant that demonstrates logging capabilities.")
.build();
println!("🚀 Starting logging demonstration...");
println!("💡 Tip: Set SWARMS_LOG_LEVEL=DEBUG for more detailed output");
println!("💡 Available levels: TRACE, DEBUG, INFO, WARN, ERROR, OFF");
println!("\n📝 Testing simple prompt...");
let prompt_result = agent.prompt("What is 2+2?").await;
match prompt_result {
Ok(response) => println!("✅ Prompt response received: {}", response),
Err(e) => println!("❌ Prompt failed: {}", e),
}
println!("\n🎯 Testing full agent task execution...");
let task = "Write a haiku about artificial intelligence";
match agent.run(task.to_string()).await {
Ok(result) => {
println!("✅ Task completed successfully!");
println!("📋 Result: {}", result);
},
Err(e) => {
println!("❌ Task failed: {}", e);
},
}
println!("\n🎉 Logging demonstration complete!");
println!("📊 Check the logs above to see the comprehensive logging in action.");
Ok(())
}