StructuredTool

Struct StructuredTool 

Source
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

Source

pub fn new( name: impl Into<String>, description: impl Into<String>, args_schema: ArgsSchema, ) -> Self

Create a new StructuredTool.

Source

pub fn with_func(self, func: StructuredToolFunc) -> Self

Set the sync function.

Source

pub fn with_coroutine(self, coroutine: AsyncStructuredToolFunc) -> Self

Set the async function.

Source

pub fn with_return_direct(self, return_direct: bool) -> Self

Set whether to return directly.

Source

pub fn with_response_format(self, format: ResponseFormat) -> Self

Set the response format.

Source

pub fn with_tags(self, tags: Vec<String>) -> Self

Set tags.

Source

pub fn with_metadata(self, metadata: HashMap<String, Value>) -> Self

Set metadata.

Source

pub fn with_extras(self, extras: HashMap<String, Value>) -> Self

Set extras.

Source

pub fn with_handle_tool_error(self, handler: HandleToolError) -> Self

Set handle_tool_error.

Source

pub fn with_handle_validation_error( self, handler: HandleValidationError, ) -> Self

Set handle_validation_error.

Source

pub fn from_function<F>( func: F, name: impl Into<String>, description: impl Into<String>, args_schema: ArgsSchema, ) -> Self
where F: Fn(HashMap<String, Value>) -> Result<Value> + Send + Sync + 'static,

Create a tool from a function.

This is the main way to create a StructuredTool.

Source

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
where F: Fn(HashMap<String, Value>) -> Result<Value> + Send + Sync + 'static, AF: Fn(HashMap<String, Value>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Value>> + Send + 'static,

Create a tool from a sync and async function pair.

Source

pub fn from_async_function<AF, Fut>( coroutine: AF, name: impl Into<String>, description: impl Into<String>, args_schema: ArgsSchema, ) -> Self
where AF: Fn(HashMap<String, Value>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Value>> + Send + 'static,

Create a tool from an async function only.

Trait Implementations§

Source§

impl BaseTool for StructuredTool

Source§

fn name(&self) -> &str

Get the unique name of the tool.
Source§

fn description(&self) -> &str

Get the description of what the tool does.
Source§

fn args_schema(&self) -> Option<&ArgsSchema>

Get the args schema for the tool.
Source§

fn return_direct(&self) -> bool

Whether to return the tool’s output directly.
Source§

fn verbose(&self) -> bool

Whether to log the tool’s progress.
Source§

fn tags(&self) -> Option<&[String]>

Get tags associated with the tool.
Source§

fn metadata(&self) -> Option<&HashMap<String, Value>>

Get metadata associated with the tool.
Source§

fn handle_tool_error(&self) -> &HandleToolError

Get how to handle tool errors.
Source§

fn handle_validation_error(&self) -> &HandleValidationError

Get how to handle validation errors.
Source§

fn response_format(&self) -> ResponseFormat

Get the response format for the tool.
Source§

fn extras(&self) -> Option<&HashMap<String, Value>>

Get optional provider-specific extra fields.
Source§

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,

Run the tool asynchronously.
Source§

fn is_single_input(&self) -> bool

Check if the tool accepts only a single input argument.
Source§

fn args(&self) -> HashMap<String, Value>

Get the tool’s input arguments schema.
Source§

fn tool_call_schema(&self) -> ArgsSchema

Get the schema for tool calls, excluding injected arguments.
Source§

fn definition(&self) -> ToolDefinition

Get the tool definition for LLM function calling.
Source§

fn parameters_schema(&self) -> Value

Get the JSON schema for the tool’s parameters.
Source§

fn invoke<'life0, 'async_trait>( &'life0 self, tool_call: ToolCall, ) -> Pin<Box<dyn Future<Output = BaseMessage> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Invoke the tool with a ToolCall.
Source§

fn invoke_args<'life0, 'async_trait>( &'life0 self, args: Value, ) -> Pin<Box<dyn Future<Output = Value> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Invoke the tool directly with arguments.
Source§

impl Debug for StructuredTool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more