pub trait ProxyToolExecutor: Send + Sync {
// Required methods
fn exec<'life0, 'life1, 'async_trait>(
&'life0 self,
tool_name: &'life1 str,
input: Value,
) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn tool_definitions() -> Vec<ProxyToolDef>
where Self: Sized;
}Expand description
代理工具执行器 trait
必须实现两个方法:
exec()- 执行逻辑tool_definitions()- 工具定义列表
§Example
ⓘ
use async_trait::async_trait;
use serde_json::json;
use std::sync::Arc;
use matrixcode_core::tools::toolproxy::{ProxyToolExecutor, ProxyToolDef};
use anyhow::Result;
use serde_json::Value;
struct ImageSearchExecutor;
#[async_trait]
impl ProxyToolExecutor for ImageSearchExecutor {
async fn exec(&self, tool_name: &str, input: Value) -> Result<String> {
// 执行逻辑...
Ok("result".to_string())
}
fn tool_definitions() -> Vec<ProxyToolDef> {
vec![
ProxyToolDef::new("image_search", "搜索图片", json!({...}))
.with_priority(true)
]
}
}
// 使用
let executor = Arc::new(ImageSearchExecutor);
let tool_defs = ImageSearchExecutor::tool_definitions();
// builder.proxy_executor(executor, tool_defs)Required Methods§
Sourcefn exec<'life0, 'life1, 'async_trait>(
&'life0 self,
tool_name: &'life1 str,
input: Value,
) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn exec<'life0, 'life1, 'async_trait>(
&'life0 self,
tool_name: &'life1 str,
input: Value,
) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
执行代理工具(必需)
Sourcefn tool_definitions() -> Vec<ProxyToolDef>where
Self: Sized,
fn tool_definitions() -> Vec<ProxyToolDef>where
Self: Sized,
返回工具定义列表(必需 - LLM 看到的)
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".