Skip to main content

Tool

Trait Tool 

Source
pub trait Tool:
    Send
    + Sync
    + 'static {
    type Input: Send + 'static;
    type Output: Send + 'static;

    const NAME: &'static str;
    const DESCRIPTION: &'static str;

    // Required method
    fn call(
        &self,
        input: Self::Input,
        ctx: &ToolContext,
    ) -> BoxFuture<'static, Result<Self::Output, ToolError>>;
}
Expand description

Native-first Tool trait with NO serde bounds.

This trait defines a tool that can be called with native Rust types. Serialization is handled separately by ToolCodec at protocol boundaries.

§Example

use agentic_tools_core::{Tool, ToolContext, ToolError};
use futures::future::BoxFuture;

struct GreetTool;

impl Tool for GreetTool {
    type Input = String;
    type Output = String;
    const NAME: &'static str = "greet";
    const DESCRIPTION: &'static str = "Greet someone by name";

    fn call(&self, input: Self::Input, _ctx: &ToolContext)
        -> BoxFuture<'static, Result<Self::Output, ToolError>>
    {
        Box::pin(async move {
            Ok(format!("Hello, {}!", input))
        })
    }
}

Required Associated Constants§

Source

const NAME: &'static str

Unique name identifying the tool.

Source

const DESCRIPTION: &'static str

Human-readable description of what the tool does.

Required Associated Types§

Source

type Input: Send + 'static

Input type for the tool (no serde bounds required).

Source

type Output: Send + 'static

Output type for the tool (no serde bounds required).

Required Methods§

Source

fn call( &self, input: Self::Input, ctx: &ToolContext, ) -> BoxFuture<'static, Result<Self::Output, ToolError>>

Execute the tool with the given input and context.

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§