pub struct ToolRegistry { /* private fields */ }Expand description
A registry of named tools available for dynamic dispatch.
Holds type-erased tool implementations and cached ToolDefinition
schemas for fast lookup and execution.
Every dispatched output is sanitized with at least the registry’s
output_floor (default OutputSanitization::SanitizeTokens),
even if an individual tool opted out.
Implementations§
Source§impl ToolRegistry
impl ToolRegistry
Sourcepub async fn dispatch_batch(
&self,
calls: &[BatchToolCall],
mode: BatchExecutionMode,
ctx: &ToolContext,
) -> Vec<BatchToolCallOutcome>
pub async fn dispatch_batch( &self, calls: &[BatchToolCall], mode: BatchExecutionMode, ctx: &ToolContext, ) -> Vec<BatchToolCallOutcome>
Dispatches a batch of BatchToolCall items according to mode, preserving call order.
BatchExecutionMode::Parallel: polls all tool futures concurrently usingfutures_util::future::join_all, returning every outcome in exact input slice order. Destructive tools require explicit confirmation viaBatchExecutionMode::ParallelAllowDestructiveorAllowDestructiveBatchonctx.BatchExecutionMode::SequentialStopOnError: runs calls one by one and stops after the firstErr(ToolError).
Sourcepub async fn dispatch_batch_str(
&self,
calls: &[BatchToolCallStr<'_>],
mode: BatchExecutionMode,
ctx: &ToolContext,
) -> Vec<BatchToolCallOutcome>
pub async fn dispatch_batch_str( &self, calls: &[BatchToolCallStr<'_>], mode: BatchExecutionMode, ctx: &ToolContext, ) -> Vec<BatchToolCallOutcome>
Dispatches a batch of borrowed BatchToolCallStr items according to mode,
deserializing directly from raw JSON strings without intermediate DOM allocation.
Source§impl ToolRegistry
impl ToolRegistry
Sourcepub const fn with_output_floor(self, floor: OutputSanitization) -> Self
pub const fn with_output_floor(self, floor: OutputSanitization) -> Self
Set the minimum OutputSanitization enforced on every dispatched tool output.
The effective policy per call is the tool’s own policy raised to at least this
floor (OutputSanitization::at_least). Lowering it to
OutputSanitization::None restores raw passthrough for tools that opt out.
Sourcepub const fn set_output_floor(&mut self, floor: OutputSanitization) -> &mut Self
pub const fn set_output_floor(&mut self, floor: OutputSanitization) -> &mut Self
In-place variant of with_output_floor.
Sourcepub const fn output_floor(&self) -> OutputSanitization
pub const fn output_floor(&self) -> OutputSanitization
The minimum OutputSanitization enforced on every dispatched tool output.
Sourcepub fn effective_output_sanitization(
&self,
name: &str,
) -> Option<OutputSanitization>
pub fn effective_output_sanitization( &self, name: &str, ) -> Option<OutputSanitization>
The policy actually applied to name’s output: its own policy raised to the floor.
Returns None if no tool named name is registered.
Sourcepub fn register<T: RustTool + 'static>(&mut self, tool: T) -> &mut Self
pub fn register<T: RustTool + 'static>(&mut self, tool: T) -> &mut Self
Register a RustTool. Returns &mut Self for chaining.
The tool’s ToolDefinition (including JSON schema) is computed once
here and cached for the lifetime of the registration.
If a tool with the same name was already registered, it is replaced.
§Panics
Panics if the tool’s JSON schema cannot be serialized. This indicates a
bug in the tool’s Params type (e.g. a broken JsonSchema impl). Use
try_register for the non-panicking variant.
Sourcepub fn try_register<T: RustTool + 'static>(
&mut self,
tool: T,
) -> Result<&mut Self, ToolError>
pub fn try_register<T: RustTool + 'static>( &mut self, tool: T, ) -> Result<&mut Self, ToolError>
Register a RustTool, returning an error instead of panicking if the
tool’s JSON schema cannot be built.
This is the fallible counterpart to register; prefer
it when tool types are supplied dynamically and a broken JsonSchema
impl should not abort the process. If a tool with the same name was
already registered, it is replaced.
§Errors
Returns ToolError if the tool’s Params type fails to produce a
JSON schema.
Sourcepub fn with_tool<T: RustTool + 'static>(self, tool: T) -> Self
pub fn with_tool<T: RustTool + 'static>(self, tool: T) -> Self
Register a RustTool, consuming and returning Self for owned chaining.
Sourcepub fn definitions_slice(&self) -> Arc<[ToolDefinition]> ⓘ
pub fn definitions_slice(&self) -> Arc<[ToolDefinition]> ⓘ
Return a shared, deterministically sorted slice of all ToolDefinitions,
computed once and cached until the registry is mutated.
Sourcepub fn definitions(&self) -> Vec<ToolDefinition>
pub fn definitions(&self) -> Vec<ToolDefinition>
Collect ToolDefinitions for all registered tools.
Returns clones of the cached definitions computed at registration time.
Sourcepub fn dispatch_boxed<'a>(
&'a self,
name: &str,
args: Value,
ctx: &'a ToolContext,
) -> Result<BoxToolFuture<'a>, ToolError>
pub fn dispatch_boxed<'a>( &'a self, name: &str, args: Value, ctx: &'a ToolContext, ) -> Result<BoxToolFuture<'a>, ToolError>
Dispatch a tool call by name with raw JSON arguments and a context, returning a boxed future.
§Errors
Returns ToolError::not_found if no tool named name is registered.
Sourcepub fn dispatch_boxed_str<'a>(
&'a self,
name: &str,
args_json: &'a str,
ctx: &'a ToolContext,
) -> Result<BoxToolFuture<'a>, ToolError>
pub fn dispatch_boxed_str<'a>( &'a self, name: &str, args_json: &'a str, ctx: &'a ToolContext, ) -> Result<BoxToolFuture<'a>, ToolError>
Dispatch a tool call by name with a raw JSON arguments string, returning a boxed future without intermediate DOM allocation.
§Errors
Returns ToolError::not_found if no tool named name is registered.
Sourcepub async fn dispatch(
&self,
name: &str,
args: Value,
ctx: &ToolContext,
) -> Result<ToolOutput, ToolError>
pub async fn dispatch( &self, name: &str, args: Value, ctx: &ToolContext, ) -> Result<ToolOutput, ToolError>
Dispatch a tool call by name with raw JSON arguments and a context.
§Errors
Returns ToolError::not_found if no tool named name is registered
(carrying error_kind = "not_registered" metadata), or the tool’s own
error if argument deserialization fails or the handler returns an error.
Sourcepub async fn dispatch_str(
&self,
name: &str,
args_json: &str,
ctx: &ToolContext,
) -> Result<ToolOutput, ToolError>
pub async fn dispatch_str( &self, name: &str, args_json: &str, ctx: &ToolContext, ) -> Result<ToolOutput, ToolError>
Dispatch a tool call by name with a raw JSON string argument.
§Errors
Returns ToolError::not_found if no tool named name is registered,
or the tool’s own error if JSON parsing or the handler fails.
Sourcepub fn is_destructive(&self, name: &str) -> bool
pub fn is_destructive(&self, name: &str) -> bool
Return true if the registered tool has ToolEffect::Destructive.
Sourcepub fn remove(&mut self, name: &str) -> bool
pub fn remove(&mut self, name: &str) -> bool
Remove a tool by name, returning true if it was present.
Sourcepub fn definition(&self, name: &str) -> Option<&ToolDefinition>
pub fn definition(&self, name: &str) -> Option<&ToolDefinition>
Borrow the cached ToolDefinition for a registered tool by name.
Returns None if no tool named name is registered. Unlike
definitions, this clones nothing.
Sourcepub fn iter(&self) -> ToolDefinitions<'_> ⓘ
pub fn iter(&self) -> ToolDefinitions<'_> ⓘ
Iterate over (name, definition) pairs for every registered tool.
Yields clones of the cached definitions computed at registration time.
Trait Implementations§
Source§impl Debug for ToolRegistry
impl Debug for ToolRegistry
Source§impl Default for ToolRegistry
impl Default for ToolRegistry
Source§impl<'a> IntoIterator for &'a ToolRegistry
Iterate over (name, definition) pairs for every registered tool.
impl<'a> IntoIterator for &'a ToolRegistry
Iterate over (name, definition) pairs for every registered tool.
Yields (&'static str, ToolDefinition) for each tool in the registry.