Skip to main content

Tool

Trait Tool 

Source
pub trait Tool<Ctx>: Send + Sync {
    type Name: ToolName;

    // Required methods
    fn name(&self) -> Self::Name;
    fn display_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>> + Send;

    // Provided method
    fn tier(&self) -> ToolTier { ... }
}
Expand description

Definition of a tool that can be called by the agent.

Tools have a strongly-typed Name associated type that determines how the tool name is serialized for LLM communication.

§Native Async Support

This trait uses Rust’s native async functions in traits (stabilized in Rust 1.75). You do NOT need the async_trait crate to implement this trait.

Required Associated Types§

Source

type Name: ToolName

The type of name for this tool.

Required Methods§

Source

fn name(&self) -> Self::Name

Returns the tool’s strongly-typed name.

Source

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

Human-readable display name for UI (e.g., “Read File” vs “read”).

Defaults to empty string. Override for better UX.

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>> + Send

Execute the tool with the given input.

§Errors

Returns an error if tool execution fails.

Provided Methods§

Source

fn tier(&self) -> ToolTier

Permission tier for this tool.

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§

Source§

impl<Ctx> Tool<Ctx> for LinkFetchTool
where Ctx: Send + Sync + 'static,

Source§

impl<Ctx, P> Tool<Ctx> for WebSearchTool<P>
where Ctx: Send + Sync + 'static, P: SearchProvider + 'static,

Source§

impl<Ctx: Send + Sync + 'static> Tool<Ctx> for TodoReadTool

Source§

impl<Ctx: Send + Sync + 'static> Tool<Ctx> for TodoWriteTool

Source§

impl<Ctx: Send + Sync + 'static> Tool<Ctx> for AskUserQuestionTool

Source§

impl<E: Environment + 'static> Tool<()> for BashTool<E>

Source§

impl<E: Environment + 'static> Tool<()> for EditTool<E>

Source§

impl<E: Environment + 'static> Tool<()> for GlobTool<E>

Source§

impl<E: Environment + 'static> Tool<()> for GrepTool<E>

Source§

impl<E: Environment + 'static> Tool<()> for ReadTool<E>

Source§

impl<E: Environment + 'static> Tool<()> for WriteTool<E>

Source§

impl<P, H, M, S> Tool<()> for SubagentTool<P, H, M, S>
where P: LlmProvider + Clone + 'static, H: AgentHooks + Clone + 'static, M: MessageStore + 'static, S: StateStore + 'static,

Source§

impl<T: McpTransport + 'static> Tool<()> for McpToolBridge<T>