Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Introduction

Troupekit is a Rust framework for building LLM agents that run inside your own program. You describe an agent in Rust with the #[agent] macro, or in a persona TOML file. You give it tools, documents and memory, and run it on a hosted model, on a model on the device, or on whichever of the two a policy picks for each call. The whole stack is one Rust library: there is no Python runtime, no server to deploy and no separate database. Its state lives in memory, or in one SQLite file when you want it to survive a crash.

It is for Rust developers who want an agent as part of an app or a service rather than as a hosted product. A desktop app, a backend worker and a tool on a small Linux board all link the same crate. Phone apps can use it too: version 0.4 builds for iOS and Android and has the Swift and Kotlin bindings that let an app call it, built from source for now.

The problem it solves

An agent run is long and fragile. It makes several model calls, each one slow and paid for, and calls tools between them. If the process dies halfway, because a server restarts or a phone OS kills a background app, a naive loop loses everything and pays for the same calls again. Troupekit records each step of a run as a checkpoint. With the SQLite store, a new process can pick up a run by its id and carry on from the last finished step.

The second problem is where the model runs. A hosted model is strong but needs the network and costs money per token. A small local model is free and private but weaker. Troupekit lets one agent use both: a route policy sends each call to the device or the cloud based on the network, a spend budget, and the battery and heat of the device.

A first agent

Here is the smallest program. We define an agent with a doc comment as its instructions, then run it once:

use troupekit::prelude::*;

/// Greet the user by name.
#[agent(model = "openai/gpt-6-luna")]
fn greeter() {}

#[tokio::main]
async fn main() -> Result<(), KitError> {
    println!("{}", greeter().run("I am Ada").await?);
    Ok(())
}

#[agent] turns the empty fn into one that returns a configured Agent, named greeter after the fn. run checks the settings, reads OPENAI_API_KEY, makes the model call and returns the answer as a String. The Quick start runs this program and then gives the agent a tool.

What ships today

Everything below is in 0.4 today. The Rust crates are on crates.io; the Swift, Kotlin and Python bindings are built from source.

AreaWhat you get
AgentsThe #[agent] macro, the Agent builder and persona TOML files, with tools, typed output, evals and spend limits. See Agents and personas.
ToolsRust fns as tools with #[tool], a guarded web fetch, web search, and HTTP endpoints declared in TOML. See Tools.
Hosted modelsSeven vendors in the built-in catalog: Anthropic, OpenAI, Google, OpenRouter, Groq, DeepSeek and Mistral. Any other OpenAI-compatible server works through your own catalog file. See Models and providers.
Local modelsOllama and LM Studio as local servers, and GGUF files run in process through llama.cpp with the llama feature. See Local models and routing.
RoutingA route policy, in Rust or TOML, that picks local or cloud per call and falls back when a target fails.
DocumentsSearch over a folder by keyword (SQLite FTS5), by vector, or both fused. Vector indexes are exact or HNSW, with optional f16 or i8 quantization. See Knowledge and retrieval.
MemoryFacts about one user and a summary of one session, kept apart per user. See Memory and storage.
WorkflowsThe Graph builder for a chain of steps, and TOML workflows with agent, tool, human, router, join and end nodes. A workflow run resumes after a crash. See Workflows and graphs.
TracingOne call, .tracing(true), records every model call, tool call and graph step as spans in a JSONL file. troupekit trace shows them in the terminal or as one HTML page. See Tracing and budgets.
StorageCheckpoints, memory, blobs, a job queue and a usage ledger in memory or in one SQLite file, optionally encrypted with SQLCipher.
PlatformsCI builds for Linux on x86_64 and aarch64, Windows, macOS, Android and iOS. See Platform support.
AppsSwift and Kotlin bindings for iOS and Android apps, Python bindings, and adapters for on-device models: Apple Foundation Models on iOS, and a LiteRT-LM model file your app supplies on Android. Built from the repository with cargo xtask build-xcframework, cargo xtask build-aar and cargo xtask build-wheel.

Note

Laws (.bend files) are checked, stored and traced in 0.4, but a run does not prove them yet; that arrives in 0.7.

What is coming

SPM, Maven and PyPI packages for the 0.4 bindings are not published yet. Version 0.5 is about agents working together: team, crew and handoff patterns in TOML, parallel branches, fan-out over a list, and forking a run from any checkpoint.

