Tokitai Core
Core types for Tokitai - Compile-time tool definitions with zero runtime dependencies
This crate provides the fundamental types and traits for the Tokitai AI tool integration system. All tool information is generated at compile time, ensuring zero runtime overhead and maximum type safety.
🎯 Key Features
- Zero Runtime Dependencies - Core types have minimal dependencies
no_stdSupport - Works in embedded environments (whenserdefeature is disabled)- Type Safety - Compile-time tool definitions prevent runtime errors
- Serde Integration - Optional serialization support via the
serdefeature
Core Types
- [
ToolDefinition] - Tool definition containing name, description, and input schema - [
ToolParameter] - Parameter definition for tools - [
ParamType] - JSON Schema type enumeration - [
ToolError] - Error type for tool invocation failures - [
ToolErrorKind] - Classification of tool errors - [
ToolProvider] - Trait for tool providers (auto-implemented by#[tool]macro)
Usage Example
use ToolDefinition;
// Create a tool definition
let tool = new;
assert_eq!;
assert_eq!;
// With serde feature enabled, convert to JSON
No-Std Support
This crate supports no_std environments when the serde feature is disabled:
[]
= { = "0.3", = false }
Type Mapping
The [ParamType] enum maps Rust types to JSON Schema types:
| Rust Type | JSON Schema Type | ParamType Variant |
|---|---|---|
String, &str |
string |
ParamType::String |
i8, i16, i32, i64, u8, u16, u32, u64 |
integer |
ParamType::Integer |
f32, f64 |
number |
ParamType::Number |
bool |
boolean |
ParamType::Boolean |
Vec<T> |
array |
ParamType::Array |
| Custom structs | object |
ParamType::Object |
use ParamType;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Error Handling
The [ToolError] type provides structured error handling for tool invocations:
use ;
// Create different error types
let validation_err = validation_error;
assert_eq!;
let not_found_err = not_found;
assert_eq!;
let internal_err = internal_error;
assert_eq!;
Tool Provider Trait
The [ToolProvider] trait is automatically implemented by the #[tool] macro:
use ToolProvider;
// After using #[tool] macro on your type:
// struct Calculator;
// #[tool] impl Calculator { ... }
// Get all tool definitions
// let tools = Calculator::tool_definitions();
// Get tool count
// let count = Calculator::tool_count();
// Find a specific tool
// let tool = Calculator::find_tool("add");
JSON Schema Macro
The json_schema! macro helps generate JSON Schema strings at compile time:
use json_schema;
const SCHEMA: &str = json_schema!;
Features
| Feature | Description |
|---|---|
serde (default) |
Enable serde serialization and JSON support |
Requirements
- Rust Version: 1.70+
- Edition: 2021
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
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.
See Also
tokitai- Main crate with runtime supporttokitai-macros- Procedural macros