tokitai 0.6.0

Tokitai - AI tool integration system with compile-time tool definitions
Documentation

Tokitai

Crates.io Documentation License Build Status

One attribute, and your Rust code is AI-callable

use tokitai::tool;

#[tool]  // <- this is the only line you need!
impl MyTools {
    pub fn add(&self, a: i32, b: i32) -> i32 {
        a + b
    }
}

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

[dependencies]
tokitai = "0.5.0"

That's it. All required dependencies (serde, serde_json, thiserror) are pulled in automatically.

2. Define your tools

use tokitai::tool;

#[tool]
struct Calculator;

#[tool]
impl Calculator {
    /// Add two numbers
    pub fn add(&self, a: i32, b: i32) -> i32 {
        a + b
    }
}

3. Get the tool definitions

let tools = Calculator::tool_definitions();

4. Handle an AI call

use tokitai::json;

let calc = Calculator::default();
let result = calc.call_tool("add", &json!({"a": 10, "b": 20}))?;
println!("{}", result);  // 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

#[tool]
impl MyTools {
    /// Custom name
    #[tool(name = "custom_name")]
    pub fn my_func(&self) {}

    /// Custom description
    #[tool(desc = "Custom description")]
    pub fn another_func(&self) {}

    /// Per-parameter attributes
    pub fn process(
        &self,
        #[tool(desc = "Parameter description", default = "null")]
        options: Option<String>
    ) {}
}

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

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 crates.io Main crate, includes the runtime support
tokitai-core crates.io Core types and traits (zero dependencies)
tokitai-macros crates.io Procedural-macro implementation

For 99% of users, this is all you need:

[dependencies]
tokitai = "0.5.0"

Examples

More examples live under the examples directory:

  • basic_usage.rs — basic usage
  • quick_chat.rs — interactive math calculator
  • version_management.rs — version-management attributes
  • ollama_integration.rs — Ollama AI integration

Happy coding!