#[tools]Expand description
Generates tools from the #[tool] methods of an impl block, for tools with state.
Each #[tool] method takes &self and follows the tool rules for its name,
description, parameters, context and return value. For a method check_stock the macro
generates check_stock_tool(self: &Arc<Self>) -> impl Tool, a tool holding the Arc that
calls the method, with the method’s visibility, and tools(self: &Arc<Self>) -> Vec<ToolSource> with every tool of the block, in order. #[tools(crate = "..")] sets the
strands path.
use std::sync::Arc;
use strands::{Tool, ToolError, tools};
struct Inventory {
stock: u32,
}
#[tools]
impl Inventory {
/// Look up stock for a product.
#[tool]
async fn check_stock(&self, sku: String) -> Result<u32, ToolError> {
let _ = sku;
Ok(self.stock)
}
}
let inventory = Arc::new(Inventory { stock: 3 });
assert_eq!(inventory.check_stock_tool().name(), "check_stock");
assert_eq!(inventory.tools().len(), 1);