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";
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
}
#[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(())
}