Level 0, why agents and why Rust
Before any code, let's be clear about what we are building and why.
One prompt, or an agent?
You already know the simple way to use a language model: send it a prompt, get text back. That is enough for a lot of work. Summarize this email. Rewrite this paragraph. If the model has everything it needs in the prompt, one call is all you need, and you should not reach for anything bigger.
Now picture a customer asking "where is my order A-1001?". The model cannot know. The answer lives in your database. Someone has to look it up, read the result, and maybe look up something else before there is an answer worth sending. You could write that flow yourself, one if at a time. Or you could give the model a way to ask for the lookup, run the lookup when it asks, hand back the result, and let it decide what to do next.
That loop is an agent: a model with a job, some tools it may call, and a loop that keeps going until it has an answer. The model decides the steps. Your code decides what the model is allowed to do, and how much it may spend doing it.
Once an agent does real work, new problems show up fast. A run takes minutes and the process gets restarted halfway through. A loop goes on longer than you expected and the bill grows. Someone asks why the agent answered the way it did. Most of this course is about those problems, because they are what separates a demo from an application.
Why troupekit exists
I was building an app with agents in Rust, and I wanted a framework that was simple but complete: agents described as personas, runs I could stop and resume from the same point, and something reliable. Rig and langchain-rust exist, and the app started on Rig, but neither could pause a run and pick it up from the same point. Local and on-device models were missing too.
So I built the framework inside that app, and there it gave better results than the other frameworks had. Within days it had its own name, its own workspace with no app code in it, and then its own repository. The ideas came from many places, and they are credited openly: the provider layer follows Rig's design, the middleware ideas come from AutoAgents, and features come from Agno, LangChain and LangGraph.
Why Rust
An agent that runs inside your own program is one more part of that program. In Rust that means one binary, no Python runtime next to it, and the same code on a server, a laptop or a phone. Troupekit's CI builds it for Linux on x86_64 and aarch64, Windows, macOS, Android and iOS.
It also means the compiler checks more of your agent than you might expect. A tool is a plain Rust function, and its argument types become the schema the model must follow. Arguments of the wrong shape are refused before your function runs.
Who this course is for
- You already build agents or GenAI applications in Rust.
- You are moving to Rust from Python or TypeScript, or you are curious about Rust.
- You build agents in Python or TypeScript today and want to see another way.
- You write application, backend, mobile or JNI code and want an agent inside it.
Your first run
Here is the smallest agent in the course, course_hello:
#![allow(unused)]
fn main() {
use troupekit::agent::Limits;
use troupekit::prelude::*;
/// Explain to a programmer who has never used one what an LLM agent is,
/// in three short sentences, with one everyday example.
#[agent(
model = "anthropic/claude-haiku-5-5",
max_turns = 2,
limits = Limits { run: Some(20_000), ..Limits::default() },
)]
fn explainer() {}
}
That empty function is the whole agent. The #[agent] macro reads the doc comment as the agent's instructions, the function name as its name, and the keys as its settings. max_turns = 2 stops the loop after two model turns, and limits caps the run at 20 000 millionths of a dollar, which is two cents. We come back to both in later lessons.
Running it is one line:
#![allow(unused)]
fn main() {
let answer = explainer()
.run("What is an agent, and when would I want one?")
.await?;
println!("{answer}");
}
Try it:
export ANTHROPIC_API_KEY=sk-ant-...
cargo run -p troupekit --example course_hello
You should see three sentences about agents. If you get an error that names ANTHROPIC_API_KEY instead, the key is not set in that shell.
Next: Your first agent, where we build an agent once, run it twice and read what each run cost.