use agentai::tool::{toolbox, Tool, ToolBox, ToolError, ToolResult};
use agentai::Agent;
use anyhow::Error;
use log::{info, LevelFilter};
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 base_url = std::env::var("AGENTAI_BASE_URL")?;
let api_key = std::env::var("AGENTAI_API_KEY")?;
let model = std::env::var("AGENTAI_MODEL").unwrap_or("openai/gpt-4.1-mini".to_string());
let mut agent = Agent::new_with_url(&base_url, &api_key, SYSTEM);
let answer: String = agent.run(&model, question, Some(&toolbox)).await?;
info!("Answer: {}", answer);
Ok(())
}
struct UrlFetcherToolBox {}
#[toolbox]
impl UrlFetcherToolBox {
#[tool]
async fn web_fetch(
&self,
url: String,
) -> ToolResult {
Ok(reqwest::get(url)
.await
.map_err(anyhow::Error::new)?
.text()
.await
.map_err(anyhow::Error::new)?)
}
}