Expand description
Troupekit is an open-source Rust framework for LLM agents that run inside
your own program. Write an agent as a Rust function with #[agent] or as a
persona TOML file, give it tools, memory and documents, and run it in graph
workflows that survive a restart. Guide: https://chaoticqubit.github.io/troupekit/.
This is the entry crate. use troupekit::prelude::*; gives the #[agent]
and #[tool] macros and the Agent and Graph builders (feature kit,
on by default). Troupe::builder() wires the five stores, in memory by
default or in one SQLite file with sqlite(path), and hands out a
Runner over them. The engines are re-exported as modules.
Re-exports§
pub use troupekit_agent as agent;pub use troupekit_core as core;pub use troupekit_graph as graph;pub use troupekit_host as host;pub use troupekit_providers as providers;pub use troupekit_tools as tools;pub use troupekit_trace as trace;pub use troupekit_local as local;pub use troupekit_context as context;
Modules§
- knowledge
- Ingest a folder into a named vector index in the store file. Unchanged files are skipped by content hash, changed files are replaced whole, a file that fails is recorded and the walk goes on, and the sources of files gone from the folder are removed.
- prelude
- The names most programs need, for
use troupekit::prelude::*;. Builder, built agent, outcome, storage, laws, errors and tools.AsTool,IntoToolOutputandInputstay at the crate root.
Structs§
- Agent
- Builds one agent from a name to an answer: model, instructions, tools,
evals, limits, storage and laws. Setters never fail;
buildchecks everything, reports the first problem and makes no model call.runandrun_withbuild and run in one call. - Agent
Memory - Long-term memory for one user and one session: facts about the user and a session summary, kept in a SQLite file. The agent gets the five memory tools, bound to this user and session, and by default the facts and summary are prepended to every run’s input.
- Built
Agent - An agent that passed every
buildcheck, ready to run many times. Cheap to clone and safe to share across tasks; each run gets its own state, and in-memory checkpoints are dropped after the run. - Built
Graph - A graph that passed every
buildcheck, ready to run many times. Cheap to clone and safe to share across tasks; in-memory checkpoints are dropped after each run. - Graph
- Builds a pipeline of agents and tool fns that run one after another. Each node reads the output of the node before it, the first reads the input; the last node’s output is the answer. Fan-out, routers and human nodes stay in workflow TOML.
- Graph
Report - The result of one finished graph run: the last node’s output, the whole state, usage, steps and the run id. Read it through the getters.
- Hnsw
Params - Build and search settings of an HNSW index.
Fields are private; start from
Defaultand use thewith_*setters.new_indexvalidates the values. - Input
- What an agent runs on: one user text, or a prepared conversation.
Built from
&str,String, oneMessageor aVec<Message>. An empty conversation fails when the run starts. - Json
- Wraps any
Serializevalue so a tool can return it as JSON text. A serialize failure becomes an error output naming the failure. Use it for structs:Json(Point { x, y }). - Knowledge
- A folder an agent can search:
Knowledge::dir("docs")plus settings. Atbuildthe folder is ingested into indexindexof the store file (unchanged files skipped) and the agent gets thesearch_knowledgetool. The embedder defaults to the catalog’s for the agent’s vendor. - Laws
- The laws attached to an agent or graph, checked at
build. 0.2 stores and validates them; no run proves them yet.autoasks the verifier to also derive laws from the code, and defaults totrue. - Open
Report - How often the index behind a handle was loaded from the file and how often its pages were refused and rebuilt from vectors, counted since the store opened. Shared by every handle of the same name.
- RunOutcome
- The result of one finished run: the answer and how it was reached.
textis the answer as text;outputis the raw final value. Read it through the getters. - RunStream
- A run in progress that yields its events in
seqorder. Every method takes&self, so one task may read events while another cancels or waits infinish. Dropping the last owner cancels the run. - Sqlite
Store - Durable Troupekit store over one SQLite file in WAL mode. Cheap to clone; clones share one connection. Every call runs on tokio’s blocking pool, so it needs a tokio runtime. A caller that stops waiting does not stop the call: it runs to its commit or rollback.
- Sqlite
Store Builder - Settings for
SqliteStore, each with a safe default: full durability, the system clock, 64 MiB caps on one state and one blob, 100 000 history steps and 1 GiB of history state, a 5 000 ms busy timeout and secure delete on.openvalidates them and opens the file. - Sqlite
Vectors - A named vector index in the store file, with text, metadata and a
keyword index kept in the same transactions. Cheap to clone; clones
and other handles of the same name share one in-memory index. Every
call checks the dimension and the bounds of its
VectorSettings. - Storage
- Where an agent or graph keeps run checkpoints.
memory()(the default) uses a fresh in-memory store per run, so nothing grows;sqlite(path)andcustom(store)keep runs forresume. - Stream
Settings - Buffer settings of one streamed run.
capacity(default 4096, fromMIN_CAPACITYtoMAX_CAPACITY) bounds queued events: when full a new text delta is dropped and counted; lifecycle events are always kept. - Tool
Context - Per-call context handed to every tool.
Cheap to clone, so typed tool closures can own a copy across awaits.
run_idnames the run that made the call;idempotency_keyis the same for a replayed call and new for every other, for tools that dedupe. - Tool
Output - What a tool returns to the model.
is_errormarks content that describes a failure the model may react to, such as an HTTP error status from a remote API. - Troupe
- The five stores of one Troupekit host, shared by every runner built
from it. Cheap to clone. Build it with
Troupe::builder(). - Troupe
Builder - Settings for a
Troupe. With no store chosen the five stores live in memory and nothing survives a restart.sqliteandsqlite_withput all five in one file.clocksets the job queue’s time source. - Vector
Settings - Settings of one named vector index.
dimsis required; the rest has safe defaults: brute force, f32 in memory, 1 MiB of text per chunk, 64 meta pairs of at most 256 and 4 096 bytes, 10 000 records per call, keyword queries of 32 terms and 2 000 chars. Built withnew(dims).
Enums§
- Durability
- How hard a commit is pushed to disk, per connection.
Fullsurvives power loss: every commit usesfullfsync, which Apple platforms need.Normalis faster and can lose the last commits on power loss, never on a process kill; WAL checkpoints still usefullfsync, so no corruption. - Index
Kind - Which index to build. Default
BruteForce, which is exact.Hnswis approximate and faster on large sets. Passed tonew_index. - KitError
- Every failure of the kit: builder settings, catalog and key problems, and the wrapped engine errors, plus run outcomes that are not an answer. Messages name the agent and the fix; they never hold an API key.
- Local
Choice - Where an on-device model comes from: a row id of the built-in local
catalog (
&str), a GGUF file (PathBuf), or a loaded model (Arc<dyn LocalModel>). Converts withFrom; read atbuild. - Progress
- Where a run stands after one
resume_forwindow.Doneholds the answer as text;Pendingmeans the budget or the step bound ran out first, and the run resumes from its last save. - Quantization
- In-memory format of stored vectors. Queries stay f32.
F32is exact,F16halves memory,I8quarters it with one f32 scale per vector. DefaultF32.
Constants§
- MAX_
PERSONA_ BYTES - Largest persona TOML that
Agent::from_tomlandfrom_toml_fileaccept, in bytes. Larger text or files fail atbuildwithKitError::Config. Fixed at 1 MiB. - MAX_
STEPS_ PER_ WINDOW - Most steps one
resume_forcall takes before it returnsPending, whatever the budget. Bounds a window even when steps are instant. Fixed at 10 000.
Traits§
- AsTool
- Anything an agent or graph accepts as a tool: every
Tool + 'static. A#[tool]fn and thetool(..)function form both qualify; anArc<dyn Tool>goes through.tool_arc(..)instead. - Into
Tool Output - Converts a tool fn’s return value into what the model sees.
Text, numbers,
bool,(), JSON values,Json<T>,Option<T>andResult<T, E: Display>convert; anErrbecomes an error output so the model can react to the failure instead of the run stopping. - Tool
- A capability an agent can call: a spec the model sees and an async call.
Object safe, so registries hold
Arc<dyn Tool>. Arguments arrive as JSON already checked againstspec().schemawhen called through a registry.
Functions§
- tool
- Builds a tool from argument type
Aand async fnf, without a macro.ftakes the parsed arguments and returns anyIntoToolOutputvalue;nameanddescriptionare what the model sees. The schema is the same onetyped_toolderives fromA.
Attribute Macros§
- agent
- Turns
fn calc() {}into a fn returning a configuredAgent: the doc comment becomes the instructions and the fn name,_read as-, the agent name. Keys such asmodel,tools = [add]andevalsmap to the builder methods of the same name. - tool
- Turns a fn into a tool value:
#[tool] async fn add(a: i64, b: i64)makesadda unit struct implementingTool; the doc comment is the description, the arguments the schema, and the body stays callable asadd::invoke(..). An importedaddturns alet addbinding into a unit-struct pattern: rename the binding or use the tool by path. Keys: name, description, crate.