#![cfg(feature = "macros")]
use agentai::tool::{Tool, ToolBox, ToolError, ToolResult, toolbox};
struct StrictToolBox;
#[toolbox]
impl StrictToolBox {
#[tool(strict)]
fn strict_tool(
&self,
city: String,
unit: Option<String>,
) -> ToolResult {
Ok(format!("{city} {unit:?}"))
}
#[tool(strict = false)]
fn not_strict(&self) -> ToolResult {
Ok("ok".to_string())
}
#[tool(name = "renamed", strict = true)]
fn renamed_strict(&self) -> ToolResult {
Ok("ok".to_string())
}
#[tool]
fn plain(&self) -> ToolResult {
Ok("ok".to_string())
}
}
fn find<'a>(tools: &'a [Tool], name: &str) -> &'a Tool {
tools
.iter()
.find(|t| t.name.as_str() == name)
.unwrap_or_else(|| panic!("tool '{name}' not found"))
}
#[test]
fn strict_option_sets_the_strict_flag() -> Result<(), ToolError> {
let tools = StrictToolBox.tools_definitions()?;
assert_eq!(find(&tools, "strict_tool").strict, Some(true));
assert!(find(&tools, "strict_tool").schema.is_some());
assert_eq!(find(&tools, "not_strict").strict, Some(false));
assert_eq!(find(&tools, "renamed").strict, Some(true));
assert_eq!(find(&tools, "plain").strict, None);
Ok(())
}