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 std::error::Error;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use troupekit::agent::Limits;
use troupekit::context::embed::HashingEmbedder;
use troupekit::prelude::*;

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

/// Builds a help desk agent over the folder `docs`, indexed into the
/// SQLite file `db`. The hashing embedder runs on this machine with no
/// network and no key. Input: folder and file. Output: the built agent.
async fn helpdesk(docs: &Path, db: &Path) -> Result<BuiltAgent, KitError> {
    Agent::new("helpdesk")
        .model(MODEL)
        .instructions(
            "Answer customer questions only from the shop's help articles. Search \
             them with search_knowledge before you answer. If the articles do not \
             cover the question, say so and do not guess.",
        )
        .knowledge(
            Knowledge::dir(docs)
                .store(db)
                .embedder(Arc::new(HashingEmbedder::new(256))),
        )
        .max_turns(4)
        .limits(Limits {
            run: Some(40_000),
            ..Limits::default()
        })
        .build()
        .await
}

/// Indexes the example help articles, then asks two questions the
/// articles answer and one they do not. Input: ANTHROPIC_API_KEY.
/// Output: each question and its answer on stdout.
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let docs = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples/support/docs");
    let dir = tempfile::tempdir()?;
    let agent = helpdesk(&docs, &dir.path().join("kb.db")).await?;
    for question in [
        "How long do I have to return an item?",
        "My parcel says delivered but it is not here. What do I do?",
        "Do you have a shop in Lisbon?",
    ] {
        println!("> {question}\n{}\n", agent.run(question).await?);
    }
    Ok(())
}