pub struct ToolRegistry { /* private fields */ }Expand description
Registry of available tools for the agent loop.
Implementations§
Source§impl ToolRegistry
impl ToolRegistry
Sourcepub fn with_cache(self, cache: Arc<dyn ToolCache>) -> Self
pub fn with_cache(self, cache: Arc<dyn ToolCache>) -> Self
Attach a tool result cache.
Sourcepub fn register(&mut self, spec: ToolSpec)
pub fn register(&mut self, spec: ToolSpec)
Register a tool. Overwrites any existing tool with the same name.
Sourcepub fn register_tools(&mut self, specs: impl IntoIterator<Item = ToolSpec>)
pub fn register_tools(&mut self, specs: impl IntoIterator<Item = ToolSpec>)
Register multiple tools at once.
Equivalent to calling register for each spec in order. Duplicate
names overwrite earlier entries.
Sourcepub fn with_tool(self, spec: ToolSpec) -> Self
pub fn with_tool(self, spec: ToolSpec) -> Self
Fluent builder: register a tool and return self.
Allows chaining multiple registrations:
use llm_agent_runtime::agent::{ToolRegistry, ToolSpec};
let registry = ToolRegistry::new()
.with_tool(ToolSpec::new("search", "Search", |args| args.clone()))
.with_tool(ToolSpec::new("calc", "Calculate", |args| args.clone()));Sourcepub async fn call(
&self,
name: &str,
args: Value,
) -> Result<Value, AgentRuntimeError>
pub async fn call( &self, name: &str, args: Value, ) -> Result<Value, AgentRuntimeError>
Call a tool by name.
§Errors
AgentRuntimeError::AgentLoop— tool not found, required field missing, or custom validator rejected the argumentsAgentRuntimeError::CircuitOpen— the tool’s circuit breaker is open (only possible when theorchestratorfeature is enabled)
Sourcepub fn get(&self, name: &str) -> Option<&ToolSpec>
pub fn get(&self, name: &str) -> Option<&ToolSpec>
Look up a registered tool by name. Returns None if not registered.
Sourcepub fn has_tool(&self, name: &str) -> bool
pub fn has_tool(&self, name: &str) -> bool
Return true if a tool with the given name is registered.
Sourcepub fn unregister(&mut self, name: &str) -> bool
pub fn unregister(&mut self, name: &str) -> bool
Remove a tool by name. Returns true if the tool was registered.
Sourcepub fn tool_names(&self) -> Vec<&str>
pub fn tool_names(&self) -> Vec<&str>
Return the list of registered tool names.
Sourcepub fn tool_names_owned(&self) -> Vec<String>
pub fn tool_names_owned(&self) -> Vec<String>
Return all registered tool names as owned Strings.
Unlike tool_names this does not borrow self, making the result
usable after the registry is moved or mutated.
Sourcepub fn all_tool_names(&self) -> Vec<String>
pub fn all_tool_names(&self) -> Vec<String>
Return all registered tool names sorted alphabetically.
Useful for deterministic output in help text, diagnostics, or tests.
Sourcepub fn tool_specs(&self) -> Vec<&ToolSpec>
pub fn tool_specs(&self) -> Vec<&ToolSpec>
Return references to all registered ToolSpecs.
Sourcepub fn filter_tools<F: Fn(&ToolSpec) -> bool>(&self, pred: F) -> Vec<&ToolSpec>
pub fn filter_tools<F: Fn(&ToolSpec) -> bool>(&self, pred: F) -> Vec<&ToolSpec>
Return references to all ToolSpecs that satisfy the given predicate.
§Example
let registry = ToolRegistry::new();
let long_desc: Vec<_> = registry.filter_tools(|s| s.description.len() > 20);Sourcepub fn rename_tool(
&mut self,
old_name: &str,
new_name: impl Into<String>,
) -> bool
pub fn rename_tool( &mut self, old_name: &str, new_name: impl Into<String>, ) -> bool
Rename a registered tool from old_name to new_name.
The tool’s name field and its registry key are both updated.
Returns true if the tool was found and renamed, false if old_name
is not registered. If new_name is already registered, it is
overwritten.
Sourcepub fn tool_count(&self) -> usize
pub fn tool_count(&self) -> usize
Return the number of registered tools.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Remove all registered tools.
Useful for resetting the registry between test runs or for dynamic agent reconfiguration.
Sourcepub fn remove(&mut self, name: &str) -> Option<ToolSpec>
pub fn remove(&mut self, name: &str) -> Option<ToolSpec>
Remove a tool from the registry by name.
Returns Some(spec) if the tool was registered, None if not found.
Sourcepub fn contains(&self, name: &str) -> bool
pub fn contains(&self, name: &str) -> bool
Return true if a tool with the given name is registered.
Sourcepub fn descriptions(&self) -> Vec<(&str, &str)>
pub fn descriptions(&self) -> Vec<(&str, &str)>
Return (name, description) pairs for all registered tools, sorted by name.
Useful for generating help text or logging the tool set at startup.
Sourcepub fn find_by_description_keyword(&self, keyword: &str) -> Vec<&ToolSpec>
pub fn find_by_description_keyword(&self, keyword: &str) -> Vec<&ToolSpec>
Return references to all tool specs whose description contains
keyword (case-insensitive).
Sourcepub fn tool_count_with_required_fields(&self) -> usize
pub fn tool_count_with_required_fields(&self) -> usize
Return the number of tools that have at least one required field.
Sourcepub fn tool_count_with_validators(&self) -> usize
pub fn tool_count_with_validators(&self) -> usize
Return the number of registered tools that have at least one attached validator.
Complements tool_count_with_required_fields; a tool can have validators
without any required field declarations (for cross-field or range checks).
Sourcepub fn names(&self) -> Vec<&str>
pub fn names(&self) -> Vec<&str>
Return the names of all registered tools, sorted alphabetically.
Sourcepub fn tool_names_starting_with(&self, prefix: &str) -> Vec<&str>
pub fn tool_names_starting_with(&self, prefix: &str) -> Vec<&str>
Return the names of all registered tools whose name starts with prefix,
sorted alphabetically.
Sourcepub fn description_for(&self, name: &str) -> Option<&str>
pub fn description_for(&self, name: &str) -> Option<&str>
Return the description of the tool with the given name, or None if
no such tool is registered.
Sourcepub fn count_with_description_containing(&self, keyword: &str) -> usize
pub fn count_with_description_containing(&self, keyword: &str) -> usize
Return the count of tools whose description contains keyword
(case-insensitive).
Sourcepub fn unregister_all(&mut self)
pub fn unregister_all(&mut self)
Remove all registered tools.
Sourcepub fn names_containing(&self, substring: &str) -> Vec<&str>
pub fn names_containing(&self, substring: &str) -> Vec<&str>
Return a sorted list of tool names that contain substring (case-insensitive).
Sourcepub fn shortest_description(&self) -> Option<&str>
pub fn shortest_description(&self) -> Option<&str>
Return the description of the tool with the shortest description string.
Returns None if the registry is empty.
Sourcepub fn longest_description(&self) -> Option<&str>
pub fn longest_description(&self) -> Option<&str>
Return the description of the tool with the longest description string.
Returns None if the registry is empty.
Sourcepub fn all_descriptions(&self) -> Vec<&str>
pub fn all_descriptions(&self) -> Vec<&str>
Return a sorted list of all tool descriptions.
Sourcepub fn tool_names_with_keyword(&self, keyword: &str) -> Vec<&str>
pub fn tool_names_with_keyword(&self, keyword: &str) -> Vec<&str>
Return the names of tools whose description contains keyword (case-insensitive).
Sourcepub fn avg_description_length(&self) -> f64
pub fn avg_description_length(&self) -> f64
Return the mean byte length of all tool descriptions.
Returns 0.0 if the registry is empty.
Sourcepub fn tool_names_sorted(&self) -> Vec<&str>
pub fn tool_names_sorted(&self) -> Vec<&str>
Return all registered tool names in ascending sorted order.
Sourcepub fn description_contains_count(&self, keyword: &str) -> usize
pub fn description_contains_count(&self, keyword: &str) -> usize
Return the count of tools whose description contains keyword (case-insensitive).
Sourcepub fn total_description_bytes(&self) -> usize
pub fn total_description_bytes(&self) -> usize
Return the total byte length of all tool description strings combined.
Useful as a rough measure of how much context the tool registry will contribute to a prompt when all descriptions are serialized together.
Sourcepub fn shortest_description_length(&self) -> usize
pub fn shortest_description_length(&self) -> usize
Return the byte length of the shortest tool description, or 0 if the
registry is empty.
Sourcepub fn longest_description_length(&self) -> usize
pub fn longest_description_length(&self) -> usize
Return the byte length of the longest tool description, or 0 if the
registry is empty.
Sourcepub fn tool_count_above_desc_bytes(&self, min_bytes: usize) -> usize
pub fn tool_count_above_desc_bytes(&self, min_bytes: usize) -> usize
Return the count of tools whose description byte length is strictly
greater than min_bytes.
Returns 0 for an empty registry or when no description exceeds
min_bytes.
Sourcepub fn tools_with_required_field(&self, field: &str) -> Vec<&ToolSpec>
pub fn tools_with_required_field(&self, field: &str) -> Vec<&ToolSpec>
Return references to all ToolSpecs that list field in their
required_fields.
Returns an empty Vec when no tools declare field as required.
Sourcepub fn tools_without_required_fields(&self) -> Vec<&ToolSpec>
pub fn tools_without_required_fields(&self) -> Vec<&ToolSpec>
Return references to all ToolSpecs that have no required fields.
Returns an empty Vec when every registered tool declares at least one
required field, or when the registry is empty.
Sourcepub fn avg_required_fields_count(&self) -> f64
pub fn avg_required_fields_count(&self) -> f64
Return the average number of required fields per registered tool.
Returns 0.0 for an empty registry.
Sourcepub fn tool_descriptions_total_words(&self) -> usize
pub fn tool_descriptions_total_words(&self) -> usize
Return the total word count across all tool descriptions.
Words are split on ASCII whitespace. Returns 0 for an empty
registry or when all descriptions are blank.
Sourcepub fn has_tools_with_empty_descriptions(&self) -> bool
pub fn has_tools_with_empty_descriptions(&self) -> bool
Return true if any registered tool has a blank description.
A blank description is one that is empty or contains only whitespace.
Returns false for an empty registry (vacuously no blank descriptions).
Sourcepub fn total_required_fields(&self) -> usize
pub fn total_required_fields(&self) -> usize
Return the total number of required fields across all registered tools.
Sums the required_fields lengths of every ToolSpec.
Returns 0 for an empty registry or when no tool has required fields.
Sourcepub fn has_tool_with_description_containing(&self, keyword: &str) -> bool
pub fn has_tool_with_description_containing(&self, keyword: &str) -> bool
Return true if at least one registered tool’s description contains
keyword (case-sensitive substring search).
Sourcepub fn tools_with_description_longer_than(&self, min_bytes: usize) -> Vec<&str>
pub fn tools_with_description_longer_than(&self, min_bytes: usize) -> Vec<&str>
Return tool names whose description byte length exceeds min_bytes, sorted.
Returns an empty Vec for an empty registry or when no description
exceeds the threshold.
Sourcepub fn max_description_bytes(&self) -> usize
pub fn max_description_bytes(&self) -> usize
Return the byte length of the longest tool description, or 0 when empty.
Sourcepub fn min_description_bytes(&self) -> usize
pub fn min_description_bytes(&self) -> usize
Return the byte length of the shortest tool description, or 0 when empty.
Sourcepub fn description_starts_with_any(&self, prefixes: &[&str]) -> bool
pub fn description_starts_with_any(&self, prefixes: &[&str]) -> bool
Return true if any tool description starts with any of the given prefixes.
Useful for checking whether a set of common description templates is
in use (e.g. "Search", "Write", "Read"). Returns false for an
empty registry or empty prefixes slice.
Sourcepub fn tool_with_most_required_fields(&self) -> Option<&ToolSpec>
pub fn tool_with_most_required_fields(&self) -> Option<&ToolSpec>
Return a reference to the ToolSpec with the most required fields.
When multiple tools share the maximum required-field count, the one that
sorts first alphabetically by name is returned for deterministic output.
Returns None for an empty registry.
Sourcepub fn tool_by_name(&self, name: &str) -> Option<&ToolSpec>
pub fn tool_by_name(&self, name: &str) -> Option<&ToolSpec>
Return a reference to the ToolSpec with the given name, or None.
Sourcepub fn tools_without_validators(&self) -> Vec<&str>
pub fn tools_without_validators(&self) -> Vec<&str>
Return the names of all tools that have no validators, sorted alphabetically.
Complements tool_count_with_validators by returning the actual names.
Returns an empty Vec for an empty registry.
Sourcepub fn tool_names_with_required_fields(&self) -> Vec<&str>
pub fn tool_names_with_required_fields(&self) -> Vec<&str>
Return the names of all tools that have at least one required field, sorted alphabetically.
Returns an empty Vec when no tools have required fields or the
registry is empty.
Sourcepub fn has_all_tools(&self, names: &[&str]) -> bool
pub fn has_all_tools(&self, names: &[&str]) -> bool
Return true if all of the given names are registered in this
registry.
Returns true for an empty names slice (vacuously true).
Sourcepub fn tools_with_required_fields_count(&self) -> usize
pub fn tools_with_required_fields_count(&self) -> usize
Return the number of tools that have at least one required field defined.
Returns 0 for an empty registry.
Sourcepub fn tool_names_with_prefix<'a>(&'a self, prefix: &str) -> Vec<&'a str>
pub fn tool_names_with_prefix<'a>(&'a self, prefix: &str) -> Vec<&'a str>
Return the names of all tools whose name starts with prefix, sorted
alphabetically.
Returns an empty Vec for an empty registry or when no tool matches.