The Roadmap lists every planned release.

How troupekit compares

Rust already has good agent frameworks, and most of them cover more ground than troupekit does today. Each mark comes from the project's own repository, its README, docs and source, as read on 2026-11-28.

FeatureTroupekitRiglangchain-rustSwiftideKalosmAutoAgentsChidori
Agents written in Rust✓✓✓✓✗✓✗
Agent or workflow files in TOML or YAML✓✗✗✗✗✓✗
Graph workflows✓✗✗✓✗✗✗
Pause a run for a human✓✓✗✓✗✗✓
Resume a run after a crash✓✓✗✗✗✗✓
Record and replay a run✗ 0.7✓✗✗✗✗✓
Local models in process✓✓✗✗✓✓✗
Local model servers such as Ollama✓✓✓✓✓✓✓
Local or cloud chosen per call by policy✓✗✗✗✗✗✗
Built-in hybrid search✓✗✗✓✓✗✗
External vector databases✗ 2.0✓✓✓✓✓✗
Long-term memory across sessions✓✓✓✗✗✗✓
Spend limits in USD or tokens✓✗✗✗✗✗✗
Tracing of model and tool calls✓✓✓✓✗✓✓
MCP tools✗ 0.6✓✗✓✗✓✓
Use from Python (bindings or SDK)✓ from source✗✗✗✗✓✓
Rust builds for iOS or Android✓✗✗✗✗✓✗

✓ has it. ✗ does not. A version after ✗ means planned for that release. Spend limits are marked at each project's latest release: Rig's cap is in its coding agent, not the library, and langchain-rust's token hook is on its main branch only. The Compare section reads twenty frameworks in Rust, Python and TypeScript at their releases, with the same agent built in each.

Each of the others is the better pick for some jobs. Rig, the largest of these, puts over 20 model providers and a dozen vector stores behind one interface, has MCP tools, record and replay and resumable sessions, and builds for browser WASM. langchain-rust suits you if you already think in LangChain chains. Swiftide focuses on streaming indexing pipelines and typed task graphs. Kalosm is about running local text, audio and image models. AutoAgents has Python bindings, an Android example app and sandboxed WASM tools. Chidori makes every run durable and replays it byte for byte; you write its agents in TypeScript and can drive them from a Python or TypeScript app. Troupekit is the only one here that picks local or cloud per call by policy, and it keeps durable runs, memory and hybrid search in one SQLite file.

The crates

Version 0.4 is a workspace of nineteen crates, seventeen of them on crates.io. You normally depend on troupekit only; it re-exports the engines as modules.

CrateWhat it does
troupekitEntry crate: one builder that wires the stores, the runner and the engines.
troupekit-kitErgonomic API: one builder or one macro per agent, tool and graph.
troupekit-macrosThe #[tool] and #[agent] attribute macros.
troupekit-coreCore types and storage traits.
troupekit-agentPersona TOML agents: loader, checkpointable run state machine, typed output, evals and budgets.
troupekit-graphDurable TOML workflows of agent, tool, human, router, join and end nodes.
troupekit-hostA leased job queue, an event log and a runner with worker and serverless step modes.
troupekit-providersModel providers: wire protocols, catalog, transports and middleware.
troupekit-toolsTool trait, registry, guarded web fetch, web search and declarative HTTP tools.
troupekit-contextMemory scopes, chunking, embeddings and hybrid retrieval.
troupekit-indexVector indexes: exact brute force and HNSW, with f16 and i8 quantization.
troupekit-store-sqliteCheckpoints, memory logs, blobs, a job queue and a usage ledger in one SQLite file.
troupekit-localOn-device models: the LocalModel trait, model catalog and llama.cpp.
troupekit-traceZero-dependency trace spans, sinks and viewers.
troupekit-cliCommand line: ingest a folder into a searchable index, and view traces.
troupekit-ffi-coreBinding-neutral API that the Swift, Kotlin and Python bindings share.
troupekit-ffiThe UniFFI layer for the Swift and Kotlin bindings.
troupekit-pyThe PyO3 layer for the Python bindings; built from source, not on crates.io.
troupekit-e2eEnd-to-end tests against real models; not on crates.io.

License

Licensed under either of MIT or Apache-2.0, at your option.