Skip to main content

Crate tools_rs

Crate tools_rs 

Source
Expand description

§Tools-rs: A Tool Collection and Execution Framework

Tools-rs provides a framework for building, registering, and executing tools with automatic JSON schema generation for LLM integration.

§Quick Start

use tools_rs::{tool, collect_tools, call_tool_with_args};

#[tool]
/// Adds two numbers together
async fn add(a: i32, b: i32) -> i32 {
    a + b
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let tools = collect_tools();
    let result = call_tool_with_args(&tools, "add", &[1, 2]).await?;
    println!("Result: {}", result);
    Ok(())
}

§Features

  • Automatic Registration: Use #[tool] to automatically register functions
  • JSON Schema Generation: Automatic schema generation for LLM integration
  • Type Safety: Full type safety with JSON serialization at boundaries
  • Async Support: Built for async/await from the ground up
  • Error Handling: Comprehensive error types with context

§Manual Registration

use tools_rs::ToolCollection;

let mut tools: ToolCollection = ToolCollection::new();
tools.register(
    "greet",
    "Greets a person",
    |name: String| async move { format!("Hello, {}!", name) },
    (),
)?;

Modules§

prelude
Convenient imports for common usage patterns.

Structs§

CallId
CollectionBuilder
Builder for ToolCollection with support for shared context injection. Construct via ToolCollection::builder().
DeserializationError
Specific deserialization errors
FunctionCall
Represents a function call with name and arguments
FunctionDecl
Function declaration for LLM consumption
FunctionResponse
Represents a function response with name and arguments
RawToolDef
A tool definition produced by an FFI adapter’s load() function.
ToolCollection
Collection of registered tools, parameterized by a metadata type M.
ToolMetadata
Metadata about a tool function
ToolRegistration
Tool registration for inventory collection. Constructed via struct literal in macro-generated code; field additions are minor-version breaking changes.
ToolsBuilder
Typestate builder for ToolCollection.
TypeSignature
Runtime type signature information

Enums§

Language
Scripting language for FFI tool adapters.
ToolError
Errors that can occur during tool operations

Traits§

ToolSchema
Trait for types that can generate a JSON Schema representation of themselves.

Functions§

call_tool
Call a tool by name with JSON arguments.
call_tool_by_name
Call a tool by name with JSON arguments on a given collection.
call_tool_with
Call a tool by name with typed arguments.
call_tool_with_args
Call a tool by name with typed arguments on a given collection.
collect_tools
Collect all tools registered via the #[tool] macro.
function_declarations
Generate function declarations in JSON format for LLM consumption.
list_tool_names
List all available tool names in a collection.

Attribute Macros§

tool

Derive Macros§

ToolSchema