Tools-rs is a dynamic framework designed for constructing and executing tools with automatic JSON schema generation, tailor-made for Large Language Model integration. Featuring compile-time function registration, type safety, async support, and rich error handling, it enhances the functionality of your applications while simplifying tool management.
Tools-rs is a robust framework designed for building, registering, and executing various tools with enhanced integration capabilities for Large Language Models (LLMs). This framework simplifies the entire process of tool management, featuring automatic JSON schema generation and comprehensive type safety.
#[tool] for seamless compile-time discovery and registration.tokio, this framework leverages async/await for efficient asynchronous execution.inventory crate for link-time tool collection, ensuring zero-cost runtime discovery.Here’s a concise example of how to use Tools-rs:
use serde_json::json;
use tools_rs::{collect_tools, FunctionCall, tool};
#[tool]
/// Adds two numbers.
async fn add(pair: (i32, i32)) -> i32 {
pair.0 + pair.1
}
#[tool]
/// Greets a person.
async fn greet(name: String) -> String {
format!("Hello, {name}!")
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let tools = collect_tools();
let sum = tools
.call(FunctionCall::new(
"add".into(),
json!({ "pair": [3, 4] }),
))
.await?.result;
println!("add → {sum}"); // Outputs: "add → 7"
let hi = tools
.call(FunctionCall::new(
"greet".into(),
json!({ "name": "Alice" }),
))
.await?.result;
println!("greet → {hi}"); // Outputs: "greet → \"Hello, Alice!\""
// Export function declarations for LLM APIs
let declarations = tools.json()?;
println!("Function declarations: {}", serde_json::to_string_pretty(&declarations)?);
Ok(())
}
Tools-rs is organized into a Rust workspace consisting of three primary crates:
Resources such as comprehensive examples and usage scenarios are readily available in the examples directory.
Tools-rs is tailored for performance with minimal overhead during tool registration and execution. It requires Rust version 1.85 or later, providing support for full type checking and graceful error handling.
Utilizing efficient data structures ensures that tool discovery remains low-cost, promoting high performance across various operations.
Consider Tools-rs when you need a powerful framework for your tools that handles LLM integrations effortlessly, providing type safety and automatic schema generation.
No comments yet.
Sign in to be the first to comment.