Skip to main content

BaseTool

Trait BaseTool 

Source
pub trait BaseTool: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn invoke(
        &self,
        args: &JsonValue,
        config: &RunnableConfig,
    ) -> Result<JsonValue, ToolError>;

    // Provided methods
    fn description(&self) -> &str { ... }
    fn parameters(&self) -> Option<&JsonValue> { ... }
    fn ainvoke<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        args: &'life1 JsonValue,
        config: &'life2 RunnableConfig,
    ) -> Pin<Box<dyn Future<Output = Result<JsonValue, ToolError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn to_tool_def(&self) -> ToolDef { ... }
}
Expand description

A tool that can be invoked by an agent.

Mirrors langchain-core’s BaseTool.

Required Methods§

Source

fn name(&self) -> &str

The name of the tool.

Source

fn invoke( &self, args: &JsonValue, config: &RunnableConfig, ) -> Result<JsonValue, ToolError>

Invoke the tool synchronously with the given arguments.

Provided Methods§

Source

fn description(&self) -> &str

A description of what the tool does.

Source

fn parameters(&self) -> Option<&JsonValue>

The JSON schema for the tool’s parameters.

Source

fn ainvoke<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, args: &'life1 JsonValue, config: &'life2 RunnableConfig, ) -> Pin<Box<dyn Future<Output = Result<JsonValue, ToolError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Invoke the tool asynchronously. Default delegates to sync invoke via block_in_place.

Sets up thread-local config/runtime context so that get_config() and get_runtime() work inside sync tool code (needed by interrupt()).

Source

fn to_tool_def(&self) -> ToolDef

Get the tool’s schema as a ToolCall-compatible descriptor.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§