Expand description
#[tool] 属性宏:把普通 async fn 声明为 Agent 工具(设计文档 4.5 工具系统宏)
用法(在使用方 crate 内):
ⓘ
use wordval_agent_macros::tool;
/// 计算两个整数之和(doc 注释作为描述)
#[tool(read_only)]
async fn add(a: i64, b: i64) -> Result<String, String> {
Ok(format!("{}", a + b))
}支持的属性:
description = "...":覆盖 doc 注释作为工具描述name = "...":自定义工具名(默认函数名)read_only:标记只读工具(权限引擎 Explore/AcceptEdits 模式判定)
展开内容:
- 生成
struct __{Pascal}Tool并实现::wordval_agent::tools::Tool(name/description/parameters_schema/execute/is_read_only) - 生成 linkme 分布式切片静态项,编译期注册到
::wordval_agent::tools::registry::TOOL_FACTORIES - 参数从
serde_json::Value反序列化(要求参数类型实现 Deserialize); 非 Option 参数进入 schemarequired,缺失时报错 - 返回值约束:
ToolResult/Result<T, E>(T: Into<String>,E: ToString)/String
支持参数类型:String/&str、整数、浮点、bool、Vec<T>、serde_json::Value/对象。