pub trait Tool: Send + Sync {
// Required methods
fn name(&self) -> String;
fn description(&self) -> String;
fn run<'life0, 'async_trait>(
&'life0 self,
input: Value,
) -> Pin<Box<dyn Future<Output = Result<String, Box<dyn Error>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided methods
fn parameters(&self) -> Value { ... }
fn call<'life0, 'life1, 'async_trait>(
&'life0 self,
input: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<String, Box<dyn Error>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn parse_input<'life0, 'life1, 'async_trait>(
&'life0 self,
input: &'life1 str,
) -> Pin<Box<dyn Future<Output = Value> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}
Required Methods§
Sourcefn description(&self) -> String
fn description(&self) -> String
Provides a description of what the tool does and when to use it.
Sourcefn run<'life0, 'async_trait>(
&'life0 self,
input: Value,
) -> Pin<Box<dyn Future<Output = Result<String, Box<dyn Error>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn run<'life0, 'async_trait>(
&'life0 self,
input: Value,
) -> Pin<Box<dyn Future<Output = Result<String, Box<dyn Error>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Executes the core functionality of the tool.
Example implementation:
ⓘ
async fn run(&self, input: Value) -> Result<String, Box<dyn Error>> {
let input_str = input.as_str().ok_or("Input should be a string")?;
self.simple_search(input_str).await
}
Provided Methods§
Sourcefn parameters(&self) -> Value
fn parameters(&self) -> Value
This are the parametters for OpenAi-like function call. You should return a jsnon like this one
{
"type": "object",
"properties": {
"command": {
"type": "string",
"description": "The raw command you want executed"
}
},
"required": ["command"]
}
If there s no implementation the defaul will be the self.description()
Sourcefn call<'life0, 'life1, 'async_trait>(
&'life0 self,
input: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<String, Box<dyn Error>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn call<'life0, 'life1, 'async_trait>(
&'life0 self,
input: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<String, Box<dyn Error>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Processes an input string and executes the tool’s functionality, returning a Result
.
This function utilizes parse_input
to parse the input and then calls run
.
Its used by the Agent
Sourcefn parse_input<'life0, 'life1, 'async_trait>(
&'life0 self,
input: &'life1 str,
) -> Pin<Box<dyn Future<Output = Value> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn parse_input<'life0, 'life1, 'async_trait>(
&'life0 self,
input: &'life1 str,
) -> Pin<Box<dyn Future<Output = Value> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Parses the input string, which could be a JSON value or a raw string, depending on the LLM model.
Implement this function to extract the parameters needed for your tool. If a simple string is sufficient, the default implementation can be used.