Derive Macro Tool

Source
#[derive(Tool)]
{
    // Attributes available to this derive:
    #[tool]
}
Expand description

Derive Tool on a struct.

Useful if your structs have internal state and you want to use it in your tool.

§Example

#[derive(Clone, Tool)]
#[tool(description = "Searches code", param(name = "code_query", description = "The code query"))]
pub struct SearchCode {
  search_command: String
}

impl SearchCode {
  pub async fn search_code(&self, context: &dyn AgentContext, code_query: &str) -> Result<ToolOutput, ToolError> {
    context.exec_cmd(&self.search_command.into()).await.map(Into::into)
  }
}