Skip to main content

Crate serdes_ai_tools

Crate serdes_ai_tools 

Source
Expand description

§serdes-ai-tools

Tool system for serdes-ai agents.

This crate provides the infrastructure for defining, registering, and executing tools that agents can use during conversations.

§Core Concepts

  • Tool: Trait for callable tools with typed parameters
  • ToolRegistry: Manage and lookup registered tools
  • ToolDefinition: JSON Schema-based tool descriptions for LLMs
  • RunContext: Execution context with dependencies passed to tools
  • ToolReturn: Return values from tool execution

§Defining Tools

Tools can be defined by implementing the Tool trait:

use async_trait::async_trait;
use serdes_ai_tools::{
    SchemaBuilder, Tool, ToolDefinition,
    RunContext, ToolResult, ToolReturn,
};

struct WeatherTool;

#[async_trait]
impl Tool for WeatherTool {
    fn definition(&self) -> ToolDefinition {
        ToolDefinition::new("get_weather", "Get current weather for a location")
            .with_parameters(
                SchemaBuilder::new()
                    .string("location", "City name", true)
                    .build()
                    .unwrap()
            )
    }

    async fn call(
        &self,
        _ctx: &RunContext,
        args: serde_json::Value,
    ) -> ToolResult {
        let location = args["location"].as_str().unwrap_or("Unknown");
        Ok(ToolReturn::text(format!("Weather in {}: 72°F, sunny", location)))
    }
}

§Using the Registry

use serdes_ai_tools::{ToolRegistry, Tool, RunContext};


let mut registry = ToolRegistry::new();
registry.register(WeatherTool);

// Get all definitions for the model
let definitions = registry.definitions();

// Check if a tool exists
assert!(registry.contains("weather"));

§Builtin Tools

The crate provides builtin tools for common operations:

§Common Tools (Third-Party Integrations)

With the common-tools feature, additional third-party tool integrations are available:

serdes-ai-tools = { version = "0.1", features = ["common-tools"] }
  • common::DuckDuckGoTool: Web search using DuckDuckGo (no API key required)
  • common::TavilyTool: AI-optimized search using Tavily’s API

Re-exports§

pub use context::RunContext;
pub use deferred::DeferredToolCall;
pub use deferred::DeferredToolDecision;
pub use deferred::DeferredToolDecisions;
pub use deferred::DeferredToolRequests;
pub use deferred::DeferredToolResult;
pub use deferred::DeferredToolResults;
pub use deferred::ToolApproved;
pub use deferred::ToolApprover;
pub use deferred::ToolDenied;
pub use definition::ObjectJsonSchema;
pub use definition::ToolDefinition;
pub use errors::ToolError;
pub use errors::ToolErrorInfo;
pub use registry::ToolProvider;
pub use registry::ToolRegistry;
pub use return_types::IntoToolReturn;
pub use return_types::SerializableToolResult;
pub use return_types::ToolResult;
pub use return_types::ToolReturn;
pub use schema::PropertySchema;
pub use schema::SchemaBuilder;
pub use tool::BoxedTool;
pub use tool::FunctionTool;
pub use tool::SyncFunctionTool;
pub use tool::Tool;

Modules§

builtin
Builtin tools for common operations.
context
Run context for tool execution.
deferred
Deferred tool execution for approval flows.
definition
Tool definition types for describing tools to LLMs.
errors
Tool-specific error types.
registry
Tool registry for managing multiple tools.
return_types
Tool return types.
schema
JSON schema generation utilities.
tool
Core tool trait and implementations.