Skip to main content

Tool

Trait Tool 

Source
pub trait Tool: Send + Sync {
    // Required methods
    fn definition(&self) -> ToolDefinition;
    fn execute<'life0, 'async_trait>(
        &'life0 self,
        ctx: InvokeContext,
        input: Value,
    ) -> Pin<Box<dyn Future<Output = Result<ToolResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

The trait every tool implements.

Flue’s AgentTool is an object with a parameters schema and an async execute. The Rust equivalent is this trait, wrapped in Arc<dyn Tool>.

§Panic safety (precondition)

run_agent wraps execute in catch_unwind so a panicking tool is converted to a model-visible Error: result rather than aborting the run. For this to be sound, a tool’s interior mutability must be poison-free (use parking_lot / atomics / tokio::sync, not std::sync::Mutex/ RwLock, which poison on panic). A tool left mid-mutation by an unwinding panic must still be safely callable on subsequent turns. The built-in tools and TaskTool satisfy this.

Required Methods§

Source

fn definition(&self) -> ToolDefinition

The static definition (name/schema/description).

Source

fn execute<'life0, 'async_trait>( &'life0 self, ctx: InvokeContext, input: Value, ) -> Pin<Box<dyn Future<Output = Result<ToolResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute the tool with validated input.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§