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 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).