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::*;

const MODEL: &str = "anthropic/claude-haiku-5-5";

/// Collapses runs of spaces and trims the customer's message.
#[tool]
fn clean(input: String) -> String {
    input.split_whitespace().collect::<Vec<_>>().join(" ")
}

/// Turns the drafted reply into a ticket line that starts with its length.
#[tool]
fn ticket(reply: String) -> String {
    format!("[{} chars] {reply}", reply.chars().count())
}

/// Runs a three-node chain: a tool fn, an agent and a tool fn. Each node
/// reads the output of the node before it. Input: ANTHROPIC_API_KEY.
/// Output: the final ticket line, the state of one node and the usage.
#[tokio::main]
async fn main() -> Result<(), KitError> {
    let writer = Agent::new("reply")
        .model(MODEL)
        .instructions("Write a friendly two-sentence reply to the customer's message.")
        .max_turns(2);
    let report = Graph::new("triage")
        .step("clean", clean)
        .agent("reply", writer)
        .step("ticket", ticket)
        .limits(Limits {
            run: Some(20_000),
            ..Limits::default()
        })
        .run_with("   my parcel   is late   and nobody answers   ")
        .await?;
    println!("ticket: {}", report.output().as_str().unwrap_or_default());
    println!("clean:  {}", report.state()["clean"]);
    println!(
        "steps:  {}, cost: {} millionths of a dollar",
        report.steps(),
        report.usage().cost_usd_micros
    );
    Ok(())
}