Skip to main content

ToolRegistry

Trait ToolRegistry 

Source
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§

Source

fn register(&mut self, tool: Arc<dyn Tool>) -> AgentResult<()>

注册工具

Source

fn get(&self, name: &str) -> Option<Arc<dyn Tool>>

获取工具

Source

fn unregister(&mut self, name: &str) -> AgentResult<bool>

移除工具

Source

fn list(&self) -> Vec<ToolDescriptor>

列出所有工具

Source

fn list_names(&self) -> Vec<String>

列出所有工具名称

Source

fn contains(&self, name: &str) -> bool

检查工具是否存在

Source

fn count(&self) -> usize

获取工具数量

Provided Methods§

Source

fn register_all(&mut self, tools: Vec<Arc<dyn Tool>>) -> AgentResult<()>

批量注册工具

Source

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,

执行工具

Source

fn to_llm_tools(&self) -> Vec<LLMTool>

转换为 LLM Tools

Implementors§