pub trait ToolRegistry: Send + Sync {
// Required methods
fn register(&mut self, tool: Arc<dyn Tool>) -> AgentResult<()>;
fn get(&self, name: &str) -> Option<Arc<dyn Tool>>;
fn unregister(&mut self, name: &str) -> AgentResult<bool>;
fn list(&self) -> Vec<ToolDescriptor>;
fn list_names(&self) -> Vec<String>;
fn contains(&self, name: &str) -> bool;
fn count(&self) -> usize;
// Provided methods
fn register_all(&mut self, tools: Vec<Arc<dyn Tool>>) -> AgentResult<()> { ... }
fn execute<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
name: &'life1 str,
input: ToolInput,
ctx: &'life2 AgentContext,
) -> Pin<Box<dyn Future<Output = AgentResult<ToolResult>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn to_llm_tools(&self) -> Vec<LLMTool> { ... }
}Expand description
定义工具注册的接口,具体实现在 foundation 层。
Required Methods§
Sourcefn unregister(&mut self, name: &str) -> AgentResult<bool>
fn unregister(&mut self, name: &str) -> AgentResult<bool>
移除工具
Sourcefn list(&self) -> Vec<ToolDescriptor>
fn list(&self) -> Vec<ToolDescriptor>
列出所有工具
Sourcefn list_names(&self) -> Vec<String>
fn list_names(&self) -> Vec<String>
列出所有工具名称
Provided Methods§
Sourcefn register_all(&mut self, tools: Vec<Arc<dyn Tool>>) -> AgentResult<()>
fn register_all(&mut self, tools: Vec<Arc<dyn Tool>>) -> AgentResult<()>
批量注册工具
Sourcefn execute<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
name: &'life1 str,
input: ToolInput,
ctx: &'life2 AgentContext,
) -> Pin<Box<dyn Future<Output = AgentResult<ToolResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn execute<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
name: &'life1 str,
input: ToolInput,
ctx: &'life2 AgentContext,
) -> Pin<Box<dyn Future<Output = AgentResult<ToolResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
执行工具
Sourcefn to_llm_tools(&self) -> Vec<LLMTool>
fn to_llm_tools(&self) -> Vec<LLMTool>
转换为 LLM Tools