troupekit 0.4.0

Rust framework for LLM agents that run inside your own program: #[agent] functions or persona TOML files, tools, memory, document search and graph workflows that survive a restart.
Documentation
use troupekit::agent::Limits;
use troupekit::prelude::*;

/// Looks up the status of one order. Order numbers look like A-1001.
#[tool]
fn order_status(order: String) -> Result<String, String> {
    match order.trim() {
        "A-1001" => Ok("shipped on 2026-11-20, arriving in 2 to 4 business days".to_string()),
        "A-1002" => Ok("packed and waiting for the courier".to_string()),
        other => Err(format!(
            "no order {other}; the number is on the confirmation email"
        )),
    }
}

/// Returns the shipping cost in euros for a parcel of `grams` to `country`,
/// given as a two-letter code such as DE or FR.
#[tool]
fn shipping_cost(country: String, grams: u32) -> Result<String, String> {
    let base = match country.trim().to_ascii_uppercase().as_str() {
        "DE" => 4.90,
        "FR" | "NL" | "AT" => 7.50,
        other => return Err(format!("we do not ship to {other} yet")),
    };
    let extra = f64::from(grams.saturating_sub(1_000) / 1_000) * 1.20;
    Ok(format!("{:.2} EUR", base + extra))
}

/// You answer customer questions for a small online shop. Use the tools
/// for every order and shipping question. When a tool returns an error,
/// tell the customer what to check instead of guessing.
#[agent(
    model = "anthropic/claude-haiku-5-5",
    tools = [order_status, shipping_cost],
    max_turns = 4,
    limits = Limits { run: Some(30_000), ..Limits::default() },
)]
fn shop_helper() {}

/// Asks three questions: one per tool and one that makes a tool fail.
/// Input: ANTHROPIC_API_KEY in the environment. Output: the answers.
#[tokio::main]
async fn main() -> Result<(), KitError> {
    let agent = shop_helper().build().await?;
    for question in [
        "Where is my order A-1001?",
        "What does it cost to send 2500 grams to France?",
        "Where is order B-77?",
    ] {
        let outcome = agent.run_with(question).await?;
        println!(
            "> {question}\n{}\n({} model calls)\n",
            outcome.text(),
            outcome.model_calls()
        );
    }
    Ok(())
}