troupekit-context 0.3.2

Memory scopes, chunking, embeddings and hybrid retrieval for the Troupekit LLM agent framework.
Documentation
cargo add troupekit
cargo add tokio --features rt-multi-thread,macros

Troupekit: a Rust framework for LLM agents

crates.io docs API CI MSRV license

Troupekit is an open-source Rust framework for LLM agents that run inside your own program. You write an agent as a Rust function with #[agent], or as a persona TOML file. You give it tools, memory and documents, and you can run it in graph workflows that survive a restart.

Why Troupekit

Everything lives in one Rust workspace, with no Python runtime: agents, workflows, retrieval, memory and tracing. Stores stay in memory until you ask for durability. Call Troupe::builder().sqlite(path) and every run checkpoints into one SQLite file, and a killed process can resume the run where it stopped.

The model can be hosted or local. Troupekit calls Anthropic, OpenAI, Gemini and any OpenAI-compatible server, or runs a GGUF model on the device through llama.cpp. A route policy can pick between them for each call.

Your own documents are searchable by keyword, by vector or both, with HNSW and quantized indexes, all in the same SQLite file. CI builds the whole thing for Linux on x86_64 and aarch64, Windows, macOS, Android and iOS.

Quick start

The quickest way to see it run is the bundled example, from a clone:

git clone https://github.com/ChaoticQubit/troupekit
cd troupekit
export OPENAI_API_KEY=sk-...
cargo run -p troupekit --example hello

The example is the whole program:

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(())
}

The doc comment becomes the agent's instructions. The model is a vendor/model selector from the built-in catalog in crates/troupekit-providers/catalog/providers.toml, and the key comes from <VENDOR>_API_KEY, here OPENAI_API_KEY.

crates/troupekit/examples/ has more to try. tool_agent gives an agent a #[tool]. kill_resume runs a SQLite-backed workflow that resumes after its process is killed. support_agent answers customer questions from a folder of Markdown articles; it needs --features knowledge.

To use it in your own project, add it with the cargo add lines at the top, or in Cargo.toml:

[dependencies]
troupekit = "0.3.1"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }

To try unreleased changes on main, depend on the repository instead: troupekit = { git = "https://github.com/ChaoticQubit/troupekit", branch = "main" }.

Crates

Crate What
troupekit Entry crate. use troupekit::prelude::* for the macros and builders; Troupe::builder() wires in-memory or SQLite stores and hands out a runner; re-exports the engines
troupekit-kit Ergonomic API: one builder or one macro per agent, tool and graph
troupekit-macros The #[agent] and #[tool] attribute macros
troupekit-core Messages, secrets, errors, events, ids, clock, storage traits and in-memory stores
troupekit-providers Anthropic, OpenAI, Gemini and OpenAI-compatible wire protocols, provider catalog with prices, retry, fallback and cost metering
troupekit-local On-device models: the LocalModel trait, a model catalog and llama.cpp
troupekit-tools Tool trait, validating registry, SSRF-guarded web fetch, web search over Brave and SearXNG, declarative HTTP tools
troupekit-context Memory scopes, profile facts, chunking, embeddings, hybrid retrieval and context blocks
troupekit-index Vector indexes: exact brute force and HNSW, f16 and i8 quantization, persistable pages
troupekit-agent Persona TOML agents: layered loader, checkpointable run, typed output, evals and LLM judge, budgets
troupekit-graph TOML workflows of agent, tool, human, router, join and end nodes, with parallel branches, human pauses and retries
troupekit-host Leased job queue, event log and a runner with worker and serverless step modes, crash-safe resume
troupekit-store-sqlite One SQLite file for checkpoints, memory logs, blobs, the job queue and the usage ledger; optional SQLCipher
troupekit-trace Zero-dependency trace spans, sinks and viewers
troupekit-cli The troupekit command: troupekit ingest <dir> builds a searchable index in one SQLite file, troupekit trace <file> shows a trace

Feature flags

Features of the troupekit crate:

Feature Default What
kit yes The #[agent] and #[tool] macros and the Agent and Graph builders
sqlite yes SQLite stores through Troupe::builder().sqlite(path)
reqwest yes The HTTP transport for cloud providers. Turn it off to build without the TLS stack
knowledge no Document loading, embeddings and hybrid search for agents
sqlcipher no Encrypted SQLite with a vendored OpenSSL
sqlcipher-system no Encrypted SQLite with the system OpenSSL
local no The LocalModel trait and model catalog
llama no llama.cpp models. Needs CMake and the llama.cpp source: run sh scripts/fetch-llama.sh or set TROUPEKIT_LLAMA_SRC

Supported Rust

Rust 1.89 or newer for troupekit, troupekit-kit, troupekit-store-sqlite and troupekit-cli; 1.85 or newer for the other crates.

Status and roadmap

Troupekit is at 0.3, before 1.0: the API can change between minor versions.

Release Theme A user can
0.1 Survives a restart Kill the app mid-run and resume from SQLite
0.2 Knows your docs Search local documents by keyword, vector or hybrid, and remember facts
0.3 (current) Thinks offline Run on a local GGUF model or switch to cloud by policy, and trace a run
0.4 In your app Call Troupekit from Swift, Kotlin and Python, and use Apple and Android on-device models
0.5 Works in teams Use team, crew and handoff patterns in TOML, parallel branches, and fork a run
0.6 Plugs in anywhere Use MCP tools, and expose Troupekit as an MCP server
0.7 Proven Prove workflow properties with Bend, replay runs deterministically and run evals
1.0 On-device core Meet the 1.0 acceptance criteria on Linux, Windows, macOS, Android and iOS

Contributing

See CONTRIBUTING.md. Report security issues as described in SECURITY.md. Everyone taking part follows the Code of Conduct.

License

Licensed under either of MIT or Apache-2.0, at your option. Unless you state otherwise, any contribution you submit for inclusion is dual licensed the same way, without any additional terms or conditions.