Tokitai
One attribute, and your Rust code is AI-callable
use tool;
// <- this is the only line you need!
Compile-time generation · Zero runtime intrusion · Type-safe by construction
Compile-time AI tool definitions · Zero runtime footprint · Magic-sticker integration
Tokitai is a procedural-macro library with zero runtime dependencies. A single #[tool] attribute turns your Rust methods into AI-callable tools, and every tool definition is generated at compile time so type errors surface during compilation.
5-minute quick start
1. Add the dependency
[]
= "0.5.0"
That's it. All required dependencies (serde, serde_json, thiserror) are pulled in automatically.
2. Define your tools
use tool;
;
3. Get the tool definitions
let tools = tool_definitions;
4. Handle an AI call
use json;
let calc = default;
let result = calc.call_tool?;
println!; // 30
Core features
| Feature | Description |
|---|---|
| Zero dependency footprint | Add only tokitai = "0.5.0" |
| Compile-time generation | Tool definitions are generated during compilation, so type errors surface early |
| One attribute | Just #[tool] — no chain of annotations to remember |
| Type-safe by construction | Rust types are mapped to JSON Schema automatically |
| Provider-agnostic | Works with any AI / LLM provider |
Type mapping
| Rust type | JSON Schema |
|---|---|
String, &str |
string |
i32, i64, u32, ... |
integer |
f32, f64 |
number |
bool |
boolean |
Vec<T> |
array |
Option<T> |
optional T |
user-defined struct |
object |
Common attributes
Wrap features (v0.5+)
In addition to the core #[tool] macro, the workspace ships a family of auto-wrapping macros that turn existing clients, OpenAPI specs, and resilience policies into tools with a single attribute: #[wrap], #[openapi] / #[openapi_op], #[delegate], #[retry], #[rate_limit], and #[circuit_breaker]. See the Wrap architecture and the Wrap cheatsheet for the full picture, and the workspace README for the at-a-glance summary.
Documentation
- 5-minute quick start — a more detailed getting-started walkthrough
- Advanced usage — advanced features and best practices
- Type system — how Rust types map to JSON Schema
- AI integration — integrating with AI providers
- Architecture — project structure and design
- Wrap architecture — the auto-wrapping macros
- API reference — full API documentation
Requirements
- Rust version: 1.80+
- Edition: 2021
License
Licensed under either of:
at your option.
Contributing
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual-licensed as above, without any additional terms or conditions.
Sub-crates
Tokitai is shipped as three crates:
| Crate | Crates.io | Role |
|---|---|---|
tokitai |
Main crate, includes the runtime support | |
tokitai-core |
Core types and traits (zero dependencies) | |
tokitai-macros |
Procedural-macro implementation |
For 99% of users, this is all you need:
[]
= "0.5.0"
Examples
More examples live under the examples directory:
basic_usage.rs— basic usagequick_chat.rs— interactive math calculatorversion_management.rs— version-management attributesollama_integration.rs— Ollama AI integration
Happy coding!