agentai 0.3.0

AgentAI is a Rust library designed to simplify the creation of AI agents.
Documentation
use agentai::tool::mcp::McpToolBox;
use agentai::{Agent, AgentResult};
use anyhow::Result;
use log::{LevelFilter, info};
use schemars::JsonSchema;
use serde::Deserialize;
use simplelog::{ColorChoice, Config, TermLogger, TerminalMode};

const SYSTEM: &str = "You are helpful assistant.";

#[tokio::main]
async fn main() -> Result<()> {
    TermLogger::init(
        LevelFilter::Trace,
        Config::default(),
        TerminalMode::Mixed,
        ColorChoice::Auto,
    )?;
    info!("Starting AgentAI");

    let question = "What is current time in Poland??";

    info!("Question: {}", question);

    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("nvidia/nemotron-3.5-super-vl:free".to_string());

    let agent = Agent::new_with_url(&base_url, &api_key, SYSTEM)?.with_model(&model);

    let mcp_tools =
        McpToolBox::new("uvx", ["mcp-server-time", "--local-timezone", "UTC"], None).await?;

    // The toolbox can also be set for one run only
    let result: AgentResult<Answer> = agent.run(question).with_toolbox(mcp_tools).await?;

    info!("{:#?}", result.answer);

    Ok(())
}

#[allow(dead_code)]
#[derive(Deserialize, JsonSchema, Debug)]
struct Answer {
    // It is always good idea to include thinking field for LLM's debugging
    /// In this field provide your thinking steps
    #[serde(rename = "_thinking")]
    thinking: String,

    /// In this field provide answer
    answer: String,
}