Skip to main content

SimpleTool

Trait SimpleTool 

Source
pub trait SimpleTool<Ctx>: Send + Sync {
    // Required methods
    fn name(&self) -> &'static str;
    fn description(&self) -> &'static str;
    fn input_schema(&self) -> Value;
    fn execute(
        &self,
        ctx: &ToolContext<Ctx>,
        input: Value,
    ) -> impl Future<Output = Result<ToolResult, Error>> + Send;

    // Provided methods
    fn display_name(&self) -> &'static str { ... }
    fn tier(&self) -> ToolTier { ... }
}
Expand description

An ergonomic Tool whose name is a plain string.

Most custom tools don’t need a strongly-typed ToolName enum — they have a single, fixed name. SimpleTool lets you write a tool by returning a &str from name instead of defining a ToolName type and an associated Tool::Name.

Any SimpleTool is automatically a Tool (via a blanket impl) with Name = DynamicToolName, so it can be registered and used exactly like a hand-written Tool.

§Example

use agent_sdk_tools::tools::{SimpleTool, ToolContext};
use agent_sdk_foundation::types::ToolResult;
use serde_json::{json, Value};
use std::future::Future;

struct WeatherTool;

impl SimpleTool<()> for WeatherTool {
    fn name(&self) -> &'static str { "get_weather" }
    fn description(&self) -> &'static str { "Get current weather for a city" }
    fn input_schema(&self) -> Value {
        json!({ "type": "object", "properties": { "city": { "type": "string" } } })
    }

    fn execute(
        &self,
        _ctx: &ToolContext<()>,
        input: Value,
    ) -> impl Future<Output = anyhow::Result<ToolResult>> + Send {
        async move {
            let city = input["city"].as_str().unwrap_or("Unknown");
            Ok(ToolResult::success(format!("Weather in {city}: Sunny")))
        }
    }
}

Required Methods§

Source

fn name(&self) -> &'static str

The tool’s name as sent to (and parsed from) the LLM.

Returns &'static str because a simple tool has one fixed name; reach for the full Tool trait with a DynamicToolName when the name is computed at runtime.

Source

fn description(&self) -> &'static str

Human-readable description of what the tool does.

Source

fn input_schema(&self) -> Value

JSON schema for the tool’s input parameters.

Source

fn execute( &self, ctx: &ToolContext<Ctx>, input: Value, ) -> impl Future<Output = Result<ToolResult, Error>> + Send

Execute the tool with the given input.

§Errors

Returns an error if tool execution fails.

Provided Methods§

Source

fn display_name(&self) -> &'static str

Human-readable display name for UI.

Defaults to an empty string; override for a friendlier label.

Source

fn tier(&self) -> ToolTier

Permission tier for this tool. Defaults to ToolTier::Observe.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§