pub trait Tool: Send + Sync {
type Input: DeserializeOwned + JsonSchema + Send + Sync + 'static;
type Output: Serialize + Send + Sync;
// Required method
fn invoke<'life0, 'async_trait>(
&'life0 self,
input: Self::Input,
) -> Pin<Box<dyn Future<Output = Result<Self::Output, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
// Provided method
fn args_schema(&self) -> Option<Value> { ... }
}Expand description
Generic tool trait (type-safe version).
For scenarios requiring type-safe input/output. Tools implementing this trait can be automatically wrapped as BaseTool.
Required Associated Types§
Sourcetype Input: DeserializeOwned + JsonSchema + Send + Sync + 'static
type Input: DeserializeOwned + JsonSchema + Send + Sync + 'static
Input type (must support deserialization and JSON Schema).
Required Methods§
Provided Methods§
Sourcefn args_schema(&self) -> Option<Value>
fn args_schema(&self) -> Option<Value>
Returns the input JSON Schema.
J9:序列化失败不再 .ok() 占位空 None——Self::Input 必须 derive
JsonSchema(否则 schema_for! 本身是编译错误),schema 自描述必可序列化,
真失败是内部错误,直接 panic 报出。
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
Source§impl Tool for Calculator
Implement Tool trait (type-safe version)
impl Tool for Calculator
Implement Tool trait (type-safe version)