Skip to main content

Crate troupekit

Crate troupekit 

Source
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, IntoToolOutput and Input stay 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; build checks everything, reports the first problem and makes no model call. run and run_with build and run in one call.
AgentMemory
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.
BuiltAgent
An agent that passed every build check, 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.
BuiltGraph
A graph that passed every build check, 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.
GraphReport
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.
HnswParams
Build and search settings of an HNSW index. Fields are private; start from Default and use the with_* setters. new_index validates the values.
Input
What an agent runs on: one user text, or a prepared conversation. Built from &str, String, one Message or a Vec<Message>. An empty conversation fails when the run starts.
Json
Wraps any Serialize value 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. At build the folder is ingested into index index of the store file (unchanged files skipped) and the agent gets the search_knowledge tool. 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. auto asks the verifier to also derive laws from the code, and defaults to true.
OpenReport
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. text is the answer as text; output is the raw final value. Read it through the getters.
RunStream
A run in progress that yields its events in seq order. Every method takes &self, so one task may read events while another cancels or waits in finish. Dropping the last owner cancels the run.
SqliteStore
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.
SqliteStoreBuilder
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. open validates them and opens the file.
SqliteVectors
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) and custom(store) keep runs for resume.
StreamSettings
Buffer settings of one streamed run. capacity (default 4096, from MIN_CAPACITY to MAX_CAPACITY) bounds queued events: when full a new text delta is dropped and counted; lifecycle events are always kept.
ToolContext
Per-call context handed to every tool. Cheap to clone, so typed tool closures can own a copy across awaits. run_id names the run that made the call; idempotency_key is the same for a replayed call and new for every other, for tools that dedupe.
ToolOutput
What a tool returns to the model. is_error marks 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().
TroupeBuilder
Settings for a Troupe. With no store chosen the five stores live in memory and nothing survives a restart. sqlite and sqlite_with put all five in one file. clock sets the job queue’s time source.
VectorSettings
Settings of one named vector index. dims is 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 with new(dims).

Enums§

Durability
How hard a commit is pushed to disk, per connection. Full survives power loss: every commit uses fullfsync, which Apple platforms need. Normal is faster and can lose the last commits on power loss, never on a process kill; WAL checkpoints still use fullfsync, so no corruption.
IndexKind
Which index to build. Default BruteForce, which is exact. Hnsw is approximate and faster on large sets. Passed to new_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.
LocalChoice
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 with From; read at build.
Progress
Where a run stands after one resume_for window. Done holds the answer as text; Pending means 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. F32 is exact, F16 halves memory, I8 quarters it with one f32 scale per vector. Default F32.

Constants§

MAX_PERSONA_BYTES
Largest persona TOML that Agent::from_toml and from_toml_file accept, in bytes. Larger text or files fail at build with KitError::Config. Fixed at 1 MiB.
MAX_STEPS_PER_WINDOW
Most steps one resume_for call takes before it returns Pending, 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 the tool(..) function form both qualify; an Arc<dyn Tool> goes through .tool_arc(..) instead.
IntoToolOutput
Converts a tool fn’s return value into what the model sees. Text, numbers, bool, (), JSON values, Json<T>, Option<T> and Result<T, E: Display> convert; an Err becomes 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 against spec().schema when called through a registry.

Functions§

tool
Builds a tool from argument type A and async fn f, without a macro. f takes the parsed arguments and returns any IntoToolOutput value; name and description are what the model sees. The schema is the same one typed_tool derives from A.

Attribute Macros§

agent
Turns fn calc() {} into a fn returning a configured Agent: the doc comment becomes the instructions and the fn name, _ read as -, the agent name. Keys such as model, tools = [add] and evals map to the builder methods of the same name.
tool
Turns a fn into a tool value: #[tool] async fn add(a: i64, b: i64) makes add a unit struct implementing Tool; the doc comment is the description, the arguments the schema, and the body stays callable as add::invoke(..). An imported add turns a let add binding into a unit-struct pattern: rename the binding or use the tool by path. Keys: name, description, crate.