pub struct ToolRegistry { /* private fields */ }Expand description
Central registry that maps tool names to their specs and handlers.
Use register() to add tools, then
dispatch() to invoke them. The registry
owns a ToolCallRuntime that manages concurrent execution.
Implementations§
Source§impl ToolRegistry
impl ToolRegistry
Sourcepub fn register(
&mut self,
spec: ToolSpec,
handler: Arc<dyn ToolHandler>,
) -> Result<()>
pub fn register( &mut self, spec: ToolSpec, handler: Arc<dyn ToolHandler>, ) -> Result<()>
Register a tool with its specification and handler.
The tool’s name is taken from spec.name. Returns an error if
registration fails (currently infallible, but the Result is
reserved for future validation).
Sourcepub fn list_specs(&self) -> Vec<ConfiguredToolSpec>
pub fn list_specs(&self) -> Vec<ConfiguredToolSpec>
Return the configured specs for every registered tool.
Sourcepub async fn dispatch(
&self,
call: ToolCall,
allow_mutating: bool,
) -> Result<ToolOutput, FunctionCallError>
pub async fn dispatch( &self, call: ToolCall, allow_mutating: bool, ) -> Result<ToolOutput, FunctionCallError>
Validate and execute a tool call.
Looks up the tool by name, verifies the payload kind matches the
handler, enforces the allow_mutating guard, acquires the
appropriate execution lock, and forwards the call to the handler.
Returns a FunctionCallError if any validation step fails or
the handler returns an error.