use agentai::tool::{Tool, ToolBox, ToolError, ToolResult, toolbox};
use agentai::{Agent, AgentResult};
use anyhow::Error;
use log::{LevelFilter, info};
use simplelog::{ColorChoice, Config, TermLogger, TerminalMode};
const SYSTEM: &str = "You are helpful assistant. You goal is to provide summary for provided site. Limit you answer to 3 sentences.";
#[tokio::main]
async fn main() -> Result<(), Error> {
TermLogger::init(
LevelFilter::Trace,
Config::default(),
TerminalMode::Mixed,
ColorChoice::Auto,
)?;
info!("Starting AgentAI");
let question = "For what I can use this library? https://raw.githubusercontent.com/AdamStrojek/rust-agentai/refs/heads/master/README.md";
info!("Question: {}", question);
let toolbox = UrlFetcherToolBox {};
dbg!(toolbox.tools_definitions()?);
let model = std::env::var("AGENTAI_MODEL").unwrap_or("claude-haiku-5-5".to_string());
let agent = Agent::new(&model, SYSTEM)?.with_toolbox(toolbox);
let result: AgentResult<String> = agent.run(question).await?;
info!("Answer: {}", result.answer);
Ok(())
}
struct UrlFetcherToolBox {}
#[toolbox]
impl UrlFetcherToolBox {
#[tool]
async fn web_fetch(
&self,
url: String,
) -> ToolResult {
reqwest::get(&url)
.await
.map_err(|e| ToolError::Failed(format!("Request to {url} failed: {e}")))?
.text()
.await
.map_err(|e| ToolError::Failed(format!("Reading {url} failed: {e}")))
}
}