Repository navigation
Troupekit 0.4.0
Troupekit is an open-source Rust framework for LLM agents that run inside your own program. 0.4.0 lets you call it from Swift, Kotlin and Python, and adds adapters for the on-device models on iOS and Android.
cargo add troupekitSince 0.4.0, the spend fixes are in the 0.4.1 and 0.4.2 notes.
What is new
Python
- A
troupekitpackage over the Rust core, for Python 3.11 or newer. - Calls block with the GIL released.
troupekit.aiohas the async forms. - Your Python code can be the model, a tool or the HTTP transport. The agent calls back into it.
Swift, iOS 16 and macOS 13 or newer
Troupekit, the library over the Rust core.TroupekitApple, withAppleFoundationModelfor Apple's on-device Foundation Models, an Apple embedder and a URLSession transport.- The on-device model needs iOS 26 on a device that supports Apple Intelligence, with it turned on and the model downloaded. Its window is 4096 tokens, shared by instructions, documents and the answer.
Kotlin, Android API 26 or newer
troupekit, the module over the Rust core.troupekit-android, withOnDeviceModel, which loads a LiteRT-LM model file your app supplies, a configurable timeout for an on-device reply, and an HttpURLConnection transport.
In every binding
start(input)saves the first checkpoint and returns the run id before any model call, so the app holds the id before anything can die.- Stream a run's events to your app as they happen.
- Resume a run in bounded windows, so a phone's background time can carry it forward.
- Build and run graphs, add knowledge with an embedder your app supplies, and use memory.
- Load agents from persona TOML files.
Two demo apps
examples/ios, a SwiftUI support agent, andexamples/android, the same agent on platform Android views. Its runtime dependencies aretroupekit-androidand kotlinx-coroutines.- Both answer from bundled support articles and stream the answer.
- Force-quit either app mid-answer and open it again: it resumes the same run from the last checkpoint and shows the answer once.
- Both resume an unfinished run in a background window of up to 25 seconds, when the OS opens one.
- A cloud API key is stored in the Keychain on iOS and encrypted with a key held in the Android Keystore on Android. It is never part of the app bundle.
Spend and privacy
- Each routed call is billed at the target that served it, and a failed call that reported usage is billed too.
- An in-flight remote call's estimated cost is held against the daily cap until its real cost is recorded. Spend is reread across midnight, and the cap is checked again before a remote fallback.
- A private agent refuses to build without an on-device model, and refuses the built-in network tools:
web_fetch,web_search, declarative HTTP tools and hosted tools. - The agent's model API key is redacted from HTTP status error text and scrubbed from traces. The bindings also redact credential headers in every text form.
Install
- Rust:
cargo add troupekit. All 17 crates are on crates.io at 0.4.0. - Python, Swift and Kotlin build from a clone. PyPI, Swift Package Manager and Maven packages are not published yet.
- Python:
cargo xtask build-wheel, thenpython -m pip install dist/troupekit-*-abi3-*.whl. - Swift:
cargo xtask build-xcframework. The Swift package at the repository root uses it. - Kotlin:
cargo xtask build-aar.
Limits, stated up front
- A crash repeats the step that was running, every tool call and parallel branch in it included. Each tool call carries an idempotency key that stays the same on the replay, and a tool with side effects has to check it to skip the repeat.
- In 0.4.0 the spend estimate counted input as about four bytes per token, so a token-dense input could cost more than estimated (#80). 0.4.1 bounds the estimate's input at one token per byte.
- In 0.4.0 a shared period cap held within one process, and runs in separate processes could spend past it together (#79). From 0.4.1 a call's worst case is held in the store, so other processes see it. In SQLite a hold lasts
hold_ms, one hour by default. A call that runs longer than its hold gives its room back to other processes, so the cap can be passed (#204). - Anthropic cache writes are counted at the plain input price, so the spend ledger under-counts them and a cap can be passed (#202, open as of 0.4.2).
- A route's daily cloud cap is counted inside one process, so runs in separate processes can pass it together (#183, open).
- Traces scrub the agent's model API key only. A key a tool reads, or one held only by a custom model client, is not scrubbed.
- Laws on an agent are checked and stored. Proving them is planned for 0.7, and team, crew and handoff patterns for 0.5.
- Android ships no on-device text embedder. The Android demo finds its articles with a word-hash embedder, which matches on shared words only.
- The API can still change before 1.0.
Repo: https://github.com/ChaoticQubit/troupekit
Docs: https://troupekit.org/
Changelog: https://github.com/ChaoticQubit/troupekit/blob/main/CHANGELOG.md
