Skip to main content

Tool

Trait Tool 

Source
pub trait Tool: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn description(&self) -> &str;
    fn parameters(&self) -> Value;
    fn execute<'life0, 'life1, 'async_trait>(
        &'life0 self,
        args: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Layer2Result<ToolResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided method
    fn validate_args(&self, _args: &Value) -> Layer2Result<bool> { ... }
}
Expand description

工具接口

所有工具必须实现此接口。

Required Methods§

Source

fn name(&self) -> &str

获取工具名称

Source

fn description(&self) -> &str

获取工具描述

Source

fn parameters(&self) -> Value

获取参数 schema

Source

fn execute<'life0, 'life1, 'async_trait>( &'life0 self, args: &'life1 str, ) -> Pin<Box<dyn Future<Output = Layer2Result<ToolResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

执行工具

Provided Methods§

Source

fn validate_args(&self, _args: &Value) -> Layer2Result<bool>

验证参数

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§