pub trait Tool {
type Input: DeserializeOwned + Send + Sync;
type Output: Serialize;
type Error: Debug + Error + ToolError + From<Error>;
// Required methods
fn invoke_typed<'life0, 'life1, 'async_trait>(
&'life0 self,
input: &'life1 Self::Input,
) -> Pin<Box<dyn Future<Output = Result<Self::Output, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn description(&self) -> ToolDescription;
// Provided methods
fn invoke<'life0, 'async_trait>(
&'life0 self,
input: Value,
) -> Pin<Box<dyn Future<Output = Result<Value, Self::Error>> + Send + 'async_trait>>
where Self: Sync + 'async_trait,
'life0: 'async_trait { ... }
fn matches(&self, name: &str) -> bool { ... }
}
Expand description
The Tool
trait defines an interface for tools that can be added to a ToolCollection
.
A Tool
is a function that takes a YAML-formatted input and returns a YAML-formatted output.
It has a description that contains metadata about the tool, such as its name and usage.
Required Associated Types§
type Input: DeserializeOwned + Send + Sync
type Output: Serialize
type Error: Debug + Error + ToolError + From<Error>
Required Methods§
fn invoke_typed<'life0, 'life1, 'async_trait>(
&'life0 self,
input: &'life1 Self::Input,
) -> Pin<Box<dyn Future<Output = Result<Self::Output, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Sourcefn description(&self) -> ToolDescription
fn description(&self) -> ToolDescription
Returns the ToolDescription
containing metadata about the tool.
Provided Methods§
Sourcefn invoke<'life0, 'async_trait>(
&'life0 self,
input: Value,
) -> Pin<Box<dyn Future<Output = Result<Value, Self::Error>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
fn invoke<'life0, 'async_trait>(
&'life0 self,
input: Value,
) -> Pin<Box<dyn Future<Output = Result<Value, Self::Error>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
Invokes the tool with the given YAML-formatted input.
§Errors
Returns an ToolUseError
if the input is not in the expected format or if the tool
fails to produce a valid output.