pub struct ToolRegistry<Ctx> { /* private fields */ }Expand description
Implementations§
Source§impl<Ctx: Send + Sync + 'static> ToolRegistry<Ctx>
impl<Ctx: Send + Sync + 'static> ToolRegistry<Ctx>
pub fn new() -> Self
Sourcepub fn register<T>(&mut self, tool: T) -> &mut Selfwhere
T: Tool<Ctx> + 'static,
pub fn register<T>(&mut self, tool: T) -> &mut Selfwhere
T: Tool<Ctx> + 'static,
Register a synchronous tool in the registry.
The tool’s name is converted to a string via serde serialization and used as the lookup key.
Sourcepub fn register_async<T>(&mut self, tool: T) -> &mut Selfwhere
T: AsyncTool<Ctx> + 'static,
pub fn register_async<T>(&mut self, tool: T) -> &mut Selfwhere
T: AsyncTool<Ctx> + 'static,
Register an async tool in the registry.
Async tools have two phases: execute (lightweight, starts operation)
and check_status (streams progress until completion).
Sourcepub fn register_listen<T>(&mut self, tool: T) -> &mut Selfwhere
T: ListenExecuteTool<Ctx> + 'static,
pub fn register_listen<T>(&mut self, tool: T) -> &mut Selfwhere
T: ListenExecuteTool<Ctx> + 'static,
Register a listen/execute tool in the registry.
Listen/execute tools start by streaming updates via listen(), then run
final execution with execute() once confirmed.
Sourcepub fn get(&self, name: &str) -> Option<&Arc<dyn ErasedTool<Ctx>>>
pub fn get(&self, name: &str) -> Option<&Arc<dyn ErasedTool<Ctx>>>
Get a synchronous tool by name.
Sourcepub fn get_async(&self, name: &str) -> Option<&Arc<dyn ErasedAsyncTool<Ctx>>>
pub fn get_async(&self, name: &str) -> Option<&Arc<dyn ErasedAsyncTool<Ctx>>>
Get an async tool by name.
Sourcepub fn get_listen(&self, name: &str) -> Option<&Arc<dyn ErasedListenTool<Ctx>>>
pub fn get_listen(&self, name: &str) -> Option<&Arc<dyn ErasedListenTool<Ctx>>>
Get a listen/execute tool by name.
Sourcepub fn is_listen(&self, name: &str) -> bool
pub fn is_listen(&self, name: &str) -> bool
Check if a tool name refers to a listen/execute tool.
Sourcepub fn all(&self) -> impl Iterator<Item = &Arc<dyn ErasedTool<Ctx>>>
pub fn all(&self) -> impl Iterator<Item = &Arc<dyn ErasedTool<Ctx>>>
Get all registered synchronous tools.
Sourcepub fn all_async(&self) -> impl Iterator<Item = &Arc<dyn ErasedAsyncTool<Ctx>>>
pub fn all_async(&self) -> impl Iterator<Item = &Arc<dyn ErasedAsyncTool<Ctx>>>
Get all registered async tools.
Sourcepub fn all_listen(
&self,
) -> impl Iterator<Item = &Arc<dyn ErasedListenTool<Ctx>>>
pub fn all_listen( &self, ) -> impl Iterator<Item = &Arc<dyn ErasedListenTool<Ctx>>>
Get all registered listen/execute tools.
Sourcepub fn to_llm_tools(&self) -> Vec<Tool>
pub fn to_llm_tools(&self) -> Vec<Tool>
Convert all tools (sync + async) to LLM tool definitions.