pub struct Tool { /* private fields */ }Expand description
Tool that takes in a function or coroutine directly.
This is the simplest form of tool that takes a single string input and returns a string output.
Implementations§
Source§impl Tool
impl Tool
Sourcepub fn new(
name: impl Into<String>,
func: Option<ToolFunc>,
description: impl Into<String>,
) -> Self
pub fn new( name: impl Into<String>, func: Option<ToolFunc>, description: impl Into<String>, ) -> Self
Create a new Tool.
Sourcepub fn with_coroutine(self, coroutine: AsyncToolFunc) -> Self
pub fn with_coroutine(self, coroutine: AsyncToolFunc) -> Self
Set the coroutine (async function).
Sourcepub fn with_args_schema(self, schema: ArgsSchema) -> Self
pub fn with_args_schema(self, schema: ArgsSchema) -> Self
Set the args schema.
Sourcepub fn with_return_direct(self, return_direct: bool) -> Self
pub fn with_return_direct(self, return_direct: bool) -> Self
Set whether to return directly.
Sourcepub fn with_response_format(self, format: ResponseFormat) -> Self
pub fn with_response_format(self, format: ResponseFormat) -> Self
Set the response format.
Set tags.
Sourcepub fn with_metadata(self, metadata: HashMap<String, Value>) -> Self
pub fn with_metadata(self, metadata: HashMap<String, Value>) -> Self
Set metadata.
Sourcepub fn with_extras(self, extras: HashMap<String, Value>) -> Self
pub fn with_extras(self, extras: HashMap<String, Value>) -> Self
Set extras.
Sourcepub fn from_function<F>(
func: F,
name: impl Into<String>,
description: impl Into<String>,
) -> Self
pub fn from_function<F>( func: F, name: impl Into<String>, description: impl Into<String>, ) -> Self
Create a Tool from a function.
Trait Implementations§
Source§impl BaseTool for Tool
impl BaseTool for Tool
Source§fn description(&self) -> &str
fn description(&self) -> &str
Get the description of what the tool does.
Source§fn args_schema(&self) -> Option<&ArgsSchema>
fn args_schema(&self) -> Option<&ArgsSchema>
Get the args schema for the tool.
Source§fn return_direct(&self) -> bool
fn return_direct(&self) -> bool
Whether to return the tool’s output directly.
Get tags associated with the tool.
Source§fn handle_tool_error(&self) -> &HandleToolError
fn handle_tool_error(&self) -> &HandleToolError
Get how to handle tool errors.
Source§fn handle_validation_error(&self) -> &HandleValidationError
fn handle_validation_error(&self) -> &HandleValidationError
Get how to handle validation errors.
Source§fn response_format(&self) -> ResponseFormat
fn response_format(&self) -> ResponseFormat
Get the response format for the tool.
Source§fn extras(&self) -> Option<&HashMap<String, Value>>
fn extras(&self) -> Option<&HashMap<String, Value>>
Get optional provider-specific extra fields.
Source§fn run(
&self,
input: ToolInput,
_config: Option<RunnableConfig>,
) -> Result<ToolOutput>
fn run( &self, input: ToolInput, _config: Option<RunnableConfig>, ) -> Result<ToolOutput>
Run the tool synchronously.
Source§fn arun<'life0, 'async_trait>(
&'life0 self,
input: ToolInput,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<ToolOutput>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn arun<'life0, 'async_trait>(
&'life0 self,
input: ToolInput,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<ToolOutput>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Run the tool asynchronously.
Source§fn is_single_input(&self) -> bool
fn is_single_input(&self) -> bool
Check if the tool accepts only a single input argument.
Source§fn tool_call_schema(&self) -> ArgsSchema
fn tool_call_schema(&self) -> ArgsSchema
Get the schema for tool calls, excluding injected arguments.
Source§fn definition(&self) -> ToolDefinition
fn definition(&self) -> ToolDefinition
Get the tool definition for LLM function calling.
Source§fn parameters_schema(&self) -> Value
fn parameters_schema(&self) -> Value
Get the JSON schema for the tool’s parameters.
Auto Trait Implementations§
impl Freeze for Tool
impl !RefUnwindSafe for Tool
impl Send for Tool
impl Sync for Tool
impl Unpin for Tool
impl !UnwindSafe for Tool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more