pub struct StructuredTool { /* private fields */ }Expand description
Tool that can operate on any number of inputs.
Unlike Tool, which accepts a single string input, StructuredTool
accepts a dictionary of typed arguments.
Implementations§
Source§impl StructuredTool
impl StructuredTool
Sourcepub fn new(
name: impl Into<String>,
description: impl Into<String>,
args_schema: ArgsSchema,
) -> Self
pub fn new( name: impl Into<String>, description: impl Into<String>, args_schema: ArgsSchema, ) -> Self
Create a new StructuredTool.
Sourcepub fn with_func(self, func: StructuredToolFunc) -> Self
pub fn with_func(self, func: StructuredToolFunc) -> Self
Set the sync function.
Sourcepub fn with_coroutine(self, coroutine: AsyncStructuredToolFunc) -> Self
pub fn with_coroutine(self, coroutine: AsyncStructuredToolFunc) -> Self
Set the async function.
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 with_handle_tool_error(self, handler: HandleToolError) -> Self
pub fn with_handle_tool_error(self, handler: HandleToolError) -> Self
Set handle_tool_error.
Sourcepub fn with_handle_validation_error(
self,
handler: HandleValidationError,
) -> Self
pub fn with_handle_validation_error( self, handler: HandleValidationError, ) -> Self
Set handle_validation_error.
Sourcepub fn from_function<F>(
func: F,
name: impl Into<String>,
description: impl Into<String>,
args_schema: ArgsSchema,
) -> Self
pub fn from_function<F>( func: F, name: impl Into<String>, description: impl Into<String>, args_schema: ArgsSchema, ) -> Self
Create a tool from a function.
This is the main way to create a StructuredTool.
Sourcepub fn from_function_with_async<F, AF, Fut>(
func: F,
coroutine: AF,
name: impl Into<String>,
description: impl Into<String>,
args_schema: ArgsSchema,
) -> Self
pub fn from_function_with_async<F, AF, Fut>( func: F, coroutine: AF, name: impl Into<String>, description: impl Into<String>, args_schema: ArgsSchema, ) -> Self
Create a tool from a sync and async function pair.
Sourcepub fn from_async_function<AF, Fut>(
coroutine: AF,
name: impl Into<String>,
description: impl Into<String>,
args_schema: ArgsSchema,
) -> Self
pub fn from_async_function<AF, Fut>( coroutine: AF, name: impl Into<String>, description: impl Into<String>, args_schema: ArgsSchema, ) -> Self
Create a tool from an async function only.
Trait Implementations§
Source§impl BaseTool for StructuredTool
impl BaseTool for StructuredTool
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 StructuredTool
impl !RefUnwindSafe for StructuredTool
impl Send for StructuredTool
impl Sync for StructuredTool
impl Unpin for StructuredTool
impl !UnwindSafe for StructuredTool
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