pub trait Tool {
// Required methods
fn info(&self) -> &ToolInfo;
fn call<'life0, 'async_trait>(
&'life0 self,
ctx: AgentContext,
args: AgentValue,
) -> Pin<Box<dyn Future<Output = Result<AgentValue, AgentError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
Trait for implementing callable tools.
Tools are functions that can be invoked by LLMs during conversations. Implement this trait to create custom tools that can be registered with the global tool registry.
§Example
ⓘ
use modular_agent_core::{Tool, ToolInfo, AgentContext, AgentValue, AgentError, async_trait};
struct MyTool {
info: ToolInfo,
}
#[async_trait]
impl Tool for MyTool {
fn info(&self) -> &ToolInfo {
&self.info
}
async fn call(&self, ctx: AgentContext, args: AgentValue) -> Result<AgentValue, AgentError> {
// Tool implementation
Ok(AgentValue::string("result"))
}
}Required Methods§
Sourcefn call<'life0, 'async_trait>(
&'life0 self,
ctx: AgentContext,
args: AgentValue,
) -> Pin<Box<dyn Future<Output = Result<AgentValue, AgentError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn call<'life0, 'async_trait>(
&'life0 self,
ctx: AgentContext,
args: AgentValue,
) -> Pin<Box<dyn Future<Output = Result<AgentValue, AgentError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".