Trait Tool

Source
pub trait Tool
where Self: JsonSchema,
{ // Required methods fn name(&self) -> &str; fn description(&self) -> &str; }
Expand description

Defines the contract for tools that can be used by LLMs

Tools provide a standardized way to extend language models with custom functionality. Each tool defines its name, description, parameter schema, and execution logic.

§Type Parameters

The Tool trait requires that implementors also implement JsonSchema, which is used to automatically generate JSON schemas for tool parameters.

§Examples

use language_barrier_core::Tool;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
struct WeatherRequest {
    location: String,
    units: Option<String>,
}

impl Tool for WeatherRequest {
    fn name(&self) -> &str {
        "get_weather"
    }

    fn description(&self) -> &str {
        "Get current weather for a location"
    }
}

Required Methods§

Source

fn name(&self) -> &str

Returns the name of the tool

This name is used to identify the tool in the LLM’s API.

Source

fn description(&self) -> &str

Returns the description of the tool

This description is sent to the LLM to help it understand when and how to use the tool. It should be clear and concise.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§